Author: Armin Rigo <[email protected]>
Branch: hpy
Changeset: r98094:bc9e1d24a759
Date: 2019-11-17 11:03 +0100
http://bitbucket.org/pypy/pypy/changeset/bc9e1d24a759/

Log:    Reintroduce hpy_universal.load(), but keeping .load_from_spec() too

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
@@ -63,19 +63,21 @@
     return handles.consume(space, h_module)
 
 def descr_load_from_spec(space, w_spec):
-    # XXX: this looks a lot like cpyext.api.create_extension_module()
+    name = space.text_w(space.getattr(w_spec, space.newtext("name")))
+    origin = space.fsencode_w(space.getattr(w_spec, space.newtext("origin")))
+    return descr_load(space, name, origin)
+
+@unwrap_spec(name='text', libpath='fsencode')
+def descr_load(space, name, libpath):
     state = space.fromcache(State)
     state.setup()
-    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:
+        with rffi.scoped_str2charp(libpath) as ll_libname:
             lib = dlopen(ll_libname, space.sys.dlopenflags)
     except DLOpenError as e:
-        w_path = space.newfilename(origin)
+        w_path = space.newfilename(libpath)
         raise raise_import_error(space,
-            space.newfilename(e.msg), w_name, w_path)
+            space.newfilename(e.msg), space.newtext(name), w_path)
 
     basename = name.split('.')[-1]
     init_name = 'HPyInit_' + basename
@@ -83,8 +85,8 @@
         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)
+            init_name, space.utf8_w(space.newfilename(libpath)))
+        w_path = space.newfilename(libpath)
         raise raise_import_error(
-            space, space.newtext(msg), w_name, w_path)
-    return create_hpy_module(space, name, origin, lib, initptr)
+            space, space.newtext(msg), space.newtext(name), w_path)
+    return create_hpy_module(space, name, libpath, 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,6 @@
     appleveldefs = {}
 
     interpleveldefs = {
-        'load_from_spec': 'interp_hpy.descr_load_from_spec'
+        'load_from_spec': 'interp_hpy.descr_load_from_spec',
+        'load': 'interp_hpy.descr_load',
     }
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to