[pypy-svn] r51513 - in pypy/dist/pypy/lib: _ctypes app_test/ctypes
fijal at codespeak.net
fijal at codespeak.net
Fri Feb 15 10:43:29 CET 2008
Author: fijal
Date: Fri Feb 15 10:43:29 2008
New Revision: 51513
Added:
pypy/dist/pypy/lib/app_test/ctypes/test_base.py (contents, props changed)
Modified:
pypy/dist/pypy/lib/_ctypes/array.py
Log:
Test and a fix.
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:43:29 2008
@@ -150,7 +150,8 @@
if isinstance(index, slice):
return self._slice_getitem(index)
index = self._fix_index(index)
- return self._type_._CData_output(self._subarray(index), self, index)
+ return self._type_._CData_output(self._subarray(index), self,
+ self._ffiarray.gettypecode(index)[0])
def __len__(self):
return self._length_
Added: pypy/dist/pypy/lib/app_test/ctypes/test_base.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/lib/app_test/ctypes/test_base.py Fri Feb 15 10:43:29 2008
@@ -0,0 +1,23 @@
+
+from ctypes import *
+
+class TestCTypesBase:
+ def test_pointer(self):
+ p = pointer(pointer(c_int(2)))
+ x = p[0]
+ assert x._base is p
+
+ def test_structure(self):
+ class X(Structure):
+ _fields_ = [('x', POINTER(c_int)),
+ ('y', POINTER(c_int))]
+
+ x = X()
+ assert x.y._base is x
+ assert x.y._index == sizeof(POINTER(c_int))
+
+ def test_array(self):
+ X = POINTER(c_int) * 24
+ x = X()
+ assert x[16]._base is x
+ assert x[16]._index == 16 * sizeof(POINTER(c_int))
More information about the Pypy-commit
mailing list