Author: Ronan Lamy <[email protected]>
Branch: hpy
Changeset: r98080:b0b337fc4202
Date: 2019-11-16 20:51 +0100
http://bitbucket.org/pypy/pypy/changeset/b0b337fc4202/
Log: Replace hpy_universal.load() with hpy_universal.load_from_spec()
diff --git a/pypy/module/hpy_universal/interp_hpy.py
b/pypy/module/hpy_universal/interp_hpy.py
--- a/pypy/module/hpy_universal/interp_hpy.py
+++ b/pypy/module/hpy_universal/interp_hpy.py
@@ -39,28 +39,29 @@
h_module = generic_cpy_call_dont_convert_result(space, initfunc, state.ctx)
return handles.consume(space, h_module)
-@unwrap_spec(origin='fsencode', init_name='text')
-def descr_load(space, origin, init_name):
+def descr_load_from_spec(space, w_spec):
# XXX: this looks a lot like cpyext.api.create_extension_module()
state = space.fromcache(State)
state.setup()
- name = init_name[len('HPyInit_'):]
+ w_name = space.getattr(w_spec, space.newtext("name"))
+ name = space.text_w(w_name)
+ origin = space.text_w(space.getattr(w_spec, space.newtext("origin")))
try:
with rffi.scoped_str2charp(origin) as ll_libname:
lib = dlopen(ll_libname, space.sys.dlopenflags)
except DLOpenError as e:
w_path = space.newfilename(origin)
- w_name = space.newtext(name)
raise raise_import_error(space,
space.newfilename(e.msg), w_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(origin)))
w_path = space.newfilename(origin)
- w_name = space.newtext(name)
raise raise_import_error(
space, space.newtext(msg), w_name, w_path)
return create_hpy_module(space, name, origin, lib, initptr)
diff --git a/pypy/module/hpy_universal/moduledef.py
b/pypy/module/hpy_universal/moduledef.py
--- a/pypy/module/hpy_universal/moduledef.py
+++ b/pypy/module/hpy_universal/moduledef.py
@@ -5,5 +5,5 @@
appleveldefs = {}
interpleveldefs = {
- 'load': 'interp_hpy.descr_load'
+ 'load_from_spec': 'interp_hpy.descr_load_from_spec'
}
diff --git a/pypy/module/hpy_universal/test/support.py
b/pypy/module/hpy_universal/test/support.py
--- a/pypy/module/hpy_universal/test/support.py
+++ b/pypy/module/hpy_universal/test/support.py
@@ -25,6 +25,14 @@
pytest.skip()
cls.compiler = ExtensionCompiler(udir)
+ w_FakeSpec = cls.space.appexec([], """():
+ class FakeSpec:
+ def __init__(self, name, origin):
+ self.name = name
+ self.origin = origin
+ return FakeSpec
+ """)
+
@unwrap_spec(source_template='text', name='text')
def descr_make_module(space, source_template, name='mytest'):
source = _support.expand_template(source_template, name)
@@ -38,10 +46,10 @@
universal_mode=True)
#
w_mod = space.appexec(
- [space.newtext(so_filename), space.newtext(name)],
- """(path, modname):
- from hpy_universal import load
- return load(path, 'HPyInit_' + modname)
+ [w_FakeSpec, space.newtext(so_filename), space.newtext(name)],
+ """(FakeSpec, path, modname):
+ from hpy_universal import load_from_spec
+ return load_from_spec(FakeSpec(modname, path))
"""
)
return w_mod
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit