diff options
author | Armin Rigo <arigo@tunes.org> | 2020-01-05 13:46:20 +0100 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2020-01-05 13:46:20 +0100 |
commit | 263cff26c5edcb9e77990078faec25431303c107 (patch) | |
tree | a38e038b27165ef09c7298912ddf758d0374b3c8 /cffi/api.py | |
parent | 0e3aa45f0edb076fe282461509d8a19effd3d8f5 (diff) | |
download | cffi-263cff26c5edcb9e77990078faec25431303c107.tar.gz |
Issue #437
Support ffi.dlopen(<void* cdata>). See updated documentation.
Diffstat (limited to 'cffi/api.py')
-rw-r--r-- | cffi/api.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/cffi/api.py b/cffi/api.py index 32fe620..999a8ae 100644 --- a/cffi/api.py +++ b/cffi/api.py @@ -141,7 +141,11 @@ class FFI(object): linked to a particular library, just like C headers; in the library we only look for the actual (untyped) symbols. """ - assert isinstance(name, basestring) or name is None + if not (isinstance(name, basestring) or + name is None or + isinstance(name, self.CData)): + raise TypeError("dlopen(name): name must be a file name, None, " + "or an already-opened 'void *' handle") with self._lock: lib, function_cache = _make_ffi_library(self, name, flags) self._function_caches.append(function_cache) @@ -799,9 +803,9 @@ class FFI(object): def _load_backend_lib(backend, name, flags): import os - if name is None: - if sys.platform != "win32": - return backend.load_library(None, flags) + if not isinstance(name, basestring): + if sys.platform != "win32" or name is not None: + return backend.load_library(name, flags) name = "c" # Windows: load_library(None) fails, but this works # on Python 2 (backward compatibility hack only) first_error = None @@ -935,7 +939,7 @@ def _make_ffi_library(ffi, libname, flags): backendlib.close_lib() self.__dict__.clear() # - if libname is not None: + if isinstance(libname, basestring): try: if not isinstance(libname, str): # unicode, on Python 2 libname = libname.encode('utf-8') |