Author: Brian Kearns <[email protected]>
Branch: stdlib-2.7.6
Changeset: r69626:81b36fff2b15
Date: 2014-03-02 20:05 -0500
http://bitbucket.org/pypy/pypy/changeset/81b36fff2b15/
Log: merge default
diff --git a/lib_pypy/cffi/vengine_cpy.py b/lib_pypy/cffi/vengine_cpy.py
--- a/lib_pypy/cffi/vengine_cpy.py
+++ b/lib_pypy/cffi/vengine_cpy.py
@@ -897,11 +897,13 @@
if (c_api_object == NULL)
return;
if (!PyCapsule_CheckExact(c_api_object)) {
+ Py_DECREF(c_api_object);
PyErr_SetNone(PyExc_ImportError);
return;
}
memcpy(_cffi_exports, PyCapsule_GetPointer(c_api_object, "cffi"),
_CFFI_NUM_EXPORTS * sizeof(void *));
+ Py_DECREF(c_api_object);
}
#define _cffi_type(num) ((CTypeDescrObject *)PyList_GET_ITEM(_cffi_types, num))
diff --git a/pypy/doc/getting-started-dev.rst b/pypy/doc/getting-started-dev.rst
--- a/pypy/doc/getting-started-dev.rst
+++ b/pypy/doc/getting-started-dev.rst
@@ -315,27 +315,27 @@
.. _`trace example`:
-Tracing bytecode and operations on objects
-++++++++++++++++++++++++++++++++++++++++++
+Tracing bytecodes
++++++++++++++++++
-You can use the trace object space to monitor the interpretation
-of bytecodes in connection with object space operations. To enable
-it, set ``__pytrace__=1`` on the interactive PyPy console::
+You can use a simple tracing mode to monitor the interpretation of
+bytecodes. To enable it, set ``__pytrace__ = 1`` on the interactive
+PyPy console::
>>>> __pytrace__ = 1
Tracing enabled
- >>>> a = 1 + 2
- |- <<<< enter <inline>a = 1 + 2 @ 1 >>>>
- |- 0 LOAD_CONST 0 (W_IntObject(1))
- |- 3 LOAD_CONST 1 (W_IntObject(2))
- |- 6 BINARY_ADD
- |- add(W_IntObject(1), W_IntObject(2)) -> W_IntObject(3)
- |- 7 STORE_NAME 0 (a)
- |- hash(W_StringObject('a')) -> W_IntObject(-468864544)
- |- int_w(W_IntObject(-468864544)) -> -468864544
- |-10 LOAD_CONST 2 (<W_NoneObject()>)
- |-13 RETURN_VALUE
- |- <<<< leave <inline>a = 1 + 2 @ 1 >>>>
+ >>>> x = 5
+ <module>: LOAD_CONST 0 (5)
+ <module>: STORE_NAME 0 (x)
+ <module>: LOAD_CONST 1 (None)
+ <module>: RETURN_VALUE 0
+ >>>> x
+ <module>: LOAD_NAME 0 (x)
+ <module>: PRINT_EXPR 0
+ 5
+ <module>: LOAD_CONST 0 (None)
+ <module>: RETURN_VALUE 0
+ >>>>
Demos
-------
diff --git a/pypy/interpreter/interactive.py b/pypy/interpreter/interactive.py
--- a/pypy/interpreter/interactive.py
+++ b/pypy/interpreter/interactive.py
@@ -189,8 +189,7 @@
try:
code.exec_code(self.space, self.w_globals, self.w_globals)
finally:
- if self.tracelevel:
- self.space.unsettrace()
+ self.unsettrace()
self.checktrace()
# run doit() in an exception-catching box
@@ -203,7 +202,38 @@
def settrace(self):
if self.tracelevel:
- self.space.settrace()
+ ec = self.space.getexecutioncontext()
+ if not hasattr(self, '_orig_bytecode_only_trace'):
+ self._orig_bytecode_only_trace = ec.bytecode_only_trace
+ ec.bytecode_only_trace = self._do_bytecode_only_trace
+
+ def unsettrace(self):
+ if self.tracelevel:
+ ec = self.space.getexecutioncontext()
+ ec.bytecode_only_trace = self._orig_bytecode_only_trace
+
+ def _do_bytecode_only_trace(self, frame):
+ from pypy.tool.pydis import Bytecode, HAVE_ARGUMENT
+
+ if frame.hide():
+ return
+
+ self.unsettrace()
+ next_instr = frame.last_instr
+ opcode = ord(frame.pycode.co_code[next_instr])
+
+ oparg = 0
+ if opcode >= HAVE_ARGUMENT:
+ lo = ord(frame.pycode.co_code[next_instr+1])
+ hi = ord(frame.pycode.co_code[next_instr+2])
+ oparg = (hi * 256) | lo
+
+ class fake:
+ code = frame.pycode
+ bytecode = Bytecode(fake, next_instr, oparg, 0)
+ print '\t%-19s %s' % (str(frame.pycode.co_name) + ':',
+ bytecode.repr_with_space(self.space))
+ self.settrace()
def checktrace(self):
s = self.space
@@ -213,11 +243,11 @@
s.wrap("__pytrace__")))
if self.tracelevel > 0 and tracelevel == 0:
- s.reset_trace()
+ self.unsettrace()
print "Tracing disabled"
if self.tracelevel == 0 and tracelevel > 0:
- self.space.unsettrace()
+ self.unsettrace()
print "Tracing enabled"
self.tracelevel = tracelevel
diff --git a/pypy/interpreter/test/test_zpy.py
b/pypy/interpreter/test/test_zpy.py
--- a/pypy/interpreter/test/test_zpy.py
+++ b/pypy/interpreter/test/test_zpy.py
@@ -7,10 +7,13 @@
pypypath = py.path.local(pypy.__file__).dirpath("bin", "pyinteractive.py")
-def run(*args):
+def run(*args, **kwds):
+ stdin = kwds.pop('stdin', '')
+ assert not kwds
argslist = map(str, args)
- popen = subprocess.Popen(argslist, stdout=subprocess.PIPE)
- stdout, stderr = popen.communicate()
+ popen = subprocess.Popen(argslist, stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE)
+ stdout, stderr = popen.communicate(stdin)
return stdout
@@ -99,3 +102,19 @@
stderr=subprocess.PIPE)
_, stderr = popen.communicate()
assert stderr.endswith('KeyError: <normalized>\n')
+
+
+def test_pytrace():
+ output = run(sys.executable, pypypath, '-S',
+ stdin="__pytrace__ = 1\nx = 5\nx")
+ assert ('\t<module>: LOAD_CONST 0 (5)\n'
+ '\t<module>: STORE_NAME 0 (x)\n'
+ '\t<module>: LOAD_CONST 1 (None)\n'
+ '\t<module>: RETURN_VALUE 0 \n'
+ '>>>> ') in output
+ assert ('\t<module>: LOAD_NAME 0 (x)\n'
+ '\t<module>: PRINT_EXPR 0 \n'
+ # '5\n' --- this line sent to stderr
+ '\t<module>: LOAD_CONST 0 (None)\n'
+ '\t<module>: RETURN_VALUE 0 \n'
+ '>>>> ') in output
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py
b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -359,6 +359,9 @@
assert x.load_function(BVoidP, 'strcpy')
py.test.raises(KeyError, x.load_function,
BVoidP, 'xxx_this_function_does_not_exist')
+ # the next one is from 'libm', not 'libc', but we assume
+ # that it is already loaded too, so it should work
+ assert x.load_function(BVoidP, 'sqrt')
def test_hash_differences():
BChar = new_primitive_type("char")
diff --git a/pypy/module/test_lib_pypy/cffi_tests/test_function.py
b/pypy/module/test_lib_pypy/cffi_tests/test_function.py
--- a/pypy/module/test_lib_pypy/cffi_tests/test_function.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/test_function.py
@@ -35,6 +35,12 @@
def getvalue(self):
return self._value
+lib_m = 'm'
+if sys.platform == 'win32':
+ #there is a small chance this fails on Mingw via environ $CC
+ import distutils.ccompiler
+ if distutils.ccompiler.get_default_compiler() == 'msvc':
+ lib_m = 'msvcrt'
class TestFunction(object):
Backend = CTypesBackend
@@ -44,18 +50,16 @@
ffi.cdef("""
double sin(double x);
""")
- m = ffi.dlopen("m")
+ m = ffi.dlopen(lib_m)
x = m.sin(1.23)
assert x == math.sin(1.23)
def test_sinf(self):
- if sys.platform == 'win32':
- py.test.skip("no 'sinf'")
ffi = FFI(backend=self.Backend())
ffi.cdef("""
float sinf(float x);
""")
- m = ffi.dlopen("m")
+ m = ffi.dlopen(lib_m)
x = m.sinf(1.23)
assert type(x) is float
assert x != math.sin(1.23) # rounding effects
@@ -67,14 +71,14 @@
ffi.cdef("""
void sin(double x);
""")
- m = ffi.dlopen("m")
+ m = ffi.dlopen(lib_m)
x = m.sin(1.23)
assert x is None
def test_dlopen_filename(self):
- path = ctypes.util.find_library("m")
+ path = ctypes.util.find_library(lib_m)
if not path:
- py.test.skip("libm not found")
+ py.test.skip("%s not found" % lib_m)
ffi = FFI(backend=self.Backend())
ffi.cdef("""
double cos(double x);
@@ -92,7 +96,7 @@
ffi.cdef("""
double cos(double x);
""")
- m = ffi.dlopen("m", ffi.RTLD_LAZY | ffi.RTLD_LOCAL)
+ m = ffi.dlopen(lib_m, ffi.RTLD_LAZY | ffi.RTLD_LOCAL)
x = m.cos(1.23)
assert x == math.cos(1.23)
@@ -293,7 +297,7 @@
typedef double func_t(double);
func_t sin;
""")
- m = ffi.dlopen("m")
+ m = ffi.dlopen(lib_m)
x = m.sin(1.23)
assert x == math.sin(1.23)
@@ -356,7 +360,7 @@
ffi.cdef("""
int nonexistent();
""")
- m = ffi.dlopen("m")
+ m = ffi.dlopen(lib_m)
assert not hasattr(m, 'nonexistent')
def test_wraps_from_stdlib(self):
@@ -370,7 +374,7 @@
def wrapper(*args):
return f(*args) + 100
return wrapper
- m = ffi.dlopen("m")
+ m = ffi.dlopen(lib_m)
sin100 = my_decorator(m.sin)
x = sin100(1.23)
assert x == math.sin(1.23) + 100
diff --git a/pypy/module/test_lib_pypy/cffi_tests/test_parsing.py
b/pypy/module/test_lib_pypy/cffi_tests/test_parsing.py
--- a/pypy/module/test_lib_pypy/cffi_tests/test_parsing.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/test_parsing.py
@@ -37,7 +37,7 @@
totalsize=-1, totalalignment=-1, sflags=0):
assert isinstance(s, FakeStruct)
s.fields = fields
-
+
def new_array_type(self, ptrtype, length):
return FakeType('<array %s x %s>' % (ptrtype, length))
@@ -61,7 +61,7 @@
return ', '.join([str(y) + str(x) for x, y, z in self.fields])
class FakeLibrary(object):
-
+
def load_function(self, BType, name):
return FakeFunction(BType, name)
@@ -71,11 +71,17 @@
self.BType = str(BType)
self.name = name
+lib_m = "m"
+if sys.platform == 'win32':
+ #there is a small chance this fails on Mingw via environ $CC
+ import distutils.ccompiler
+ if distutils.ccompiler.get_default_compiler() == 'msvc':
+ lib_m = 'msvcrt'
def test_simple():
ffi = FFI(backend=FakeBackend())
ffi.cdef("double sin(double x);")
- m = ffi.dlopen("m")
+ m = ffi.dlopen(lib_m)
func = m.sin # should be a callable on real backends
assert func.name == 'sin'
assert func.BType == '<func (<double>), <double>, False>'
@@ -149,7 +155,7 @@
x, double/*several*//*comment*/y) /*on the same line*/
;
""")
- m = ffi.dlopen("m")
+ m = ffi.dlopen(lib_m)
func = m.sin
assert func.name == 'sin'
assert func.BType == '<func (<double>, <double>), <double>, False>'
diff --git a/pypy/module/test_lib_pypy/cffi_tests/test_unicode_literals.py
b/pypy/module/test_lib_pypy/cffi_tests/test_unicode_literals.py
--- a/pypy/module/test_lib_pypy/cffi_tests/test_unicode_literals.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/test_unicode_literals.py
@@ -11,6 +11,13 @@
import sys, math
from cffi import FFI
+lib_m = "m"
+if sys.platform == 'win32':
+ #there is a small chance this fails on Mingw via environ $CC
+ import distutils.ccompiler
+ if distutils.ccompiler.get_default_compiler() == 'msvc':
+ lib_m = 'msvcrt'
+
def test_cast():
ffi = FFI()
@@ -56,7 +63,7 @@
def test_dlopen():
ffi = FFI()
ffi.cdef("double sin(double x);")
- m = ffi.dlopen("m") # unicode literal
+ m = ffi.dlopen(lib_m) # unicode literal
x = m.sin(1.23)
assert x == math.sin(1.23)
diff --git a/pypy/module/test_lib_pypy/cffi_tests/test_verify.py
b/pypy/module/test_lib_pypy/cffi_tests/test_verify.py
--- a/pypy/module/test_lib_pypy/cffi_tests/test_verify.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/test_verify.py
@@ -5,7 +5,12 @@
from pypy.module.test_lib_pypy.cffi_tests.support import *
+lib_m = ['m']
if sys.platform == 'win32':
+ #there is a small chance this fails on Mingw via environ $CC
+ import distutils.ccompiler
+ if distutils.ccompiler.get_default_compiler() == 'msvc':
+ lib_m = ['msvcrt']
pass # no obvious -Werror equivalent on MSVC
else:
if (sys.platform == 'darwin' and
@@ -64,13 +69,13 @@
def test_simple_case():
ffi = FFI()
ffi.cdef("double sin(double x);")
- lib = ffi.verify('#include <math.h>', libraries=["m"])
+ lib = ffi.verify('#include <math.h>', libraries=lib_m)
assert lib.sin(1.23) == math.sin(1.23)
def test_rounding_1():
ffi = FFI()
ffi.cdef("float sin(double x);")
- lib = ffi.verify('#include <math.h>', libraries=["m"])
+ lib = ffi.verify('#include <math.h>', libraries=lib_m)
res = lib.sin(1.23)
assert res != math.sin(1.23) # not exact, because of double->float
assert abs(res - math.sin(1.23)) < 1E-5
@@ -78,7 +83,7 @@
def test_rounding_2():
ffi = FFI()
ffi.cdef("double sin(float x);")
- lib = ffi.verify('#include <math.h>', libraries=["m"])
+ lib = ffi.verify('#include <math.h>', libraries=lib_m)
res = lib.sin(1.23)
assert res != math.sin(1.23) # not exact, because of double->float
assert abs(res - math.sin(1.23)) < 1E-5
@@ -104,7 +109,7 @@
def test_longdouble():
ffi = FFI()
ffi.cdef("long double sinl(long double x);")
- lib = ffi.verify('#include <math.h>', libraries=["m"])
+ lib = ffi.verify('#include <math.h>', libraries=lib_m)
for input in [1.23,
ffi.cast("double", 1.23),
ffi.cast("long double", 1.23)]:
diff --git a/pypy/module/test_lib_pypy/cffi_tests/test_zdistutils.py
b/pypy/module/test_lib_pypy/cffi_tests/test_zdistutils.py
--- a/pypy/module/test_lib_pypy/cffi_tests/test_zdistutils.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/test_zdistutils.py
@@ -8,6 +8,13 @@
class DistUtilsTest(object):
+ def setup_class(self):
+ self.lib_m = "m"
+ if sys.platform == 'win32':
+ #there is a small chance this fails on Mingw via environ $CC
+ import distutils.ccompiler
+ if distutils.ccompiler.get_default_compiler() == 'msvc':
+ self.lib_m = 'msvcrt'
def test_locate_engine_class(self):
cls = _locate_engine_class(FFI(), self.generic)
@@ -27,7 +34,7 @@
ffi.cdef("double sin(double x);")
csrc = '/*hi there %s!*/\n#include <math.h>\n' % self
v = Verifier(ffi, csrc, force_generic_engine=self.generic,
- libraries=["m"])
+ libraries=[self.lib_m])
v.write_source()
with open(v.sourcefilename, 'r') as f:
data = f.read()
@@ -38,7 +45,7 @@
ffi.cdef("double sin(double x);")
csrc = '/*hi there %s!*/\n#include <math.h>\n' % self
v = Verifier(ffi, csrc, force_generic_engine=self.generic,
- libraries=["m"])
+ libraries=[self.lib_m])
v.sourcefilename = filename = str(udir.join('write_source.c'))
v.write_source()
assert filename == v.sourcefilename
@@ -51,7 +58,7 @@
ffi.cdef("double sin(double x);")
csrc = '/*hi there %s!*/\n#include <math.h>\n' % self
v = Verifier(ffi, csrc, force_generic_engine=self.generic,
- libraries=["m"])
+ libraries=[self.lib_m])
try:
from StringIO import StringIO
except ImportError:
@@ -65,7 +72,7 @@
ffi.cdef("double sin(double x);")
csrc = '/*hi there %s!*/\n#include <math.h>\n' % self
v = Verifier(ffi, csrc, force_generic_engine=self.generic,
- libraries=["m"])
+ libraries=[self.lib_m])
v.compile_module()
assert v.get_module_name().startswith('_cffi_')
if v.generates_python_module():
@@ -77,7 +84,7 @@
ffi.cdef("double sin(double x);")
csrc = '/*hi there %s!2*/\n#include <math.h>\n' % self
v = Verifier(ffi, csrc, force_generic_engine=self.generic,
- libraries=["m"])
+ libraries=[self.lib_m])
basename = self.__class__.__name__ + 'test_compile_module'
v.modulefilename = filename = str(udir.join(basename + '.so'))
v.compile_module()
@@ -94,7 +101,7 @@
ffi.cdef("%s sin(double x);" % csrc)
v = Verifier(ffi, "#include <math.h>",
force_generic_engine=self.generic,
- libraries=["m"])
+ libraries=[self.lib_m])
names.append(v.get_module_name())
assert names[0] == names[1] != names[2]
@@ -112,7 +119,7 @@
ffi.cdef("double sin(double x);")
csrc = '/*hi there %s!3*/\n#include <math.h>\n' % self
v = Verifier(ffi, csrc, force_generic_engine=self.generic,
- libraries=["m"])
+ libraries=[self.lib_m])
library = v.load_library()
assert library.sin(12.3) == math.sin(12.3)
@@ -123,7 +130,7 @@
udir.join('test_verifier_args.h').write('#include <math.h>\n')
v = Verifier(ffi, csrc, include_dirs=[str(udir)],
force_generic_engine=self.generic,
- libraries=["m"])
+ libraries=[self.lib_m])
library = v.load_library()
assert library.sin(12.3) == math.sin(12.3)
@@ -132,7 +139,7 @@
ffi.cdef("double sin(double x);")
csrc = "/*6%s*/\n#include <math.h>" % self
lib = ffi.verify(csrc, force_generic_engine=self.generic,
- libraries=["m"])
+ libraries=[self.lib_m])
assert lib.sin(12.3) == math.sin(12.3)
assert isinstance(ffi.verifier, Verifier)
with open(ffi.verifier.sourcefilename, 'r') as f:
@@ -150,7 +157,7 @@
'''
lib = ffi.verify(csrc, define_macros=[('TEST_EXTENSION_OBJECT', '1')],
force_generic_engine=self.generic,
- libraries=["m"])
+ libraries=[self.lib_m])
assert lib.sin(12.3) == math.sin(12.3)
v = ffi.verifier
ext = v.get_extension()
@@ -164,7 +171,7 @@
ffi.cdef("double sin(double x);")
csrc = '/*hi there9!%s*/\n#include <math.h>\n' % self
v = Verifier(ffi, csrc, force_generic_engine=self.generic,
- libraries=["m"])
+ libraries=[self.lib_m])
assert not os.path.exists(v.sourcefilename)
v.get_extension()
assert os.path.exists(v.sourcefilename)
diff --git a/rpython/jit/metainterp/optimizeopt/rewrite.py
b/rpython/jit/metainterp/optimizeopt/rewrite.py
--- a/rpython/jit/metainterp/optimizeopt/rewrite.py
+++ b/rpython/jit/metainterp/optimizeopt/rewrite.py
@@ -271,7 +271,13 @@
def optimize_GUARD_VALUE(self, op):
value = self.getvalue(op.getarg(0))
if value.is_virtual():
- raise InvalidLoop('A promote of a virtual (a recently allocated
object) never makes sense!')
+ arg = value.get_constant_class(self.optimizer.cpu)
+ if arg:
+ addr = arg.getaddr()
+ name = self.optimizer.metainterp_sd.get_name_from_address(addr)
+ else:
+ name = "<unknown>"
+ raise InvalidLoop('A promote of a virtual %s (a recently allocated
object) never makes sense!' % name)
if value.last_guard:
# there already has been a guard_nonnull or guard_class or
# guard_nonnull_class on this value, which is rather silly.
diff --git
a/rpython/jit/metainterp/optimizeopt/test/test_disable_optimizations.py
b/rpython/jit/metainterp/optimizeopt/test/test_disable_optimizations.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_disable_optimizations.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_disable_optimizations.py
@@ -35,8 +35,8 @@
def raises(self, e, fn, *args):
try:
fn(*args)
- except e:
- pass
+ except Exception, e:
+ return e
opt = allopts[optnum]
exec "TestNo%sLLtype = TestLLtype" % (opt[0].upper() + opt[1:])
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py
b/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py
@@ -91,7 +91,7 @@
return loop
def raises(self, e, fn, *args):
- py.test.raises(e, fn, *args)
+ return py.test.raises(e, fn, *args).value
class OptimizeOptTest(BaseTestWithUnroll):
@@ -2824,8 +2824,10 @@
guard_value(p2, ConstPtr(myptr)) []
jump(p2)
"""
- self.raises(InvalidLoop, self.optimize_loop,
- ops, "crash!")
+ exc = self.raises(InvalidLoop, self.optimize_loop,
+ ops, "crash!")
+ if exc:
+ assert "node" in exc.msg
def test_merge_guard_class_guard_value(self):
ops = """
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_util.py
b/rpython/jit/metainterp/optimizeopt/test/test_util.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_util.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_util.py
@@ -321,6 +321,13 @@
max_retrace_guards = 15
jitcounter = DeterministicJitCounter()
+ def get_name_from_address(self, addr):
+ # hack
+ try:
+ return "".join(addr.ptr.name)[:-1] # remove \x00
+ except AttributeError:
+ return ""
+
class Storage(compile.ResumeGuardDescr):
"for tests."
def __init__(self, metainterp_sd=None, original_greenkey=None):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit