Commits

Tyler Wade committed c8d597c

Add caching for the debug flag for skipping asserts

Comments (0)

Files changed (7)

pypy/bin/pyinteractive.py

             flags = list(sys.flags)
             flags[6] = 2
             sys.flags = type(sys.flags)(flags)
-            import __builtin__
-            setattr(__builtin__, '__debug__', False)
+            import __pypy__
+            __pypy__.set_debug(False)
         """)
 
     # call pypy_find_stdlib: the side-effect is that it sets sys.prefix and

pypy/interpreter/app_main.py

         sys.dont_write_bytecode = bool(sys.flags.dont_write_bytecode)
 
         if sys.flags.optimize >= 1:
-            import __builtin__
-            setattr(__builtin__, '__debug__', False)
+            import __pypy__
+            __pypy__.set_debug(False)
 
         if sys.py3kwarning:
             print >> sys.stderr, (

pypy/interpreter/astcompiler/test/test_compiler.py

 
     def test_assert_skipping(self):
         space = self.space
+        mod = space.getbuiltinmodule('__pypy__')
+        w_set_debug = space.getattr(mod, space.wrap('set_debug'))
+        space.call_function(w_set_debug, space.w_False)
+
         source = """if 1:
         assert False
         """
-        w_saved_flags = space.sys.get('flags')
-        space.appexec([], """():
-            import sys
-            flags = list(sys.flags)
-            flags[6] = 2
-            sys.flags = type(sys.flags)(flags)
-        """)
-
         try:
             self.run(source)
         finally:
-            space.sys.w_dict.setitem(space.wrap('flags'), w_saved_flags)
+            space.call_function(w_set_debug, space.w_True)
 
 
 class AppTestCompiler:

pypy/interpreter/pyopcode.py

         return next_instr
 
     def JUMP_IF_NOT_DEBUG(self, target, next_instr):
-        try:
-            optimize = self.space.sys.get_flag('optimize')
-        except:
-            optimize = 0
-        if optimize >= 1:
+        if not self.space.sys.debug:
             return target
         return next_instr
 

pypy/module/__pypy__/__init__.py

         'newlist_hint'              : 'interp_magic.newlist_hint',
         'newdict'                   : 'interp_dict.newdict',
         'dictstrategy'              : 'interp_dict.dictstrategy',
+        'set_debug'                 : 'interp_magic.set_debug',
     }
     if sys.platform == 'win32':
         interpleveldefs['get_console_cp'] = 'interp_magic.get_console_cp'

pypy/module/__pypy__/interp_magic.py

 @unwrap_spec(sizehint=int)
 def newlist_hint(space, sizehint):
     return space.newlist_hint(sizehint)
+
+@unwrap_spec(debug=bool)
+def set_debug(space, debug):
+    print debug
+    space.sys.debug = debug
+    space.setitem(space.builtin.w_dict,
+                  space.wrap('__debug__'),
+                  space.wrap(debug))

pypy/module/sys/__init__.py

 
 class Module(MixedModule):
     """Sys Builtin Module. """
-    _immutable_fields_ = ["defaultencoding?"]
+    _immutable_fields_ = ["defaultencoding?", "debug?"]
 
     def __init__(self, space, w_name):
         """NOT_RPYTHON""" # because parent __init__ isn't
         self.w_default_encoder = None
         self.defaultencoding = "ascii"
         self.filesystemencoding = None
+        self.debug = True
 
     interpleveldefs = {
         '__name__'              : '(space.wrap("sys"))', 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.