[pypy-commit] pypy test-cpyext: Move implementation of load_module to SystemCompilationInfo subclasses

rlamy pypy.commits at gmail.com
Tue Sep 13 11:34:09 EDT 2016


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: test-cpyext
Changeset: r87078:c88d32f9692f
Date: 2016-09-13 16:33 +0100
http://bitbucket.org/pypy/pypy/changeset/c88d32f9692f/

Log:	Move implementation of load_module to SystemCompilationInfo
	subclasses

diff --git a/pypy/module/cpyext/test/test_cpyext.py b/pypy/module/cpyext/test/test_cpyext.py
--- a/pypy/module/cpyext/test/test_cpyext.py
+++ b/pypy/module/cpyext/test/test_cpyext.py
@@ -82,6 +82,25 @@
         soname.rename(pydname)
         return str(pydname)
 
+class ExtensionCompiler(SystemCompilationInfo):
+    """Extension compiler for appdirect mode"""
+    def load_module(space, mod, name):
+        import imp
+        return imp.load_dynamic(name, mod)
+
+class SpaceCompiler(SystemCompilationInfo):
+    """Extension compiler for regular (untranslated PyPy) mode"""
+    def __init__(self, space, *args, **kwargs):
+        self.space = space
+        SystemCompilationInfo.__init__(self, *args, **kwargs)
+
+    def load_module(self, mod, name):
+        space = self.space
+        api.load_extension_module(space, mod, name)
+        return space.getitem(
+            space.sys.get('modules'), space.wrap(name))
+
+
 def get_cpyext_info(space):
     from pypy.module.imp.importing import get_so_extension
     state = space.fromcache(State)
@@ -102,7 +121,7 @@
             link_extra = ["-g"]
         else:
             compile_extra = link_extra = None
-    return SystemCompilationInfo(
+    return SpaceCompiler(space,
         include_extra=api.include_dirs,
         compile_extra=compile_extra,
         link_extra=link_extra,
@@ -132,7 +151,7 @@
             "-O0", "-g", "-Werror=implicit-function-declaration", "-fPIC"]
         link_extra = None
     ext = get_so_suffix()
-    return SystemCompilationInfo(
+    return ExtensionCompiler(
         include_extra=[get_python_inc()],
         compile_extra=compile_extra,
         link_extra=link_extra,
@@ -411,7 +430,7 @@
                 kwds = dict(source_files=[filename])
             mod = self.sys_info.compile_extension_module(
                 name, include_dirs=include_dirs, **kwds)
-            w_result = load_module(space, mod, name)
+            w_result = self.sys_info.load_module(mod, name)
             if not self.runappdirect:
                 self.record_imported_module(name)
             return w_result
@@ -419,13 +438,7 @@
 
         @gateway.unwrap_spec(mod=str, name=str)
         def load_module(space, mod, name):
-            if self.runappdirect:
-                import imp
-                return imp.load_dynamic(name, mod)
-            else:
-                api.load_extension_module(space, mod, name)
-                return space.getitem(
-                    space.sys.get('modules'), space.wrap(name))
+            return self.sys_info.load_module(mod, name)
 
         @gateway.unwrap_spec(modname=str, prologue=str,
                              more_init=str, PY_SSIZE_T_CLEAN=bool)


More information about the pypy-commit mailing list