[pypy-svn] r70178 - pypy/branch/import-builtin/pypy/interpreter

afa at codespeak.net afa at codespeak.net
Thu Dec 17 18:02:48 CET 2009


Author: afa
Date: Thu Dec 17 18:02:48 2009
New Revision: 70178

Modified:
   pypy/branch/import-builtin/pypy/interpreter/baseobjspace.py
   pypy/branch/import-builtin/pypy/interpreter/mixedmodule.py
   pypy/branch/import-builtin/pypy/interpreter/module.py
Log:
Attempt to support the sys.setdefaultencoding hack:
keep a copy of the dict module when freezing,
and use it when reloading the module.


Modified: pypy/branch/import-builtin/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/branch/import-builtin/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/branch/import-builtin/pypy/interpreter/baseobjspace.py	Thu Dec 17 18:02:48 2009
@@ -281,10 +281,9 @@
                 raise
             modname = self.str_w(w_modname)
             mod = self.interpclass_w(w_mod)
-            if isinstance(mod, Module) and not mod.startup_called:
+            if isinstance(mod, Module):
                 self.timer.start("startup " + modname)
-                mod.startup(self)
-                mod.startup_called = True
+                mod.init(self)
                 self.timer.stop("startup " + modname)
 
 
@@ -372,10 +371,9 @@
             # And initialize it
             from pypy.interpreter.module import Module
             mod = self.interpclass_w(w_mod)
-            if isinstance(mod, Module) and not mod.startup_called:
+            if isinstance(mod, Module):
                 self.timer.start("startup " + name)
-                mod.startup(self)
-                mod.startup_called = True
+                mod.init(self)
                 self.timer.stop("startup " + name)
             return w_mod
 

Modified: pypy/branch/import-builtin/pypy/interpreter/mixedmodule.py
==============================================================================
--- pypy/branch/import-builtin/pypy/interpreter/mixedmodule.py	(original)
+++ pypy/branch/import-builtin/pypy/interpreter/mixedmodule.py	Thu Dec 17 18:02:48 2009
@@ -13,7 +13,8 @@
 
     applevel_name = None
     expose__file__attribute = True
-    
+    w_initialdict = None
+
     def __init__(self, space, w_name): 
         """ NOT_RPYTHON """ 
         Module.__init__(self, space, w_name) 
@@ -21,6 +22,13 @@
         self.__class__.buildloaders()
         self.loaders = self.loaders.copy()    # copy from the class to the inst
 
+    def init(self, space):
+        """This is called each time the module is imported or reloaded
+        """
+        if self.w_initialdict is not None:
+            space.call_method(self.w_dict, 'update', self.w_initialdict)
+        Module.init(self, space)
+
     def get_applevel_name(cls):
         """ NOT_RPYTHON """
         if cls.applevel_name is not None:
@@ -86,7 +94,7 @@
         return self.w_dict 
 
     def _freeze_(self):
-        self.getdict()
+        self.w_initialdict = self.space.call_method(self.getdict(), 'copy')
         self.startup_called = False
         # hint for the annotator: Modules can hold state, so they are
         # not constant

Modified: pypy/branch/import-builtin/pypy/interpreter/module.py
==============================================================================
--- pypy/branch/import-builtin/pypy/interpreter/module.py	(original)
+++ pypy/branch/import-builtin/pypy/interpreter/module.py	Thu Dec 17 18:02:48 2009
@@ -22,6 +22,13 @@
         """NOT_RPYTHON: to allow built-in modules to do some more setup
         after the space is fully initialized."""
 
+    def init(self, space):
+        """This is called each time the module is imported or reloaded
+        """
+        if not self.startup_called:
+            self.startup_called = True
+            self.startup(space)
+
     def startup(self, space):
         """This is called at runtime on import to allow the module to
         do initialization when it is imported for the first time.



More information about the Pypy-commit mailing list