[pypy-svn] r61705 - in pypy/trunk/pypy/lib: _ctypes app_test/ctypes_tests

afa at codespeak.net afa at codespeak.net
Wed Feb 11 00:30:42 CET 2009


Author: afa
Date: Wed Feb 11 00:30:39 2009
New Revision: 61705

Modified:
   pypy/trunk/pypy/lib/_ctypes/structure.py
   pypy/trunk/pypy/lib/app_test/ctypes_tests/test_structures.py
Log:
ctypes Structure instances accept extra attributes, and simply store them in the __dict__.


Modified: pypy/trunk/pypy/lib/_ctypes/structure.py
==============================================================================
--- pypy/trunk/pypy/lib/_ctypes/structure.py	(original)
+++ pypy/trunk/pypy/lib/_ctypes/structure.py	Wed Feb 11 00:30:39 2009
@@ -181,7 +181,7 @@
         try:
             fieldtype = self._fieldtypes[name].ctype
         except KeyError:
-            raise AttributeError(name)
+            return _CData.__setattr__(self, name, value)
         if ensure_objects(value) is not None:
             key = keepalive_key(getattr(self.__class__, name).num)
             store_reference(self, key, value._objects)

Modified: pypy/trunk/pypy/lib/app_test/ctypes_tests/test_structures.py
==============================================================================
--- pypy/trunk/pypy/lib/app_test/ctypes_tests/test_structures.py	(original)
+++ pypy/trunk/pypy/lib/app_test/ctypes_tests/test_structures.py	Wed Feb 11 00:30:39 2009
@@ -384,6 +384,13 @@
         assert p.name == "John Doe"
         assert p.age == 25
 
+    def test_setattr(self):
+        class X(Structure):
+            _fields_ = [("a", c_int)]
+
+        x = X()
+        x.other = 42
+        assert x.other == 42
 
 class TestPointerMember(BaseCTypesTestChecker):
 



More information about the Pypy-commit mailing list