[pypy-svn] r51556 - pypy/dist/pypy/lib/_ctypes

fijal at codespeak.net fijal at codespeak.net
Sat Feb 16 14:32:20 CET 2008


Author: fijal
Date: Sat Feb 16 14:32:20 2008
New Revision: 51556

Modified:
   pypy/dist/pypy/lib/_ctypes/array.py
   pypy/dist/pypy/lib/_ctypes/basics.py
   pypy/dist/pypy/lib/_ctypes/builtin.py
   pypy/dist/pypy/lib/_ctypes/function.py
   pypy/dist/pypy/lib/_ctypes/pointer.py
   pypy/dist/pypy/lib/_ctypes/structure.py
   pypy/dist/pypy/lib/_ctypes/union.py
Log:
strange, dangerous checkin. Make _CData_input unsafe. Now it returns
the buffer and object to keep it alive. I cannot think right now
about better solution, at least fixes segfaults (but I don't like it)


Modified: pypy/dist/pypy/lib/_ctypes/array.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/array.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/array.py	Sat Feb 16 14:32:20 2008
@@ -129,7 +129,7 @@
         index = self._fix_index(index)
         if getattr(value, '_objects', None):
             self._objects[keepalive_key(index)] = value._objects
-        value = self._type_._CData_input(value)
+        cobj, value = self._type_._CData_input(value)
         if not isinstance(self._type_._ffishape, tuple):
             self._buffer[index] = value[0]
             # something more sophisticated, cannot set field directly

Modified: pypy/dist/pypy/lib/_ctypes/basics.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/basics.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/basics.py	Sat Feb 16 14:32:20 2008
@@ -28,7 +28,7 @@
         cobj = self.from_param(value)
         # XXX this function segfaults randomly, because
         # cobj is considered to be an owner of that, fix
-        return cobj._get_buffer_for_param()
+        return cobj, cobj._get_buffer_for_param()
 
     def _CData_output(self, resarray, base=None, index=-1):
         assert isinstance(resarray, _rawffi.ArrayInstance)

Modified: pypy/dist/pypy/lib/_ctypes/builtin.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/builtin.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/builtin.py	Sat Feb 16 14:32:20 2008
@@ -11,7 +11,8 @@
 def _string_at_addr(addr, lgt):
     # address here can be almost anything
     import ctypes
-    obj = ctypes.c_char_p._CData_input(addr)[0]
+    cobj, arg = ctypes.c_char_p._CData_input(addr)
+    obj = arg[0]
     return _rawffi.charp2rawstring(obj, lgt)
 
 def set_conversion_mode(encoding, errors):
@@ -22,7 +23,8 @@
 
 def _wstring_at_addr(addr, lgt):
     import ctypes
-    obj = ctypes.c_wchar_p._CData_input(addr)[0]
+    cobj, arg = ctypes.c_wchar_p._CData_input(addr)
+    obj = arg[0]
     # XXX purely applevel
     if lgt == -1:
         lgt = sys.maxint

Modified: pypy/dist/pypy/lib/_ctypes/function.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/function.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/function.py	Sat Feb 16 14:32:20 2008
@@ -77,7 +77,8 @@
                 argtypes = argtypes[:] + self._guess_argtypes(args[cut:])
         restype = self._restype_
         funcptr = self._getfuncptr(argtypes, restype)
-        resarray = funcptr(*self._wrap_args(argtypes, args))
+        args = self._wrap_args(argtypes, args)
+        resarray = funcptr(*[arg for obj, arg in args])
         if restype is not None:
             return restype._CData_output(resarray)
 

Modified: pypy/dist/pypy/lib/_ctypes/pointer.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/pointer.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/pointer.py	Sat Feb 16 14:32:20 2008
@@ -100,7 +100,8 @@
         return self._type_._CData_output(self._subarray(index), self, index)
 
     def __setitem__(self, index, value):
-        self._subarray(index)[0] = self._type_._CData_input(value)[0]
+        cobj, arg = self._type_._CData_input(value)
+        self._subarray(index)[0] = arg[0]
 
     def __nonzero__(self):
         return self._buffer[0] != 0

Modified: pypy/dist/pypy/lib/_ctypes/structure.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/structure.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/structure.py	Sat Feb 16 14:32:20 2008
@@ -167,7 +167,7 @@
         if getattr(value, '_objects', None):
             key = keepalive_key(getattr(self.__class__, name).offset)
             self.__dict__['_objects'][key] = value._objects
-        value = fieldtype._CData_input(value)
+        cobj, value = fieldtype._CData_input(value)
         self._buffer.__setattr__(name, value[0])
 
     def __getattribute__(self, name):

Modified: pypy/dist/pypy/lib/_ctypes/union.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/union.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/union.py	Sat Feb 16 14:32:20 2008
@@ -79,6 +79,6 @@
             fieldtype = self._fieldtypes[name].ctype
         except KeyError:
             raise AttributeError(name)
-        value = fieldtype._CData_input(value)
+        cobj, value = fieldtype._CData_input(value)
         buf = self._ffiarrays[name].fromaddress(self._buffer.buffer, 1)
         buf[0] = value[0]



More information about the Pypy-commit mailing list