summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2013-02-22 14:19:57 +0100
committerArmin Rigo <arigo@tunes.org>2013-02-22 14:19:57 +0100
commit6e5929152f128bbc166666b88a1b3c95534042c2 (patch)
tree3f08f2872220150dbe303b04d8d0d420fc2cfcd6
parent9eead7af80b1908b399c9a0941a2b9dfc3bc3189 (diff)
downloadcffi-6e5929152f128bbc166666b88a1b3c95534042c2.tar.gz
(lazka, arigo) Change dlopen() to accept either a full path or a library
name.
-rw-r--r--cffi/api.py14
-rw-r--r--doc/source/index.rst6
-rw-r--r--testing/test_function.py11
3 files changed, 21 insertions, 10 deletions
diff --git a/cffi/api.py b/cffi/api.py
index 664f6fc..58b720e 100644
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -345,17 +345,17 @@ def _make_ffi_library(ffi, libname, flags):
name = libname
if name is None:
name = 'c' # on Posix only
- if os.path.sep in name or (
- os.path.altsep is not None and os.path.altsep in name):
- path = name
- else:
+ backend = ffi._backend
+ try:
+ if '.' not in name and '/' not in name:
+ raise OSError
+ backendlib = backend.load_library(name, flags)
+ except OSError:
import ctypes.util
path = ctypes.util.find_library(name)
if path is None:
raise OSError("library not found: %r" % (name,))
- #
- backend = ffi._backend
- backendlib = backend.load_library(path, flags)
+ backendlib = backend.load_library(path, flags)
#
def make_accessor(name):
key = 'function ' + name
diff --git a/doc/source/index.rst b/doc/source/index.rst
index 28f3de0..6fa600c 100644
--- a/doc/source/index.rst
+++ b/doc/source/index.rst
@@ -439,9 +439,9 @@ the functions from the correct one.
The ``libpath`` is the file name of the shared library, which can
contain a full path or not (in which case it is searched in standard
-locations, as described in ``man dlopen``). Alternatively, if
-``libpath`` is None, it returns the standard C library (which can be
-used to access the functions of glibc, on Linux).
+locations, as described in ``man dlopen``), with extensions or not.
+Alternatively, if ``libpath`` is None, it returns the standard C library
+(which can be used to access the functions of glibc, on Linux).
This gives ABI-level access to the library: you need to have all types
declared manually exactly as they were while the library was made. No
diff --git a/testing/test_function.py b/testing/test_function.py
index fddd938..0ae18c5 100644
--- a/testing/test_function.py
+++ b/testing/test_function.py
@@ -69,6 +69,17 @@ class TestFunction(object):
x = m.sin(1.23)
assert x is None
+ def test_dlopen_filename(self):
+ if not os.path.exists('/ib/libm.so.6'):
+ py.test.skip("/lib/libm.so.6 does not exist")
+ ffi = FFI(backend=self.Backend())
+ ffi.cdef("""
+ double cos(double x);
+ """)
+ m = ffi.dlopen("/lib/libm.so.6")
+ x = m.cos(1.23)
+ assert x == math.cos(1.23)
+
def test_dlopen_flags(self):
ffi = FFI(backend=self.Backend())
ffi.cdef("""