[pypy-svn] pypy jitypes2: the previous checkin was partly broken; now c_char_p and c_wchar_p are strong typed as well; there is still one failing test because now we are too strict and do not allow implicit conversions from typed pointers to void*

antocuni commits-noreply at bitbucket.org
Fri Mar 25 12:11:55 CET 2011


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: jitypes2
Changeset: r42931:1dcf40fbb6ad
Date: 2011-03-25 11:15 +0100
http://bitbucket.org/pypy/pypy/changeset/1dcf40fbb6ad/

Log:	the previous checkin was partly broken; now c_char_p and c_wchar_p
	are strong typed as well; there is still one failing test because
	now we are too strict and do not allow implicit conversions from
	typed pointers to void*

diff --git a/lib_pypy/_ctypes/primitive.py b/lib_pypy/_ctypes/primitive.py
--- a/lib_pypy/_ctypes/primitive.py
+++ b/lib_pypy/_ctypes/primitive.py
@@ -1,3 +1,4 @@
+import _ffi
 import _rawffi
 import weakref
 import sys
@@ -140,6 +141,7 @@
                     value = 0
                 self._buffer[0] = value
             result.value = property(_getvalue, _setvalue)
+            result._ffiargtype = _ffi.types.Pointer(_ffi.types.char)
 
         elif tp == 'Z':
             # c_wchar_p
@@ -163,6 +165,7 @@
                     value = 0
                 self._buffer[0] = value
             result.value = property(_getvalue, _setvalue)
+            result._ffiargtype = _ffi.types.Pointer(_ffi.types.unichar)
 
         elif tp == 'P':
             # c_void_p

diff --git a/lib_pypy/_ctypes/pointer.py b/lib_pypy/_ctypes/pointer.py
--- a/lib_pypy/_ctypes/pointer.py
+++ b/lib_pypy/_ctypes/pointer.py
@@ -120,8 +120,7 @@
         my_ffitype = type(self).get_ffi_argtype()
         # for now, we always allow types.pointer, else a lot of tests
         # break. We need to rethink how pointers are represented, though
-        if my_ffitype.deref_pointer() != ffitype.deref_pointer() \
-                and ffitype != _ffi.types.pointer:
+        if my_ffitype.deref_pointer() != ffitype.deref_pointer():
             raise ArgumentError, "expected %s instance, got %s" % (type(self), ffitype)
         return self._get_buffer_value()
 


More information about the Pypy-commit mailing list