[pypy-commit] pypy fix_bool_restype: Fix issue 2475: bool restypes not working
Graham Markall
pypy.commits at gmail.com
Sun Feb 19 07:03:30 EST 2017
Author: Graham Markall <graham.markall at embecosm.com>
Branch: fix_bool_restype
Changeset: r90196:9bb716c6f836
Date: 2017-02-15 18:44 +0000
http://bitbucket.org/pypy/pypy/changeset/9bb716c6f836/
Log: Fix issue 2475: bool restypes not working
This commit adds a check to the performance hack in
CFuncPtr._wrap_result that doesn't use the hack when the return type
is bool, because a new bool object needs to be created.
A test of a C function with a bool restype is added.
diff --git a/lib_pypy/_ctypes/function.py b/lib_pypy/_ctypes/function.py
--- a/lib_pypy/_ctypes/function.py
+++ b/lib_pypy/_ctypes/function.py
@@ -604,7 +604,8 @@
"""
# hack for performance: if restype is a "simple" primitive type, don't
# allocate the buffer because it's going to be thrown away immediately
- if self._is_primitive(restype) and not restype._is_pointer_like():
+ if (self._is_primitive(restype) and restype._type_ != '?'
+ and not restype._is_pointer_like()):
return result
#
shape = restype._ffishape_
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py b/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py
@@ -99,6 +99,15 @@
result = f(0, 0, 0, 0, 0, 0)
assert result == '\x00'
+ def test_boolresult(self):
+ f = dll._testfunc_i_bhilfd
+ f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_double]
+ f.restype = c_bool
+ false_result = f(0, 0, 0, 0, 0, 0)
+ assert false_result is False
+ true_result = f(1, 0, 0, 0, 0, 0)
+ assert true_result is True
+
def test_voidresult(self):
f = dll._testfunc_v
f.restype = None
More information about the pypy-commit
mailing list