[pypy-svn] r66155 - in pypy/trunk/pypy/rpython/lltypesystem: . test
fijal at codespeak.net
fijal at codespeak.net
Fri Jul 10 09:02:31 CEST 2009
Author: fijal
Date: Fri Jul 10 09:02:31 2009
New Revision: 66155
Modified:
pypy/trunk/pypy/rpython/lltypesystem/ll2ctypes.py
pypy/trunk/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
Log:
A test and a fix for library in library_paths, but not in libraries.
Modified: pypy/trunk/pypy/rpython/lltypesystem/ll2ctypes.py
==============================================================================
--- pypy/trunk/pypy/rpython/lltypesystem/ll2ctypes.py (original)
+++ pypy/trunk/pypy/rpython/lltypesystem/ll2ctypes.py Fri Jul 10 09:02:31 2009
@@ -19,6 +19,7 @@
from pypy.rpython.lltypesystem.rclass import OBJECT
from pypy.rpython.annlowlevel import base_ptr_lltype
from pypy.rpython import raddress
+from pypy.translator.platform import platform
def uaddressof(obj):
return fixid(ctypes.addressof(obj))
@@ -813,10 +814,21 @@
cfunc = get_on_lib(ctypes.windll.kernel32, funcname)
else:
cfunc = None
+ not_found = []
for libname in libraries:
- libpath = ctypes.util.find_library(libname)
- if not libpath and os.path.isabs(libname):
- libpath = libname
+ libpath = None
+ ext = platform.so_ext
+ prefixes = platform.so_prefixes
+ for dir in eci.library_dirs:
+ for prefix in prefixes:
+ tryfile = os.path.join(dir, prefix + libname + '.' + ext)
+ if os.path.isfile(tryfile):
+ libpath = tryfile
+ break
+ if not libpath:
+ libpath = ctypes.util.find_library(libname)
+ if not libpath and os.path.isabs(libname):
+ libpath = libname
if libpath:
dllclass = getattr(ctypes, calling_conv + 'dll')
# urgh, cannot pass the flag to dllclass.LoadLibrary
@@ -824,11 +836,20 @@
cfunc = get_on_lib(clib, funcname)
if cfunc is not None:
break
+ else:
+ not_found.append(libname)
if cfunc is None:
# function name not found in any of the libraries
if not libraries:
place = 'the standard C library (missing libraries=...?)'
+ elif len(not_found) == len(libraries):
+ if len(not_found) == 1:
+ raise NotImplementedError(
+ 'cannot find the library %r' % (not_found[0],))
+ else:
+ raise NotImplementedError(
+ 'cannot find any of the libraries %r' % (not_found,))
elif len(libraries) == 1:
place = 'library %r' % (libraries[0],)
else:
Modified: pypy/trunk/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
==============================================================================
--- pypy/trunk/pypy/rpython/lltypesystem/test/test_ll2ctypes.py (original)
+++ pypy/trunk/pypy/rpython/lltypesystem/test/test_ll2ctypes.py Fri Jul 10 09:02:31 2009
@@ -15,6 +15,7 @@
from pypy.rpython.test.test_llinterp import interpret
from pypy.annotation.annrpython import RPythonAnnotator
from pypy.rpython.rtyper import RPythonTyper
+from pypy.tool.udir import udir
class TestLL2Ctypes(object):
@@ -994,3 +995,21 @@
v2 = ctypes2lltype(llmemory.GCREF, ctypes.c_void_p(1235))
assert v2 != v
+class TestPlatform(object):
+ def test_lib_on_libpaths(self):
+ from pypy.translator.platform import platform
+ from pypy.translator.tool.cbuild import ExternalCompilationInfo
+
+ tmpdir = udir.join('lib_on_libppaths')
+ tmpdir.ensure(dir=1)
+ c_file = tmpdir.join('c_file.c')
+ c_file.write('int f(int a, int b) { return (a + b); }')
+ eci = ExternalCompilationInfo()
+ so = platform.compile([c_file], eci, standalone=False)
+ eci = ExternalCompilationInfo(
+ libraries = ['c_file'],
+ library_dirs = [str(so.dirpath())]
+ )
+ f = rffi.llexternal('f', [rffi.INT, rffi.INT], rffi.INT,
+ compilation_info=eci)
+ assert f(3, 4) == 7
More information about the Pypy-commit
mailing list