[pypy-commit] pypy ffistruct: add docstrings for WrapDispatcher methods; raise a proper applevel exception instead of assert False

antocuni noreply at buildbot.pypy.org
Fri Nov 11 16:32:39 CET 2011


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: ffistruct
Changeset: r49316:b088b5e09108
Date: 2011-11-10 22:03 +0100
http://bitbucket.org/pypy/pypy/changeset/b088b5e09108/

Log:	add docstrings for WrapDispatcher methods; raise a proper applevel
	exception instead of assert False

diff --git a/pypy/module/_ffi/dispatcher.py b/pypy/module/_ffi/dispatcher.py
--- a/pypy/module/_ffi/dispatcher.py
+++ b/pypy/module/_ffi/dispatcher.py
@@ -94,7 +94,9 @@
             return w_arg
 
     def error(self, w_ffitype, w_obj):
-        assert False # XXX raise a proper app-level exception
+        raise operationerrfmt(space.w_TypeError,
+                              'Unsupported ffi type to convert: %s',
+                              w_ffitype.name)
 
     def handle_signed(self, w_ffitype, w_obj, intval):
         """
@@ -238,44 +240,83 @@
         singlefloatval = self.get_singlefloat(w_ffitype)
         return self.space.wrap(float(singlefloatval))
 
-    def error(self, w_ffitype, w_obj):
-        assert False # XXX raise a proper app-level exception
+    def error(self, w_ffitype):
+        raise operationerrfmt(space.w_TypeError,
+                              'Unsupported ffi type to convert: %s',
+                              w_ffitype.name)
 
     def get_longlong(self, w_ffitype):
+        """
+        Return type: lltype.SignedLongLong
+        """
         self.error(w_ffitype)
 
     def get_ulonglong(self, w_ffitype):
+        """
+        Return type: lltype.UnsignedLongLong
+        """
         self.error(w_ffitype)
 
     def get_signed(self, w_ffitype):
+        """
+        Return type: lltype.Signed
+        """
         self.error(w_ffitype)
 
     def get_unsigned(self, w_ffitype):
+        """
+        Return type: lltype.Unsigned
+        """
         self.error(w_ffitype)
 
     def get_unsigned_which_fits_into_a_signed(self, w_ffitype):
+        """
+        Return type: lltype.Signed.
+        
+        We return Signed even if the input type is unsigned, because this way
+        we get an app-level <int> instead of a <long>.
+        """
         self.error(w_ffitype)
 
     def get_pointer(self, w_ffitype):
+        """
+        Return type: lltype.Unsigned
+        """
         self.error(w_ffitype)
 
     def get_char(self, w_ffitype):
+        """
+        Return type: rffi.UCHAR
+        """
         self.error(w_ffitype)
 
     def get_unichar(self, w_ffitype):
+        """
+        Return type: rffi.WCHAR_T
+        """
         self.error(w_ffitype)
 
     def get_float(self, w_ffitype):
+        """
+        Return type: lltype.Float
+        """
         self.error(w_ffitype)
 
     def get_singlefloat(self, w_ffitype):
+        """
+        Return type: lltype.SingleFloat
+        """
         self.error(w_ffitype)
 
     def get_struct(self, w_datashape):
         """
-        XXX: write nice docstring in the base class, must return an ULONG
+        Return type: lltype.Unsigned
+        (the address of the structure)
         """
         return self.func.call(self.argchain, rffi.ULONG, is_struct=True)
 
     def get_void(self, w_ffitype):
+        """
+        Return type: None
+        """
         self.error(w_ffitype)
diff --git a/pypy/module/_ffi/interp_funcptr.py b/pypy/module/_ffi/interp_funcptr.py
--- a/pypy/module/_ffi/interp_funcptr.py
+++ b/pypy/module/_ffi/interp_funcptr.py
@@ -165,9 +165,8 @@
         elif restype is libffi.types.schar:
             return rffi.cast(rffi.LONG, call(self.argchain, rffi.SIGNEDCHAR))
         else:
-            raise OperationError(space.w_ValueError,
-                                 space.wrap('Unsupported restype'))
-
+            self.error(w_ffitype)
+            
     def get_unsigned(self, w_ffitype):
         return self.func.call(self.argchain, rffi.ULONG)
 
@@ -185,9 +184,8 @@
         elif restype is libffi.types.uchar:
             return rffi.cast(rffi.LONG, call(self.argchain, rffi.UCHAR))
         else:
-            raise OperationError(space.w_ValueError,
-                                 space.wrap('Unsupported restype'))
-        return space.wrap(intres)
+            self.error(w_ffitype)
+
 
     def get_pointer(self, w_ffitype):
         ptrres = self.func.call(self.argchain, rffi.VOIDP)
@@ -206,9 +204,6 @@
         return self.func.call(self.argchain, rffi.FLOAT)
 
     def get_struct(self, w_datashape):
-        """
-        XXX: write nice docstring in the base class, must return an ULONG
-        """
         return self.func.call(self.argchain, rffi.ULONG, is_struct=True)
 
     def get_void(self, w_ffitype):


More information about the pypy-commit mailing list