1. Christoph Reiter
  2. pypy

Commits

Christoph Reiter  committed 09e0aaf

Fix translation

  • Participants
  • Parent commits 939ce8f
  • Branches cpyext-import-ex

Comments (0)

Files changed (2)

File pypy/module/cpyext/import_.py

View file
  • Ignore whitespace
     return space.call_function(w_import,
                                w_name, w_globals, w_locals, w_fromlist, w_level)
 
-@cpython_api([PyObject, PyObject, PyObject, PyObject, rffi.INT_real], PyObject)
-def PyImport_ImportModuleLevel(space, w_name, w_globals, w_locals, w_fromlist, w_level):
+@cpython_api([CONST_STRING, PyObject, PyObject, PyObject, rffi.INT_real], PyObject)
+def PyImport_ImportModuleLevel(space, name, w_globals, w_locals, w_fromlist, level):
     """
     Import a module. This is best described by referring to the built-in
     Python function __import__(), as the standard __import__() function
     else:
         w_builtin = space.getbuiltinmodule('__builtin__')
 
+    w_name = space.wrap(rffi.charp2str(name))
+    w_level = space.wrap(rffi.cast(lltype.Signed, level))
+
     return _import(space, w_builtin, w_name, w_globals, w_locals,
                    w_fromlist, w_level)
 
-@cpython_api([PyObject, PyObject, PyObject, PyObject], PyObject)
-def PyImport_ImportModuleEx(space, w_name, w_globals, w_locals, w_fromlist):
+@cpython_api([CONST_STRING, PyObject, PyObject, PyObject], PyObject)
+def PyImport_ImportModuleEx(space, name, w_globals, w_locals, w_fromlist):
     """
     Import a module. This is best described by referring to the built-in
     Python function __import__(), as the standard __import__() function
 
     The function is an alias for PyImport_ImportModuleLevel() with -1 as level,
     meaning relative import."""
-    return PyImport_ImportModuleLevel(space, w_name, w_globals, w_locals, w_fromlist, space.wrap(-1))
+    return PyImport_ImportModuleLevel(
+        space, name, w_globals, w_locals, w_fromlist, -1)
 
 @cpython_api([PyObject], PyObject)
 def PyImport_Import(space, w_name):

File pypy/module/cpyext/test/test_import.py

View file
  • Ignore whitespace
         assert space.getattr(stat, space.wrap("S_IMODE"))
 
     def test_import_ext(self, space, api):
-        w_ospath = api.PyImport_ImportModuleEx(
-            space.wrap("os.path"), None, None, space.wrap(["foo"]))
-        assert w_ospath
+        with rffi.scoped_str2charp("os.path") as modname:
+            w_ospath = api.PyImport_ImportModuleEx(
+                modname, None, None, space.wrap(["foo"]))
+            assert w_ospath
 
         import os.path as ospath
         assert space.unwrap(space.getattr(w_ospath, space.wrap('__name__'))) == ospath.__name__
 
     def test_import_module_level(self, space, api):
-        w_stat = api.PyImport_ImportModuleLevel(
-            space.wrap("stat"), None, None, space.newdict(), space.wrap(0))
+        with rffi.scoped_str2charp("stat") as modname:
+            w_stat = api.PyImport_ImportModuleLevel(
+                modname, None, None, space.newdict(), 0)
         assert w_stat
         assert w_stat is space.getitem(space.sys.get("modules"), space.wrap("stat"))