[pypy-svn] r61836 - in pypy/trunk/pypy/lib: _ctypes app_test/ctypes_tests
afa at codespeak.net
afa at codespeak.net
Fri Feb 13 16:32:46 CET 2009
Author: afa
Date: Fri Feb 13 16:32:44 2009
New Revision: 61836
Modified:
pypy/trunk/pypy/lib/_ctypes/function.py
pypy/trunk/pypy/lib/app_test/ctypes_tests/support.py
pypy/trunk/pypy/lib/app_test/ctypes_tests/test_checkretval.py
Log:
Implement _check_retval_, and unskip some tests
Modified: pypy/trunk/pypy/lib/_ctypes/function.py
==============================================================================
--- pypy/trunk/pypy/lib/_ctypes/function.py (original)
+++ pypy/trunk/pypy/lib/_ctypes/function.py Fri Feb 13 16:32:44 2009
@@ -55,7 +55,10 @@
not callable(restype):
raise TypeError("Expected ctypes type, got %s" % (restype,))
self._restype_ = restype
- restype = property(_getrestype, _setrestype)
+ def _delrestype(self):
+ self._ptr = None
+ del self._restype_
+ restype = property(_getrestype, _setrestype, _delrestype)
def _ffishapes(self, args, restype):
argtypes = [arg._ffiargshape for arg in args]
@@ -260,6 +263,23 @@
If there is no OUT parameter, return the actual function result
If there is one OUT parameter, return it
If there are many OUT parameters, return a tuple"""
+
+ retval = None
+
+ if restype is not None:
+ checker = getattr(self.restype, '_check_retval_', None)
+ if checker:
+ val = restype(resbuffer[0])
+ # the original ctypes seems to make the distinction between
+ # classes defining a new type, and their subclasses
+ if '_type_' in restype.__dict__:
+ val = val.value
+ retval = checker(val)
+ elif not isinstance(restype, _CDataMeta):
+ retval = restype(resbuffer[0])
+ else:
+ retval = restype._CData_retval(resbuffer)
+
results = []
if self._paramflags:
for argtype, (_, obj), paramflag in zip(argtypes[1:], argsandobjs[1:],
@@ -282,10 +302,7 @@
return tuple(results)
# No output parameter, return the actual function result.
- if restype is not None:
- if not isinstance(restype, _CDataMeta):
- return restype(resbuffer[0])
- return restype._CData_retval(resbuffer)
+ return retval
def __del__(self):
if self._needs_free:
Modified: pypy/trunk/pypy/lib/app_test/ctypes_tests/support.py
==============================================================================
--- pypy/trunk/pypy/lib/app_test/ctypes_tests/support.py (original)
+++ pypy/trunk/pypy/lib/app_test/ctypes_tests/support.py Fri Feb 13 16:32:44 2009
@@ -8,7 +8,7 @@
def setup_class(cls):
try:
- import _rawffi
+ import _rawffi
except ImportError:
py.test.skip("these tests are white-box tests for pypy _rawffi based ctypes impl")
Modified: pypy/trunk/pypy/lib/app_test/ctypes_tests/test_checkretval.py
==============================================================================
--- pypy/trunk/pypy/lib/app_test/ctypes_tests/test_checkretval.py (original)
+++ pypy/trunk/pypy/lib/app_test/ctypes_tests/test_checkretval.py Fri Feb 13 16:32:44 2009
@@ -16,8 +16,6 @@
class TestRetval:
def test_checkretval(self):
- py.test.skip("_check_retval_ is not supported")
-
assert 42 == dll._testfunc_p_p(42)
dll._testfunc_p_p.restype = CHECKED
@@ -35,7 +33,6 @@
pass
else:
def test_oledll(self):
- py.test.skip("_check_retval_ is not supported")
raises(WindowsError,
- oledll.oleaut32.CreateTypeLib2,
- 0, 0, 0)
+ oledll.oleaut32.CreateTypeLib2,
+ 0, 0, 0)
More information about the Pypy-commit
mailing list