[pypy-svn] r50879 - in pypy/dist/pypy/lib: _ctypes app_test/ctypes
fijal at codespeak.net
fijal at codespeak.net
Tue Jan 22 14:22:23 CET 2008
Author: fijal
Date: Tue Jan 22 14:22:22 2008
New Revision: 50879
Modified:
pypy/dist/pypy/lib/_ctypes/structure.py
pypy/dist/pypy/lib/app_test/ctypes/test_structures.py
Log:
Some patology and a test for it
Modified: pypy/dist/pypy/lib/_ctypes/structure.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/structure.py (original)
+++ pypy/dist/pypy/lib/_ctypes/structure.py Tue Jan 22 14:22:22 2008
@@ -142,11 +142,13 @@
value = fieldtype._CData_input(value)
self._buffer.__setattr__(name, value[0])
- def __getattr__(self, name):
+ def __getattribute__(self, name):
+ if name == '_fieldtypes':
+ return _CData.__getattribute__(self, '_fieldtypes')
try:
fieldtype = self._fieldtypes[name].ctype
except KeyError:
- raise AttributeError(name)
+ return _CData.__getattribute__(self, name)
return fieldtype._CData_output(self._subarray(fieldtype, name))
def _get_buffer_for_param(self):
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:22:22 2008
@@ -420,3 +420,14 @@
else:
raise AssertionError, "AttributeError not raised"
+
+class TestPatologicalCases:
+ def test_structure_overloading_getattr(self):
+ class X(Structure):
+ _fields_ = [('x', c_int)]
+
+ def __getattr__(self, name):
+ raise AttributeError, name
+
+ x = X()
+ assert x.x == 0
More information about the Pypy-commit
mailing list