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

fijal at codespeak.net fijal at codespeak.net
Fri Feb 15 10:21:08 CET 2008


Author: fijal
Date: Fri Feb 15 10:21:07 2008
New Revision: 51507

Modified:
   pypy/dist/pypy/lib/_ctypes/array.py
   pypy/dist/pypy/lib/_ctypes/basics.py
   pypy/dist/pypy/lib/_ctypes/pointer.py
   pypy/dist/pypy/lib/_ctypes/structure.py
Log:
Introduce _base and _index, following b_base and b_index in ctypes.


Modified: pypy/dist/pypy/lib/_ctypes/array.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/array.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/array.py	Fri Feb 15 10:21:07 2008
@@ -150,7 +150,7 @@
         if isinstance(index, slice):
             return self._slice_getitem(index)
         index = self._fix_index(index)
-        return self._type_._CData_output(self._subarray(index))
+        return self._type_._CData_output(self._subarray(index), self, index)
 
     def __len__(self):
         return self._length_

Modified: pypy/dist/pypy/lib/_ctypes/basics.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/basics.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/basics.py	Fri Feb 15 10:21:07 2008
@@ -17,16 +17,18 @@
         else:
             return self.from_param(as_parameter)
 
-    def _CData_input(self, value):
+    def _CData_input(self, value, base=None, index=-1):
         """Used when data enters into ctypes from user code.  'value' is
         some user-specified Python object, which is converted into a _rawffi
         array of length 1 containing the same value according to the
         type 'self'.
         """
         cobj = self.from_param(value)
+        cobj.__dict__['_base'] = base
+        cobj.__dict__['_index'] = index
         return cobj._get_buffer_for_param()
 
-    def _CData_output(self, resarray):
+    def _CData_output(self, resarray, base=None, index=-1):
         assert isinstance(resarray, _rawffi.ArrayInstance)
         """Used when data exits ctypes and goes into user code.
         'resarray' is a _rawffi array of length 1 containing the value,
@@ -34,6 +36,8 @@
         """
         res = self.__new__(self)
         res.__dict__['_buffer'] = resarray
+        res.__dict__['_base'] = base
+        res.__dict__['_index'] = index
         return res.__ctypes_from_outparam__()
 
     def __mul__(self, other):

Modified: pypy/dist/pypy/lib/_ctypes/pointer.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/pointer.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/pointer.py	Fri Feb 15 10:21:07 2008
@@ -94,10 +94,11 @@
     def __getitem__(self, index):
         if isinstance(index, slice):
             return self._slice_getitem(index)
-        return self._type_._CData_output(self._subarray(index))
+        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]
+        self._subarray(index)[0] = self._type_._CData_input(value, self,
+                                                            index)[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	Fri Feb 15 10:21:07 2008
@@ -138,10 +138,12 @@
     def _alignmentofinstances(self):
         return self._ffistruct.alignment
 
-    def _CData_output(self, resarray):
+    def _CData_output(self, resarray, base=None, index=-1):
         res = self.__new__(self)
         ffistruct = self._ffistruct.fromaddress(resarray.buffer)
         res.__dict__['_buffer'] = ffistruct
+        res.__dict__['_base'] = base
+        res.__dict__['_index'] = index
         return res.__ctypes_from_outparam__()
 
 class Structure(_CData):
@@ -171,7 +173,8 @@
             fieldtype = self._fieldtypes[name].ctype
         except KeyError:
             return _CData.__getattribute__(self, name)
-        return fieldtype._CData_output(self._subarray(fieldtype, name))
+        return fieldtype._CData_output(self._subarray(fieldtype, name), self,
+                                       getattr(self.__class__, name).offset)
 
     def _get_buffer_for_param(self):
         return self._buffer.byptr()



More information about the Pypy-commit mailing list