[pypy-svn] r7269 - in pypy/trunk/src/pypy/interpreter: . test

mgedmin at codespeak.net mgedmin at codespeak.net
Tue Nov 16 11:15:12 CET 2004


Author: mgedmin
Date: Tue Nov 16 11:15:12 2004
New Revision: 7269

Modified:
   pypy/trunk/src/pypy/interpreter/pyopcode.py
   pypy/trunk/src/pypy/interpreter/test/test_interpreter.py
Log:
Bugfix: when an import statement was executed in a function without a locals
dict, a plain unwrapped None could be passed into space.call_function causing
assertion errors later on.



Modified: pypy/trunk/src/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/pyopcode.py	(original)
+++ pypy/trunk/src/pypy/interpreter/pyopcode.py	Tue Nov 16 11:15:12 2004
@@ -614,8 +614,11 @@
                 raise
             raise OperationError(space.w_ImportError,
                                  space.wrap("__import__ not found"))
+        w_locals = f.w_locals
+        if w_locals is None:            # CPython does this
+            w_locals = space.w_None
         w_obj = space.call_function(w_import, space.wrap(modulename),
-                                    f.w_globals, f.w_locals, w_fromlist)
+                                    f.w_globals, w_locals, w_fromlist)
         f.valuestack.push(w_obj)
 
     def IMPORT_STAR(f):

Modified: pypy/trunk/src/pypy/interpreter/test/test_interpreter.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/test/test_interpreter.py	(original)
+++ pypy/trunk/src/pypy/interpreter/test/test_interpreter.py	Tue Nov 16 11:15:12 2004
@@ -1,4 +1,5 @@
 import autopath
+import textwrap
 from pypy.tool import testit
 
 class TestInterpreter(testit.TestCase):
@@ -142,6 +143,24 @@
         self.assertEquals(self.codetest(code, 'f', [9]),
                           1+2+3 + 5+6+7+8+900)
 
+    def test_import(self):
+        # Regression test for a bug in PyInterpFrame.IMPORT_NAME: when an
+        # import statement was executed in a function without a locals dict, a
+        # plain unwrapped None could be passed into space.call_function causing
+        # assertion errors later on.
+        real_call_function = self.space.call_function
+        def safe_call_function(w_obj, *arg_w):
+            for arg in arg_w:
+                assert arg is not None
+            return real_call_function(w_obj, *arg_w)
+        self.space.call_function = safe_call_function
+        code = textwrap.dedent('''
+            def f():
+                import sys
+            ''')
+        self.codetest(code, 'f', [])
+
+
 class AppTestInterpreter(testit.AppTestCase):
     def test_trivial(self):
         x = 42



More information about the Pypy-commit mailing list