[pypy-svn] r58183 - in pypy/dist/pypy/interpreter: . test

arigo at codespeak.net arigo at codespeak.net
Tue Sep 16 19:28:54 CEST 2008


Author: arigo
Date: Tue Sep 16 19:28:53 2008
New Revision: 58183

Modified:
   pypy/dist/pypy/interpreter/mixedmodule.py
   pypy/dist/pypy/interpreter/test/test_appinterp.py
Log:
Test and fix.


Modified: pypy/dist/pypy/interpreter/mixedmodule.py
==============================================================================
--- pypy/dist/pypy/interpreter/mixedmodule.py	(original)
+++ pypy/dist/pypy/interpreter/mixedmodule.py	Tue Sep 16 19:28:53 2008
@@ -19,6 +19,7 @@
         Module.__init__(self, space, w_name) 
         self.lazy = True 
         self.__class__.buildloaders()
+        self.loaders = self.loaders.copy()    # copy from the class to the inst
 
     def get_applevel_name(cls):
         """ NOT_RPYTHON """

Modified: pypy/dist/pypy/interpreter/test/test_appinterp.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_appinterp.py	(original)
+++ pypy/dist/pypy/interpreter/test/test_appinterp.py	Tue Sep 16 19:28:53 2008
@@ -132,3 +132,30 @@
                     assert name in module.__dict__
         """)
         assert space.is_true(w_module.call('somefunc'))
+
+    def test_whacking_at_loaders(self):
+        """Some MixedModules change 'self.loaders' in __init__(), but doing
+        so they incorrectly mutated a class attribute.  'loaders' is now a
+        per-instance attribute, holding a fresh copy of the dictionary.
+        """
+        from pypy.interpreter.mixedmodule import MixedModule
+        from pypy.conftest import maketestobjspace
+
+        class MyModule(MixedModule):
+            interpleveldefs = {}
+            appleveldefs = {}
+            def __init__(self, space, w_name):
+                def loader(myspace):
+                    assert myspace is space
+                    return myspace.wrap("hello")
+                MixedModule.__init__(self, space, w_name)
+                self.loaders["hi"] = loader
+
+        space1 = self.space
+        w_mymod1 = MyModule(space1, space1.wrap('mymod'))
+
+        space2 = maketestobjspace()
+        w_mymod2 = MyModule(space2, space2.wrap('mymod'))
+
+        w_str = space1.getattr(w_mymod1, space1.wrap("hi"))
+        assert space1.str_w(w_str) == "hello"



More information about the Pypy-commit mailing list