[pypy-issue] Issue #2475: ctypes restype appears to have no effect (pypy/pypy)
Graham Markall
issues-reply at bitbucket.org
Wed Feb 15 07:07:53 EST 2017
New issue 2475: ctypes restype appears to have no effect
https://bitbucket.org/pypy/pypy/issues/2475/ctypes-restype-appears-to-have-no-effect
Graham Markall:
Compiling the following C source with gcc -shared -fPIC -o libtest.so test.c
int f() { return 0; }
int t() { return 1; }
int t2() { return 2; }
and then executing:
import ctypes
import os
lib = ctypes.CDLL(os.path.join(os.getcwd(), 'libtest.so'))
lib.f.restype = ctypes.c_bool
lib.t.restype = ctypes.c_bool
lib.t2.restype = ctypes.c_bool
print lib.f(), type(lib.f())
print lib.t(), type(lib.t())
print lib.t2(), type(lib.t2())
produces different results between CPython and PyPy. On PyPy 5.6.0 I get:
$ pypy test.py
0 <type 'int'>
1 <type 'int'>
2 <type 'int'>
whereas with CPython 2.7.13 I get:
$ python test.py
False <type 'bool'>
True <type 'bool'>
True <type 'bool'>
It appears as if setting restype has no effect - should this be expected to work under PyPy?
More information about the pypy-issue
mailing list