[pypy-svn] r40032 - in pypy/dist/pypy: interpreter module/posix

ac at codespeak.net ac at codespeak.net
Wed Mar 7 16:32:26 CET 2007


Author: ac
Date: Wed Mar  7 16:32:25 2007
New Revision: 40032

Modified:
   pypy/dist/pypy/interpreter/baseobjspace.py
   pypy/dist/pypy/interpreter/module.py
   pypy/dist/pypy/module/posix/__init__.py
   pypy/dist/pypy/module/posix/interp_posix.py
Log:
Add a startup method to Module to allow modules to do runtime initialization.
Make posix module use the startup method to initialize the environ dict.



Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py	Wed Mar  7 16:32:25 2007
@@ -197,7 +197,17 @@
 
     def startup(self):
         # To be called before using the space
-        pass
+
+        # Initialize all builtin modules
+        from pypy.interpreter.module import Module
+        for modname in self._builtinmodule_list:
+            try:
+                mod = self.getbuiltinmodule(modname)
+            except OperationError:
+                # Not found, ignore it.
+                continue
+            if isinstance(mod, Module):
+                mod.startup(self)
 
     def finish(self):
         w_exitfunc = self.sys.getdictvalue_w(self, 'exitfunc')

Modified: pypy/dist/pypy/interpreter/module.py
==============================================================================
--- pypy/dist/pypy/interpreter/module.py	(original)
+++ pypy/dist/pypy/interpreter/module.py	Wed Mar  7 16:32:25 2007
@@ -20,6 +20,11 @@
         """NOT_RPYTHON: to allow built-in modules to do some more setup
         after the space is fully initialized."""
 
+    def startup(self, space):
+        """This is called at runtime before the space gets uses to allow
+        the module to do initialization at runtime.
+        """
+        
     def getdict(self):
         return self.w_dict
 

Modified: pypy/dist/pypy/module/posix/__init__.py
==============================================================================
--- pypy/dist/pypy/module/posix/__init__.py	(original)
+++ pypy/dist/pypy/module/posix/__init__.py	Wed Mar  7 16:32:25 2007
@@ -90,6 +90,10 @@
         if config.translating and config.translation.backend == "llvm":
             space.delattr(self, space.wrap("execv"))
 
+    def startup(self, space):
+        from pypy.module.posix import interp_posix
+        interp_posix.get(space).startup(space)
+        
 for constant in dir(os):
     value = getattr(os, constant)
     if constant.isupper() and type(value) is int:

Modified: pypy/dist/pypy/module/posix/interp_posix.py
==============================================================================
--- pypy/dist/pypy/module/posix/interp_posix.py	(original)
+++ pypy/dist/pypy/module/posix/interp_posix.py	Wed Mar  7 16:32:25 2007
@@ -259,7 +259,9 @@
     def __init__(self, space): 
         self.posix_putenv_garbage = {}
         self.w_environ = space.newdict()
+    def startup(self, space):
         _convertenviron(space, self.w_environ)
+
 def get(space): 
     return space.fromcache(State) 
 



More information about the Pypy-commit mailing list