[pypy-svn] r51720 - in pypy/dist/pypy/lib: _ctypes app_test/ctypes
cfbolz at codespeak.net
cfbolz at codespeak.net
Thu Feb 21 14:32:18 CET 2008
Author: cfbolz
Date: Thu Feb 21 14:32:18 2008
New Revision: 51720
Modified:
pypy/dist/pypy/lib/_ctypes/structure.py
pypy/dist/pypy/lib/app_test/ctypes/test_structures.py
Log:
allow tuples as _fields_
Modified: pypy/dist/pypy/lib/_ctypes/structure.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/structure.py (original)
+++ pypy/dist/pypy/lib/_ctypes/structure.py Thu Feb 21 14:32:18 2008
@@ -44,6 +44,8 @@
_CDataMeta.__setattr__(self, name, value)
def names_and_fields(_fields_, superclass, zero_offset=False, anon=None):
+ if isinstance(_fields_, tuple):
+ _fields_ = list(_fields_)
for _, tp in _fields_:
if not isinstance(tp, _CDataMeta):
raise TypeError("Expected CData subclass, got %s" % (tp,))
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 Thu Feb 21 14:32:18 2008
@@ -387,6 +387,16 @@
s.p = None
assert s.x == 12345678
+ def test_fields_is_a_tuple(self):
+ class Person(Structure):
+ _fields_ = (("name", c_char*6),
+ ("age", c_int))
+
+ # short enough
+ p = Person("123456", 6)
+ assert p.name == "123456"
+ assert p.age == 6
+
class TestRecursiveStructure(BaseCTypesTestChecker):
def test_contains_itself(self):
class Recursive(Structure):
More information about the Pypy-commit
mailing list