Commits

Amaury Forgeot d'Arc committed ac4d1d5

Implement imp.load_dynamic(), which loads a cpyext dll.

Comments (0)

Files changed (3)

pypy/module/cpyext/test/test_cpyext.py

         assert module.__doc__ == "docstring"
         assert module.return_cookie() == 3.14
 
+    def test_load_dynamic(self):
+        import sys
+        init = """
+        if (Py_IsInitialized())
+            Py_InitModule("foo", NULL);
+        """
+        foo = self.import_module(name='foo', init=init)
+        assert 'foo' in sys.modules
+        del sys.modules['foo']
+        import imp
+        foo2 = imp.load_dynamic('foo', foo.__file__)
+        assert 'foo' in sys.modules
+        assert foo.__dict__ == foo2.__dict__
 
     def test_InitModule4_dotted(self):
         """

pypy/module/imp/__init__.py

         'load_module':     'interp_imp.load_module',
         'load_source':     'interp_imp.load_source',
         'load_compiled':   'interp_imp.load_compiled',
+        'load_dynamic':    'interp_imp.load_dynamic',
         '_run_compiled_module': 'interp_imp._run_compiled_module',   # pypy
         '_getimporter':    'importing._getimporter',                 # pypy
         #'run_module':      'interp_imp.run_module',
         }
 
     appleveldefs = {
-        'load_dynamic':    'app_imp.load_dynamic',
         }
 
     def __init__(self, space, *args):

pypy/module/imp/interp_imp.py

     _run_compiled_module(space, w_modulename, filename, w_file, w_mod)
     return w_mod
 
+@unwrap_spec(filename=str)
+def load_dynamic(space, w_modulename, filename, w_file=None):
+    importing.load_c_extension(space, filename, space.str_w(w_modulename))
+    return importing.check_sys_modules(space, w_modulename)
+
 def new_module(space, w_name):
     return space.wrap(Module(space, w_name))