[pypy-svn] r79868 - in pypy/trunk/pypy: interpreter module/imp
arigo at codespeak.net
arigo at codespeak.net
Tue Dec 7 17:16:13 CET 2010
Author: arigo
Date: Tue Dec 7 17:16:11 2010
New Revision: 79868
Modified:
pypy/trunk/pypy/interpreter/mixedmodule.py
pypy/trunk/pypy/module/imp/importing.py
Log:
Fix issue557 by tweaking what occurs when reload()ing a built-in module.
Now the state that is saved and restored should be the state after
the module is first imported *and* after startup() has been called.
Modified: pypy/trunk/pypy/interpreter/mixedmodule.py
==============================================================================
--- pypy/trunk/pypy/interpreter/mixedmodule.py (original)
+++ pypy/trunk/pypy/interpreter/mixedmodule.py Tue Dec 7 17:16:11 2010
@@ -13,6 +13,10 @@
applevel_name = None
expose__file__attribute = True
+
+ # The following attribute is None as long as the module has not been
+ # imported yet, and when it has been, it is mod.__dict__.items() just
+ # after startup().
w_initialdict = None
def __init__(self, space, w_name):
@@ -26,8 +30,14 @@
"""This is called each time the module is imported or reloaded
"""
if self.w_initialdict is not None:
+ # the module was already imported. Refresh its content with
+ # the saved dict, as done with built-in and extension modules
+ # on CPython.
space.call_method(self.w_dict, 'update', self.w_initialdict)
- Module.init(self, space)
+ else:
+ Module.init(self, space)
+ if not self.lazy and self.w_initialdict is None:
+ self.w_initialdict = space.call_method(self.w_dict, 'items')
def get_applevel_name(cls):
""" NOT_RPYTHON """
@@ -96,6 +106,7 @@
def _freeze_(self):
self.getdict()
+ self.w_initialdict = None
self.startup_called = False
# hint for the annotator: Modules can hold state, so they are
# not constant
Modified: pypy/trunk/pypy/module/imp/importing.py
==============================================================================
--- pypy/trunk/pypy/module/imp/importing.py (original)
+++ pypy/trunk/pypy/module/imp/importing.py Tue Dec 7 17:16:11 2010
@@ -529,7 +529,7 @@
space.sys.setmodule(w_module)
raise
finally:
- space.reloading_modules.clear()
+ del space.reloading_modules[modulename]
# __________________________________________________________________
More information about the Pypy-commit
mailing list