[pypy-commit] pypy precompiled-headers: merge default into branch
mattip
noreply at buildbot.pypy.org
Fri Feb 7 11:08:05 CET 2014
Author: Matti Picus <matti.picus at gmail.com>
Branch: precompiled-headers
Changeset: r69092:b238bc9d56d5
Date: 2014-02-07 09:08 +0200
http://bitbucket.org/pypy/pypy/changeset/b238bc9d56d5/
Log: merge default into branch
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
@@ -81,6 +81,7 @@
'newdict' : 'interp_dict.newdict',
'dictstrategy' : 'interp_dict.dictstrategy',
'set_debug' : 'interp_magic.set_debug',
+ 'locals_to_fast' : 'interp_magic.locals_to_fast',
}
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
@@ -1,5 +1,6 @@
from pypy.interpreter.error import OperationError, wrap_oserror
from pypy.interpreter.gateway import unwrap_spec
+from pypy.interpreter.pyframe import PyFrame
from rpython.rlib.objectmodel import we_are_translated
from pypy.objspace.std.listobject import W_ListObject
from pypy.objspace.std.typeobject import MethodCache
@@ -111,3 +112,8 @@
@unwrap_spec(estimate=int)
def add_memory_pressure(estimate):
rgc.add_memory_pressure(estimate)
+
+ at unwrap_spec(w_frame=PyFrame)
+def locals_to_fast(space, w_frame):
+ assert isinstance(w_frame, PyFrame)
+ w_frame.locals2fast()
diff --git a/pypy/module/__pypy__/test/test_locals2fast.py b/pypy/module/__pypy__/test/test_locals2fast.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/__pypy__/test/test_locals2fast.py
@@ -0,0 +1,81 @@
+# Tests from Fabio Zadrozny
+
+
+class AppTestLocals2Fast:
+ """
+ Test setting locals in one function from another function
+ using several approaches.
+ """
+
+ def setup_class(cls):
+ cls.w_save_locals = cls.space.appexec([], """():
+ import sys
+ if '__pypy__' in sys.builtin_module_names:
+ import __pypy__
+ save_locals = __pypy__.locals_to_fast
+ else:
+ # CPython version
+ import ctypes
+ @staticmethod
+ def save_locals(frame):
+ ctypes.pythonapi.PyFrame_LocalsToFast(
+ ctypes.py_object(frame), ctypes.c_int(0))
+ return save_locals
+ """)
+
+ def test_set_locals_using_save_locals(self):
+ import sys
+ def use_save_locals(name, value):
+ frame = sys._getframe().f_back
+ locals_dict = frame.f_locals
+ locals_dict[name] = value
+ self.save_locals(frame)
+ def test_method(fn):
+ x = 1
+ # The method 'fn' should attempt to set x = 2 in the current frame.
+ fn('x', 2)
+ return x
+ x = test_method(use_save_locals)
+ assert x == 2
+
+ def test_frame_simple_change(self):
+ import sys
+ frame = sys._getframe()
+ a = 20
+ frame.f_locals['a'] = 50
+ self.save_locals(frame)
+ assert a == 50
+
+ def test_frame_co_freevars(self):
+ import sys
+ outer_var = 20
+ def func():
+ frame = sys._getframe()
+ frame.f_locals['outer_var'] = 50
+ self.save_locals(frame)
+ assert outer_var == 50
+ func()
+
+ def test_frame_co_cellvars(self):
+ import sys
+ def check_co_vars(a):
+ frame = sys._getframe()
+ def function2():
+ print a
+ assert 'a' in frame.f_code.co_cellvars
+ frame = sys._getframe()
+ frame.f_locals['a'] = 50
+ self.save_locals(frame)
+ assert a == 50
+ check_co_vars(1)
+
+ def test_frame_change_in_inner_frame(self):
+ import sys
+ def change(f):
+ assert f is not sys._getframe()
+ f.f_locals['a'] = 50
+ self.save_locals(f)
+ frame = sys._getframe()
+ a = 20
+ change(frame)
+ assert a == 50
diff --git a/pypy/module/pypyjit/test_pypy_c/test_misc.py b/pypy/module/pypyjit/test_pypy_c/test_misc.py
--- a/pypy/module/pypyjit/test_pypy_c/test_misc.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_misc.py
@@ -333,8 +333,8 @@
loop, = log.loops_by_id("struct")
if sys.maxint == 2 ** 63 - 1:
extra = """
- i8 = int_lt(i4, -2147483648)
- guard_false(i8, descr=...)
+ i8 = int_ge(i4, -2147483648)
+ guard_true(i8, descr=...)
"""
else:
extra = ""
diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py
--- a/rpython/annotator/annrpython.py
+++ b/rpython/annotator/annrpython.py
@@ -582,18 +582,18 @@
def consider_op(self, block, opindex):
op = block.operations[opindex]
- argcells = [self.binding(a) for a in op.args]
+ try:
+ argcells = [self.binding(a) for a in op.args]
- # let's be careful about avoiding propagated SomeImpossibleValues
- # to enter an op; the latter can result in violations of the
- # more general results invariant: e.g. if SomeImpossibleValue enters is_
- # is_(SomeImpossibleValue, None) -> SomeBool
- # is_(SomeInstance(not None), None) -> SomeBool(const=False) ...
- # boom -- in the assert of setbinding()
- for arg in argcells:
- if isinstance(arg, annmodel.SomeImpossibleValue):
- raise BlockedInference(self, op, opindex)
- try:
+ # let's be careful about avoiding propagated SomeImpossibleValues
+ # to enter an op; the latter can result in violations of the
+ # more general results invariant: e.g. if SomeImpossibleValue enters is_
+ # is_(SomeImpossibleValue, None) -> SomeBool
+ # is_(SomeInstance(not None), None) -> SomeBool(const=False) ...
+ # boom -- in the assert of setbinding()
+ for arg in argcells:
+ if isinstance(arg, annmodel.SomeImpossibleValue):
+ raise BlockedInference(self, op, opindex)
resultcell = op.consider(self, *argcells)
except annmodel.AnnotatorError as e: # note that UnionError is a subclass
graph = self.bookkeeper.position_key[0]
diff --git a/rpython/annotator/test/test_annrpython.py b/rpython/annotator/test/test_annrpython.py
--- a/rpython/annotator/test/test_annrpython.py
+++ b/rpython/annotator/test/test_annrpython.py
@@ -4139,6 +4139,16 @@
a.build_types(f, [str])
assert ("Cannot prove that the object is callable" in exc.value.msg)
+ def test_UnionError_on_PBC(self):
+ l = ['a', 1]
+ def f(x):
+ l.append(x)
+ a = self.RPythonAnnotator()
+ with py.test.raises(annmodel.UnionError) as excinfo:
+ a.build_types(f, [int])
+ assert 'Happened at file' in excinfo.value.source
+ assert 'Known variable annotations:' in excinfo.value.source
+
def test_str_format_error(self):
def f(s, x):
return s.format(x)
diff --git a/rpython/tool/sourcetools.py b/rpython/tool/sourcetools.py
--- a/rpython/tool/sourcetools.py
+++ b/rpython/tool/sourcetools.py
@@ -6,7 +6,6 @@
# XXX We should try to generalize and single out one approach to dynamic
# XXX code compilation.
-import types
import sys, os, inspect, new
import py
@@ -296,40 +295,3 @@
result.func_defaults = f.func_defaults
result.func_dict.update(f.func_dict)
return result
-
-
-def _convert_const_maybe(x, encoding):
- if isinstance(x, str):
- return x.decode(encoding)
- elif isinstance(x, tuple):
- items = [_convert_const_maybe(item, encoding) for item in x]
- return tuple(items)
- return x
-
-def with_unicode_literals(fn=None, **kwds):
- """Decorator that replace all string literals with unicode literals.
- Similar to 'from __future__ import string literals' at function level.
- Useful to limit changes in the py3k branch.
- """
- encoding = kwds.pop('encoding', 'ascii')
- if kwds:
- raise TypeError("Unexpected keyword argument(s): %s" % ', '.join(kwds.keys()))
- def decorator(fn):
- co = fn.func_code
- new_consts = []
- for const in co.co_consts:
- new_consts.append(_convert_const_maybe(const, encoding))
- new_consts = tuple(new_consts)
- new_code = types.CodeType(co.co_argcount, co.co_nlocals, co.co_stacksize,
- co.co_flags, co.co_code, new_consts, co.co_names,
- co.co_varnames, co.co_filename, co.co_name,
- co.co_firstlineno, co.co_lnotab)
- fn.func_code = new_code
- return fn
- #
- # support the usage of @with_unicode_literals instead of @with_unicode_literals()
- if fn is not None:
- assert type(fn) is types.FunctionType
- return decorator(fn)
- else:
- return decorator
diff --git a/rpython/tool/test/test_sourcetools.py b/rpython/tool/test/test_sourcetools.py
--- a/rpython/tool/test/test_sourcetools.py
+++ b/rpython/tool/test/test_sourcetools.py
@@ -1,7 +1,5 @@
-# -*- encoding: utf-8 -*-
-import py
from rpython.tool.sourcetools import (
- func_with_new_name, func_renamer, rpython_wrapper, with_unicode_literals)
+ func_renamer, func_with_new_name, rpython_wrapper)
def test_rename():
def f(x, y=5):
@@ -57,30 +55,3 @@
('decorated', 40, 2),
('bar', 40, 2),
]
-
-
-def test_with_unicode_literals():
- @with_unicode_literals()
- def foo():
- return 'hello'
- assert type(foo()) is unicode
- #
- @with_unicode_literals
- def foo():
- return 'hello'
- assert type(foo()) is unicode
- #
- def foo():
- return 'hello àèì'
- py.test.raises(UnicodeDecodeError, "with_unicode_literals(foo)")
- #
- @with_unicode_literals(encoding='utf-8')
- def foo():
- return 'hello àèì'
- assert foo() == u'hello àèì'
- #
- @with_unicode_literals
- def foo():
- return ('a', 'b')
- assert type(foo()[0]) is unicode
-
More information about the pypy-commit
mailing list