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 pypy.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 getpointer(self, name, argtypes, restype, flags=FUNCFLAG_CDECL): return Func(name, argtypes, restype, dlsym(self.lib, name), flags=flags, keepalive=self)
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 pypy.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 getpointer(self, name, argtypes, restype, flags=FUNCFLAG_STDCALL): return Func(name, argtypes, restype, dlsym(self.lib, name), flags=flags, keepalive=self)
def getaddressindll(self, name): return dlsym(self.lib, name)
def getrawpointer(self, name, argtypes, restype, flags=FUNCFLAG_CDECL): # these arguments are already casted to proper ffi # structures! return RawFuncPtr(name, argtypes, restype, dlsym(self.lib, name), flags=flags, keepalive=self)