[pypy-svn] r47183 - in pypy/dist/pypy/rpython/lltypesystem: . test
fijal at codespeak.net
fijal at codespeak.net
Fri Oct 5 11:21:01 CEST 2007
Author: fijal
Date: Fri Oct 5 11:21:00 2007
New Revision: 47183
Modified:
pypy/dist/pypy/rpython/lltypesystem/ll2ctypes.py
pypy/dist/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
Log:
Use lib[func_name] instead of lib.func_name to be safe regarding double
function gets (ie different signatures), needed for fcntl
Modified: pypy/dist/pypy/rpython/lltypesystem/ll2ctypes.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/ll2ctypes.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/ll2ctypes.py Fri Oct 5 11:21:00 2007
@@ -512,6 +512,14 @@
# ____________________________________________
def get_ctypes_callable(funcptr, calling_conv):
+ def get_on_lib(lib, elem):
+ """ Wrapper to always use lib[func] instead of lib.func
+ """
+ try:
+ return lib[elem]
+ except AttributeError:
+ pass
+
if getattr(funcptr._obj, 'sources', None):
# give up - for tests with an inlined bit of C code
raise NotImplementedError("cannot call a C function defined in "
@@ -520,10 +528,10 @@
funcname = funcptr._obj._name
libraries = getattr(funcptr._obj, 'libraries', None)
if not libraries:
- cfunc = getattr(standard_c_lib, funcname, None)
+ cfunc = get_on_lib(standard_c_lib, funcname)
# XXX magic: on Windows try to load the function from 'kernel32' too
if cfunc is None and hasattr(ctypes, 'windll'):
- cfunc = getattr(ctypes.windll.kernel32, funcname, None)
+ cfunc = get_on_lib(ctypes.windll.kernel32, funcname)
else:
cfunc = None
for libname in libraries:
@@ -533,7 +541,7 @@
if libpath:
dllclass = getattr(ctypes, calling_conv + 'dll')
clib = dllclass.LoadLibrary(libpath)
- cfunc = getattr(clib, funcname, None)
+ cfunc = get_on_lib(clib, funcname)
if cfunc is not None:
break
Modified: pypy/dist/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/test/test_ll2ctypes.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/test/test_ll2ctypes.py Fri Oct 5 11:21:00 2007
@@ -665,3 +665,13 @@
assert res == pycrypt("pass", "ab")
rffi.free_charp(r)
assert not ALLOCATED
+
+ def test_different_signatures(self):
+ fcntl_int = rffi.llexternal('fcntl', [rffi.INT, rffi.INT, rffi.INT],
+ rffi.INT)
+ fcntl_str = rffi.llexternal('fcntl', [rffi.INT, rffi.INT, rffi.CCHARP],
+ rffi.INT)
+ fcntl_int(12345, 1, 0)
+ fcntl_str(12345, 3, "xxx")
+ fcntl_int(12345, 1, 0)
+
More information about the Pypy-commit
mailing list