[pypy-commit] pypy default: Add caching for the debug flag for skipping asserts
waedt
noreply at buildbot.pypy.org
Tue Jun 4 11:58:38 CEST 2013
Author: Tyler Wade <wayedt at gmail.com>
Branch:
Changeset: r64754:c8d597cf7e85
Date: 2013-04-29 04:29 -0500
http://bitbucket.org/pypy/pypy/changeset/c8d597cf7e85/
Log: Add caching for the debug flag for skipping asserts
diff --git a/pypy/bin/pyinteractive.py b/pypy/bin/pyinteractive.py
--- a/pypy/bin/pyinteractive.py
+++ b/pypy/bin/pyinteractive.py
@@ -101,8 +101,8 @@
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
diff --git a/pypy/interpreter/app_main.py b/pypy/interpreter/app_main.py
--- a/pypy/interpreter/app_main.py
+++ b/pypy/interpreter/app_main.py
@@ -451,8 +451,8 @@
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, (
diff --git a/pypy/interpreter/astcompiler/test/test_compiler.py b/pypy/interpreter/astcompiler/test/test_compiler.py
--- a/pypy/interpreter/astcompiler/test/test_compiler.py
+++ b/pypy/interpreter/astcompiler/test/test_compiler.py
@@ -846,21 +846,17 @@
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:
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -877,11 +877,7 @@
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
diff --git a/pypy/module/__pypy__/__init__.py b/pypy/module/__pypy__/__init__.py
--- a/pypy/module/__pypy__/__init__.py
+++ b/pypy/module/__pypy__/__init__.py
@@ -57,6 +57,7 @@
'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'
diff --git a/pypy/module/__pypy__/interp_magic.py b/pypy/module/__pypy__/interp_magic.py
--- a/pypy/module/__pypy__/interp_magic.py
+++ b/pypy/module/__pypy__/interp_magic.py
@@ -101,3 +101,11 @@
@unwrap_spec(sizehint=int)
def newlist_hint(space, sizehint):
return space.newlist_hint(sizehint)
+
+ at 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))
diff --git a/pypy/module/sys/__init__.py b/pypy/module/sys/__init__.py
--- a/pypy/module/sys/__init__.py
+++ b/pypy/module/sys/__init__.py
@@ -7,7 +7,7 @@
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
@@ -18,6 +18,7 @@
self.w_default_encoder = None
self.defaultencoding = "ascii"
self.filesystemencoding = None
+ self.debug = True
interpleveldefs = {
'__name__' : '(space.wrap("sys"))',
More information about the pypy-commit
mailing list