[pypy-svn] r25433 - in pypy/dist/pypy: objspace/flow translator/c/test

tismer at codespeak.net tismer at codespeak.net
Thu Apr 6 06:14:57 CEST 2006


Author: tismer
Date: Thu Apr  6 06:14:54 2006
New Revision: 25433

Modified:
   pypy/dist/pypy/objspace/flow/objspace.py
   pypy/dist/pypy/translator/c/test/test_wrapping.py
Log:
protect flow space from write access to globals.

(actually, the intention is to detect global imports and resolve them as constant)

Modified: pypy/dist/pypy/objspace/flow/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/flow/objspace.py	(original)
+++ pypy/dist/pypy/objspace/flow/objspace.py	Thu Apr  6 06:14:54 2006
@@ -603,6 +603,16 @@
     FlowObjSpace.regular_getattr = FlowObjSpace.getattr
     FlowObjSpace.getattr = getattr
 
+    # protect us from globals access
+    def setitem(self, w_obj, w_key, w_val):
+        ec = self.getexecutioncontext()
+        if not (ec and w_obj is ec.w_globals):
+            return self.regular_setitem(w_obj, w_key, w_val)
+        raise SyntaxError, "attempt to write global attribute %r in %r" % (w_key, ec.graph.func)
+
+    FlowObjSpace.regular_setitem = FlowObjSpace.setitem
+    FlowObjSpace.setitem = setitem
+
 override()
 
 # ______________________________________________________________________

Modified: pypy/dist/pypy/translator/c/test/test_wrapping.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_wrapping.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_wrapping.py	Thu Apr  6 06:14:54 2006
@@ -343,8 +343,15 @@
 
 ### XXX write up the rules how to use this ###
 
+def t2():
+    global sys
+    import sys
+
 def setup_new_module(mod, modname):
     # note the name clash with py.test on setup_module
+    #t1()
+    #t2()
+    return
     from types import module
     m = module(modname)
     allobjs = mod.__dict__.values()



More information about the Pypy-commit mailing list