[pypy-svn] r61775 - in pypy/trunk/pypy/lib: _ctypes app_test/ctypes_tests
afa at codespeak.net
afa at codespeak.net
Thu Feb 12 13:21:09 CET 2009
Author: afa
Date: Thu Feb 12 13:21:08 2009
New Revision: 61775
Modified:
pypy/trunk/pypy/lib/_ctypes/pointer.py
pypy/trunk/pypy/lib/app_test/ctypes_tests/test_parameters.py
Log:
Functions expecting POINTER(A) should allow pointers to subclasses of A.
test and fix.
Modified: pypy/trunk/pypy/lib/_ctypes/pointer.py
==============================================================================
--- pypy/trunk/pypy/lib/_ctypes/pointer.py (original)
+++ pypy/trunk/pypy/lib/_ctypes/pointer.py Thu Feb 12 13:21:08 2009
@@ -38,7 +38,7 @@
if isinstance(value, self._type_):
return byref(value)
# Array instances are also pointers when the item types are the same.
- if isinstance(value, Array):
+ if isinstance(value, (_Pointer, Array)):
if issubclass(type(value)._type_, self._type_):
return value
return _CDataMeta.from_param(self, value)
Modified: pypy/trunk/pypy/lib/app_test/ctypes_tests/test_parameters.py
==============================================================================
--- pypy/trunk/pypy/lib/app_test/ctypes_tests/test_parameters.py (original)
+++ pypy/trunk/pypy/lib/app_test/ctypes_tests/test_parameters.py Thu Feb 12 13:21:08 2009
@@ -49,6 +49,18 @@
assert CWCHARP.from_param("abc") == "abcabcabc"
+ def test_pointer_subclasses(self):
+ from ctypes import *
+
+ Void_pp = POINTER(c_void_p)
+ class My_void_p(c_void_p):
+ pass
+
+ My_void_pp = POINTER(My_void_p)
+ o = My_void_pp()
+
+ assert Void_pp.from_param(o) is o
+
# XXX Replace by c_char_p tests
def test_cstrings(self):
py.test.skip("testing implementation internals")
More information about the Pypy-commit
mailing list