def load_cffi1_module(space, name, path, initptr): # This is called from pypy.module.cpyext.api.load_extension_module() from pypy.module._cffi_backend.call_python import get_ll_cffi_call_python initfunc = rffi.cast(INITFUNCPTR, initptr) with lltype.scoped_alloc(rffi.VOIDPP.TO, 16, zero=True) as p: p[0] = rffi.cast(rffi.VOIDP, VERSION_EXPORT) p[1] = rffi.cast(rffi.VOIDP, get_ll_cffi_call_python()) initfunc(p) version = rffi.cast(lltype.Signed, p[0]) if not (VERSION_MIN <= version <= VERSION_MAX): raise oefmt( space.w_ImportError, "cffi extension module '%s' uses an unknown version tag %s. " "This module might need a more recent version of PyPy. " "The current PyPy provides CFFI %s.", name, hex(version), _cffi_backend.VERSION) src_ctx = rffi.cast(parse_c_type.PCTX, p[1]) ffi = W_FFIObject(space, src_ctx) lib = W_LibObject(ffi, name) if src_ctx.c_includes: lib.make_includes_from(src_ctx.c_includes) w_name = space.newtext(name) module = Module(space, w_name) if path is not None: module.setdictvalue(space, '__file__', space.newtext(path)) module.setdictvalue(space, 'ffi', ffi) module.setdictvalue(space, 'lib', lib) w_modules_dict = space.sys.get('modules') space.setitem(w_modules_dict, w_name, module) space.setitem(w_modules_dict, space.newtext(name + '.lib'), lib) return module
def load_cffi1_module(space, name, path, initptr): # This is called from pypy.module.cpyext.api.load_extension_module() initfunc = rffi.cast(initfunctype, initptr) with lltype.scoped_alloc(rffi.VOIDPP.TO, 2) as p: p[0] = rffi.cast(rffi.VOIDP, VERSION_EXPORT) initfunc(p) version = rffi.cast(lltype.Signed, p[0]) if not (VERSION_MIN <= version <= VERSION_MAX): raise oefmt(space.w_ImportError, "cffi extension module '%s' has unknown version %s", name, hex(version)) src_ctx = rffi.cast(parse_c_type.PCTX, p[1]) ffi = W_FFIObject(space, src_ctx) lib = W_LibObject(ffi, name) if src_ctx.c_includes: lib.make_includes_from(src_ctx.c_includes) w_name = space.wrap(name) module = Module(space, w_name) module.setdictvalue(space, '__file__', space.wrap(path)) module.setdictvalue(space, 'ffi', space.wrap(ffi)) module.setdictvalue(space, 'lib', space.wrap(lib)) w_modules_dict = space.sys.get('modules') space.setitem(w_modules_dict, w_name, space.wrap(module)) space.setitem(w_modules_dict, space.wrap(name + '.lib'), space.wrap(lib))
def load_cffi1_module(space, name, path, initptr): # This is called from pypy.module.cpyext.api.load_extension_module() from pypy.module._cffi_backend.call_python import get_ll_cffi_call_python initfunc = rffi.cast(INITFUNCPTR, initptr) with lltype.scoped_alloc(rffi.VOIDPP.TO, 16, zero=True) as p: p[0] = rffi.cast(rffi.VOIDP, VERSION_EXPORT) p[1] = rffi.cast(rffi.VOIDP, get_ll_cffi_call_python()) initfunc(p) version = rffi.cast(lltype.Signed, p[0]) if not (VERSION_MIN <= version <= VERSION_MAX): raise oefmt(space.w_ImportError, "cffi extension module '%s' uses an unknown version tag %s. " "This module might need a more recent version of PyPy. " "The current PyPy provides CFFI %s.", name, hex(version), _cffi_backend.VERSION) src_ctx = rffi.cast(parse_c_type.PCTX, p[1]) ffi = W_FFIObject(space, src_ctx) lib = W_LibObject(ffi, name) if src_ctx.c_includes: lib.make_includes_from(src_ctx.c_includes) w_name = space.wrap(name) module = Module(space, w_name) if path is not None: module.setdictvalue(space, '__file__', space.wrap(path)) module.setdictvalue(space, 'ffi', space.wrap(ffi)) module.setdictvalue(space, 'lib', space.wrap(lib)) w_modules_dict = space.sys.get('modules') space.setitem(w_modules_dict, w_name, space.wrap(module)) space.setitem(w_modules_dict, space.wrap(name + '.lib'), space.wrap(lib))
def __init__(self, ffi, w_filename, flags): space = ffi.space fname, handle, autoclose = misc.dlopen_w(space, w_filename, flags) W_LibObject.__init__(self, ffi, fname) self.libhandle = handle if autoclose: self.register_finalizer(space)
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)
class W_DlOpenLibObject(W_LibObject): 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) W_LibObject.__init__(self, ffi, filename) self.libhandle = handle