def load_lib(self): if not self._is_inited: load_paths = rt.deref(rt.deref(rt.load_paths)) for x in range(rt.count(load_paths)): s = rffi.str2charp( str(rt.name(rt.nth(load_paths, rt.wrap(x)))) + "/" + str(self._name)) try: self._dyn_lib = dynload.dlopen(s) self._is_inited = True except dynload.DLOpenError as ex: continue finally: rffi.free_charp(s) break if not self._is_inited: s = rffi.str2charp(str(self._name)) try: self._dyn_lib = dynload.dlopen(s) self._is_inited = True except dynload.DLOpenError as ex: raise object.runtime_error( u"Couldn't Load Library: " + self._name, u"pixie.stdlib/LibraryNotFoundException") finally: rffi.free_charp(s)
def load_lib(self): if not self._is_inited: load_paths = rt.deref(rt.deref(rt.load_paths)) for x in range(rt.count(load_paths)): s = rffi.str2charp(str(rt.name(rt.nth(load_paths, rt.wrap(x)))) + "/" + str(self._name)) try: self._dyn_lib = dynload.dlopen(s) self._is_inited = True except dynload.DLOpenError as ex: continue finally: rffi.free_charp(s) break if not self._is_inited: s = rffi.str2charp(str(self._name)) try: self._dyn_lib = dynload.dlopen(s) self._is_inited = True except dynload.DLOpenError as ex: raise object.runtime_error(u"Couldn't Load Library: " + self._name, u"pixie.stdlib/LibraryNotFoundException") finally: rffi.free_charp(s)
def load_extension_module(space, path, name): if os.sep not in path: path = os.curdir + os.sep + path # force a '/' in the path state = space.fromcache(State) if state.find_extension(name, path) is not None: return old_context = state.package_context state.package_context = name, path try: from rpython.rlib import rdynload try: ll_libname = rffi.str2charp(path) try: dll = rdynload.dlopen(ll_libname) finally: lltype.free(ll_libname, flavor='raw') except rdynload.DLOpenError, e: raise oefmt(space.w_ImportError, "unable to load extension module '%s': %s", path, e.msg) try: initptr = rdynload.dlsym(dll, 'init%s' % (name.split('.')[-1],)) except KeyError: raise oefmt(space.w_ImportError, "function init%s not found in library %s", name, path) initfunc = rffi.cast(initfunctype, initptr) generic_cpy_call(space, initfunc) state.check_and_raise_exception()
def load_extension_module(space, path, name): if os.sep not in path: path = os.curdir + os.sep + path # force a '/' in the path state = space.fromcache(State) if state.find_extension(name, path) is not None: return old_context = state.package_context state.package_context = name, path try: from rpython.rlib import rdynload try: ll_libname = rffi.str2charp(path) try: dll = rdynload.dlopen(ll_libname) finally: lltype.free(ll_libname, flavor='raw') except rdynload.DLOpenError, e: raise operationerrfmt( space.w_ImportError, "unable to load extension module '%s': %s", path, e.msg) try: initptr = rdynload.dlsym(dll, 'init%s' % (name.split('.')[-1],)) except KeyError: raise operationerrfmt( space.w_ImportError, "function init%s not found in library %s", name, path) initfunc = rffi.cast(initfunctype, initptr) generic_cpy_call(space, initfunc) state.check_and_raise_exception()
def _(name, apispec): apispec = null if apispec is None else apispec path = rffi.str2charp(as_cstring(name)) try: lib = rdynload.dlopen(path) except rdynload.DLOpenError, e: raise unwind(LLoadError(name))
def builtin_ffi_dynload(ctx): assert len( ctx.params ) == 2 and ctx.params[0].type == 'str' and ctx.params[0].type == 'str' libname = ctx.params[0].strvalue libpath = ctx.params[1].strvalue # load dylib if haven't if libname in ctx.machine.space.ffi_libs: ctx.tos.push(ctx.machine.space.null) return # try to load dylib path = rffi.str2charp(libpath) try: lib = rdynload.dlopen(path) except rdynload.DLOpenError as e: ctx.machine.error = ctx.machine.space.newstr( 'unable to load library: %s' % libname) return finally: lltype.free(path, flavor='raw') # cache dylib ctx.machine.space.ffi_libs[libname] = ctx.machine.space.newforeignlibrary( libname, lib) ctx.tos.push(ctx.machine.space.null)
def __init__(self, ffi, filename, flags): with rffi.scoped_str2charp(filename) as ll_libname: if filename is None: filename = "<None>" try: handle = dlopen(ll_libname, flags) except DLOpenError, e: raise wrap_dlopenerror(ffi.space, e, filename)
def load_and_initialize(self, module_name): from rpython.rlib.rdynload import dlopen, dlsym, dlclose, DLOpenError import os c_name = rffi.str2charp(os.path.join(IProxy.space.executable_path(), module_name)) try: module = dlopen(c_name) except DLOpenError, e: rffi.free_charp(c_name) raise MissingPlugin
def load_and_initialize(self, module_name): from rpython.rlib.rdynload import dlopen, dlsym, dlclose, DLOpenError import os c_name = rffi.str2charp(os.path.join(IProxy.space.executable_path(), module_name)) try: module = dlopen(c_name) except DLOpenError, e: rffi.free_charp(c_name) raise error.PrimitiveFailedError
def _(argv): if len(argv) < 1: raise Error(u"library requires at least a path name") name = argument(argv, 0, String) apispec = argv[1] if len(argv) > 1 else null path = rffi.str2charp(as_cstring(name)) try: lib = rdynload.dlopen(path) except rdynload.DLOpenError, e: raise Error(u"Unable to load library: " + e.msg.decode('utf-8'))
def __init__(self, ffi, filename, flags): with rffi.scoped_str2charp(filename) as ll_libname: if filename is None: filename = "<None>" try: handle = dlopen(ll_libname, flags) except DLOpenError as e: raise wrap_dlopenerror(ffi.space, e, filename) W_LibObject.__init__(self, ffi, filename) self.libhandle = handle self.register_finalizer(ffi.space)
def __init__(self, space, filename, flags): self.space = space with rffi.scoped_str2charp(filename) as ll_libname: if filename is None: filename = "<None>" try: self.handle = dlopen(ll_libname, flags) except DLOpenError as e: raise wrap_dlopenerror(space, e, filename) self.name = filename self.register_finalizer(space)
def thaw(self): if not self._is_inited: s = rffi.str2charp(str(self._name)) try: self._dyn_lib = dynload.dlopen(s) except dynload.DLOpenError as ex: raise object.WrappedException(object.RuntimeException(rt.wrap(ex.msg))) finally: rffi.free_charp(s) self._is_inited = True
def thaw(self): if not self._is_inited: s = rffi.str2charp(str(self._name)) try: self._dyn_lib = dynload.dlopen(s) except dynload.DLOpenError as ex: raise object.WrappedException( object.RuntimeException(rt.wrap(ex.msg))) finally: rffi.free_charp(s) self._is_inited = True
def dlopen_w(space, w_filename, flags): from pypy.module._cffi_backend.cdataobj import W_CData from pypy.module._cffi_backend import ctypeptr autoclose = True if isinstance(w_filename, W_CData): # 'flags' ignored in this case w_ctype = w_filename.ctype if (not isinstance(w_ctype, ctypeptr.W_CTypePointer) or not w_ctype.is_void_ptr): raise oefmt( space.w_TypeError, "dlopen() takes a file name or 'void *' handle, not '%s'", w_ctype.name) handle = w_filename.unsafe_escaping_ptr() if not handle: raise oefmt(space.w_RuntimeError, "cannot call dlopen(NULL)") fname = w_ctype.extra_repr(handle) handle = rffi.cast(DLLHANDLE, handle) autoclose = False # elif WIN32 and space.isinstance_w(w_filename, space.w_unicode): fname = space.text_w(space.repr(w_filename)) utf8_name = space.utf8_w(w_filename) uni_len = space.len_w(w_filename) with rffi.scoped_utf82wcharp(utf8_name, uni_len) as ll_libname: try: handle = dlopenU(ll_libname, flags) except DLOpenError as e: raise wrap_dlopenerror(space, e, fname) else: if space.is_none(w_filename): fname = None else: fname = space.fsencode_w(w_filename) with rffi.scoped_str2charp(fname) as ll_libname: if fname is None: fname = "<None>" try: handle = dlopen(ll_libname, flags) except DLOpenError as e: raise wrap_dlopenerror(space, e, fname) return fname, handle, autoclose
def dlopen_w(space, w_filename, flags): if WIN32 and space.isinstance_w(w_filename, space.w_unicode): fname = space.text_w(space.repr(w_filename)) unicode_name = space.unicode_w(w_filename) with rffi.scoped_unicode2wcharp(unicode_name) as ll_libname: try: handle = dlopenU(ll_libname, flags) except DLOpenError as e: raise wrap_dlopenerror(space, e, fname) else: if space.is_none(w_filename): fname = None else: fname = space.fsencode_w(w_filename) with rffi.scoped_str2charp(fname) as ll_libname: if fname is None: fname = "<None>" try: handle = dlopen(ll_libname, flags) except DLOpenError as e: raise wrap_dlopenerror(space, e, fname) return fname, handle
def descr_load(space, name, libpath): state = space.fromcache(State) state.setup() try: with rffi.scoped_str2charp(libpath) as ll_libname: lib = dlopen(ll_libname, space.sys.dlopenflags) except DLOpenError as e: w_path = space.newfilename(libpath) raise raise_import_error(space, space.newfilename(e.msg), space.newtext(name), w_path) basename = name.split('.')[-1] init_name = 'HPyInit_' + basename try: initptr = dlsym(lib, init_name) except KeyError: msg = b"function %s not found in library %s" % ( init_name, space.utf8_w(space.newfilename(libpath))) w_path = space.newfilename(libpath) raise raise_import_error(space, space.newtext(msg), space.newtext(name), w_path) return create_hpy_module(space, name, libpath, lib, initptr)
def __init__(self, libname, mode=-1): """Load the library, or raises DLOpenError.""" self.lib = rffi.cast(DLLHANDLE, 0) with rffi.scoped_str2charp(libname) as ll_libname: self.lib = dlopen(ll_libname, mode)
def __init__(self, libname, mode=-1): """Load the library, or raises DLOpenError.""" RawCDLL.__init__(self, rffi.cast(DLLHANDLE, -1)) with rffi.scoped_str2charp(libname) as ll_libname: self.lib = dlopen(ll_libname, mode)
rootincpath = [] rootlibpath = [] def identify(): return 'Cling' ts_reflect = False ts_call = 'auto' ts_memory = 'auto' ts_helper = 'auto' std_string_name = 'std::basic_string<char>' # force loading (and exposure) of libCore symbols with rffi.scoped_str2charp('libCore.so') as ll_libname: _coredll = rdynload.dlopen(ll_libname, rdynload.RTLD_GLOBAL | rdynload.RTLD_NOW) # require local translator path to pickup common defs from rpython.translator import cdir translator_c_dir = py.path.local(cdir) eci = ExternalCompilationInfo( separate_module_files=[srcpath.join("clingcwrapper.cxx")], include_dirs=[incpath, translator_c_dir] + rootincpath, includes=["clingcwrapper.h"], library_dirs=rootlibpath, libraries=["Cling"], compile_extra=["-fno-strict-aliasing", "-std=c++11"], use_cpp_linker=True, )
def __init__(self, libname, mode=-1, lib=0): """Load the library, or raises DLOpenError.""" self.lib = rffi.cast(DLLHANDLE, lib) if lib == 0: with rffi.scoped_str2charp(libname) as ll_libname: self.lib = dlopen(ll_libname, mode)
def identify(): return 'Cling' ts_reflect = False ts_call = 'auto' ts_memory = 'auto' ts_helper = 'auto' std_string_name = 'std::basic_string<char>' # force loading (and exposure) of libCore symbols with rffi.scoped_str2charp('libCore.so') as ll_libname: _coredll = rdynload.dlopen(ll_libname, rdynload.RTLD_GLOBAL | rdynload.RTLD_NOW) # require local translator path to pickup common defs from rpython.translator import cdir translator_c_dir = py.path.local(cdir) eci = ExternalCompilationInfo( separate_module_files=[srcpath.join("clingcwrapper.cxx")], include_dirs=[incpath, translator_c_dir] + rootincpath, includes=["clingcwrapper.h"], library_dirs=rootlibpath, libraries=["Cling"], compile_extra=["-fno-strict-aliasing", "-std=c++11"], use_cpp_linker=True, )