[pypy-svn] r50880 - in pypy/dist/pypy/lib: _ctypes app_test/ctypes
fijal at codespeak.net
fijal at codespeak.net
Tue Jan 22 14:35:18 CET 2008
Author: fijal
Date: Tue Jan 22 14:35:16 2008
New Revision: 50880
Modified:
pypy/dist/pypy/lib/_ctypes/array.py
pypy/dist/pypy/lib/app_test/ctypes/test_array.py
pypy/dist/pypy/lib/app_test/ctypes/test_structures.py
Log:
* Support for array of structures
* Make skip messages more elaborate
Modified: pypy/dist/pypy/lib/_ctypes/array.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/array.py (original)
+++ pypy/dist/pypy/lib/_ctypes/array.py Tue Jan 22 14:35:16 2008
@@ -101,7 +101,14 @@
return
value = self._type_._CData_input(value)
index = self._fix_index(index)
- self._buffer[index] = value[0]
+ if not isinstance(self._type_._ffishape, tuple):
+ self._buffer[index] = value[0]
+ # something more sophisticated, cannot set field directly
+ else:
+ from ctypes import memmove
+ dest = self._buffer.itemaddress(index)
+ source = value[0]
+ memmove(dest, source, self._type_._ffishape[0])
def __getitem__(self, index):
if isinstance(index, slice):
Modified: pypy/dist/pypy/lib/app_test/ctypes/test_array.py
==============================================================================
--- pypy/dist/pypy/lib/app_test/ctypes/test_array.py (original)
+++ pypy/dist/pypy/lib/app_test/ctypes/test_array.py Tue Jan 22 14:35:16 2008
@@ -108,3 +108,16 @@
sz = (c_wchar * 3).from_address(addressof(p))
assert sz[:] == "foo"
assert sz.value == "foo"
+
+class TestSophisticatedThings:
+ def test_array_of_structures(self):
+ class X(Structure):
+ _fields_ = [('x', c_int), ('y', c_int)]
+
+ Y = X * 2
+ y = Y()
+ x = X()
+ x.y = 3
+ y[1] = x
+ assert y[1].y == 3
+
Modified: pypy/dist/pypy/lib/app_test/ctypes/test_structures.py
==============================================================================
--- pypy/dist/pypy/lib/app_test/ctypes/test_structures.py (original)
+++ pypy/dist/pypy/lib/app_test/ctypes/test_structures.py Tue Jan 22 14:35:16 2008
@@ -202,7 +202,7 @@
raises(ValueError, type(Structure), "X", (Structure,), d)
def test_initializers(self):
- py.test.skip("unsupported")
+ py.test.skip("Structures with inlined arrays")
class Person(Structure):
_fields_ = [("name", c_char*6),
("age", c_int)]
@@ -234,7 +234,7 @@
raises(TypeError, setattr, POINT, "_fields_", [("x", 1), ("y", 2)])
def test_intarray_fields(self):
- py.test.skip("unsupported")
+ py.test.skip("Structures with inlined arrays")
class SomeInts(Structure):
_fields_ = [("a", c_int * 4)]
@@ -431,3 +431,4 @@
x = X()
assert x.x == 0
+
More information about the Pypy-commit
mailing list