[pypy-commit] pypy reflex-support: merge default into branch
wlav
noreply at buildbot.pypy.org
Tue Jun 26 21:15:56 CEST 2012
Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: reflex-support
Changeset: r55841:782ac49bb966
Date: 2012-06-25 17:47 -0700
http://bitbucket.org/pypy/pypy/changeset/782ac49bb966/
Log: merge default into branch
diff --git a/pypy/doc/cppyy.rst b/pypy/doc/cppyy.rst
--- a/pypy/doc/cppyy.rst
+++ b/pypy/doc/cppyy.rst
@@ -87,14 +87,19 @@
$ cd pypy
$ hg up reflex-support # optional
$ cd pypy/translator/goal
+
+ # This example shows python, but using pypy-c is faster and uses less memory
$ python translate.py -O jit --gcrootfinder=shadowstack targetpypystandalone.py --withmod-cppyy
This will build a ``pypy-c`` that includes the cppyy module, and through that,
Reflex support.
Of course, if you already have a pre-built version of the ``pypy`` interpreter,
you can use that for the translation rather than ``python``.
+If not, you may want `to obtain a binary distribution`_ to speed up the
+translation step.
.. _`PyPy sources`: https://bitbucket.org/pypy/pypy/overview
+.. _`to obtain a binary distribution`: http://doc.pypy.org/en/latest/getting-started.html#download-a-pre-built-pypy
Basic example
diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -11,7 +11,8 @@
.. branch: reflex-support
Provides cppyy module (disabled by default) for access to C++ through Reflex.
See doc/cppyy.rst for full details and functionality.
-
+.. branch: nupypy-axis-arg-check
+Check that axis arg is valid in _numpypy
.. "uninteresting" branches that we should just ignore for the whatsnew:
.. branch: slightly-shorter-c
diff --git a/pypy/module/_ssl/test/test_ztranslation.py b/pypy/module/_ssl/test/test_ztranslation.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/_ssl/test/test_ztranslation.py
@@ -0,0 +1,4 @@
+from pypy.objspace.fake.checkmodule import checkmodule
+
+def test__ffi_translates():
+ checkmodule('_ssl')
diff --git a/pypy/module/_ssl/thread_lock.py b/pypy/module/_ssl/thread_lock.py
--- a/pypy/module/_ssl/thread_lock.py
+++ b/pypy/module/_ssl/thread_lock.py
@@ -65,6 +65,8 @@
eci = ExternalCompilationInfo(
separate_module_sources=[separate_module_source],
+ post_include_bits=[
+ "int _PyPy_SSL_SetupThreads(void);"],
export_symbols=['_PyPy_SSL_SetupThreads'],
)
diff --git a/pypy/module/array/interp_array.py b/pypy/module/array/interp_array.py
--- a/pypy/module/array/interp_array.py
+++ b/pypy/module/array/interp_array.py
@@ -167,7 +167,6 @@
def get_raw_address(self):
return self.array._charbuf_start()
-
def make_array(mytype):
W_ArrayBase = globals()['W_ArrayBase']
diff --git a/pypy/module/cppyy/test/conftest.py b/pypy/module/cppyy/test/conftest.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/cppyy/test/conftest.py
@@ -0,0 +1,5 @@
+import py
+
+def pytest_runtest_setup(item):
+ if py.path.local.sysfind('genreflex') is None:
+ py.test.skip("genreflex is not installed")
diff --git a/pypy/module/cppyy/test/test_cppyy.py b/pypy/module/cppyy/test/test_cppyy.py
--- a/pypy/module/cppyy/test/test_cppyy.py
+++ b/pypy/module/cppyy/test/test_cppyy.py
@@ -145,7 +145,7 @@
e1 = None
gc.collect()
assert t.get_overload("getCount").call(None) == 1
- e2.destruct()
+ e2.destruct()
assert t.get_overload("getCount").call(None) == 0
e2 = None
gc.collect()
diff --git a/pypy/module/cppyy/test/test_operators.py b/pypy/module/cppyy/test/test_operators.py
--- a/pypy/module/cppyy/test/test_operators.py
+++ b/pypy/module/cppyy/test/test_operators.py
@@ -133,7 +133,7 @@
o = gbl.operator_unsigned_long();
o.m_ulong = sys.maxint + 128
- assert o.m_ulong == sys.maxint + 128
+ assert o.m_ulong == sys.maxint + 128
assert long(o) == sys.maxint + 128
o = gbl.operator_float(); o.m_float = 3.14
diff --git a/pypy/module/cpyext/include/pycapsule.h b/pypy/module/cpyext/include/pycapsule.h
--- a/pypy/module/cpyext/include/pycapsule.h
+++ b/pypy/module/cpyext/include/pycapsule.h
@@ -50,6 +50,8 @@
PyAPI_FUNC(void *) PyCapsule_Import(const char *name, int no_block);
+void init_capsule(void);
+
#ifdef __cplusplus
}
#endif
diff --git a/pypy/module/cpyext/include/pycobject.h b/pypy/module/cpyext/include/pycobject.h
--- a/pypy/module/cpyext/include/pycobject.h
+++ b/pypy/module/cpyext/include/pycobject.h
@@ -47,6 +47,8 @@
void (*destructor)(void *);
} PyCObject;
#endif
+
+void init_pycobject(void);
#ifdef __cplusplus
}
diff --git a/pypy/module/micronumpy/interp_numarray.py b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -15,6 +15,7 @@
from pypy.rlib.rstring import StringBuilder
from pypy.rpython.lltypesystem import lltype, rffi
from pypy.tool.sourcetools import func_with_new_name
+from pypy.module.micronumpy.interp_support import unwrap_axis_arg
count_driver = jit.JitDriver(
@@ -156,10 +157,6 @@
def _reduce_ufunc_impl(ufunc_name, promote_to_largest=False):
def impl(self, space, w_axis=None, w_out=None):
- if space.is_w(w_axis, space.w_None):
- axis = -1
- else:
- axis = space.int_w(w_axis)
if space.is_w(w_out, space.w_None) or not w_out:
out = None
elif not isinstance(w_out, BaseArray):
@@ -168,7 +165,7 @@
else:
out = w_out
return getattr(interp_ufuncs.get(space), ufunc_name).reduce(space,
- self, True, promote_to_largest, axis,
+ self, True, promote_to_largest, w_axis,
False, out)
return func_with_new_name(impl, "reduce_%s_impl" % ufunc_name)
@@ -570,11 +567,10 @@
def descr_mean(self, space, w_axis=None, w_out=None):
if space.is_w(w_axis, space.w_None):
- w_axis = space.wrap(-1)
w_denom = space.wrap(support.product(self.shape))
else:
- dim = space.int_w(w_axis)
- w_denom = space.wrap(self.shape[dim])
+ axis = unwrap_axis_arg(space, len(self.shape), w_axis)
+ w_denom = space.wrap(self.shape[axis])
return space.div(self.descr_sum_promote(space, w_axis, w_out), w_denom)
def descr_var(self, space, w_axis=None):
@@ -1310,12 +1306,24 @@
raise OperationError(space.w_NotImplementedError, space.wrap("unsupported"))
if space.is_w(w_axis, space.w_None):
return space.wrap(support.product(arr.shape))
+ shapelen = len(arr.shape)
if space.isinstance_w(w_axis, space.w_int):
- return space.wrap(arr.shape[space.int_w(w_axis)])
+ axis = space.int_w(w_axis)
+ if axis < -shapelen or axis>= shapelen:
+ raise operationerrfmt(space.w_ValueError,
+ "axis entry %d is out of bounds [%d, %d)", axis,
+ -shapelen, shapelen)
+ return space.wrap(arr.shape[axis])
+ # numpy as of June 2012 does not implement this
s = 1
elems = space.fixedview(w_axis)
for w_elem in elems:
- s *= arr.shape[space.int_w(w_elem)]
+ axis = space.int_w(w_elem)
+ if axis < -shapelen or axis>= shapelen:
+ raise operationerrfmt(space.w_ValueError,
+ "axis entry %d is out of bounds [%d, %d)", axis,
+ -shapelen, shapelen)
+ s *= arr.shape[axis]
return space.wrap(s)
def dot(space, w_obj, w_obj2):
diff --git a/pypy/module/micronumpy/interp_support.py b/pypy/module/micronumpy/interp_support.py
--- a/pypy/module/micronumpy/interp_support.py
+++ b/pypy/module/micronumpy/interp_support.py
@@ -4,6 +4,7 @@
from pypy.module.micronumpy import interp_dtype
from pypy.objspace.std.strutil import strip_spaces
from pypy.rlib import jit
+from pypy.rlib.rarithmetic import maxint
FLOAT_SIZE = rffi.sizeof(lltype.Float)
@@ -103,3 +104,16 @@
return _fromstring_bin(space, s, count, length, dtype)
else:
return _fromstring_text(space, s, count, sep, length, dtype)
+
+def unwrap_axis_arg(space, shapelen, w_axis):
+ if space.is_w(w_axis, space.w_None) or not w_axis:
+ axis = maxint
+ else:
+ axis = space.int_w(w_axis)
+ if axis < -shapelen or axis>= shapelen:
+ raise operationerrfmt(space.w_ValueError,
+ "axis entry %d is out of bounds [%d, %d)", axis,
+ -shapelen, shapelen)
+ if axis < 0:
+ axis += shapelen
+ return axis
diff --git a/pypy/module/micronumpy/interp_ufuncs.py b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -2,11 +2,11 @@
from pypy.interpreter.error import OperationError, operationerrfmt
from pypy.interpreter.gateway import interp2app, unwrap_spec, NoneNotWrapped
from pypy.interpreter.typedef import TypeDef, GetSetProperty, interp_attrproperty
-from pypy.module.micronumpy import interp_boxes, interp_dtype, support, loop
+from pypy.module.micronumpy import interp_boxes, interp_dtype, loop
from pypy.rlib import jit
from pypy.rlib.rarithmetic import LONG_BIT
from pypy.tool.sourcetools import func_with_new_name
-
+from pypy.module.micronumpy.interp_support import unwrap_axis_arg
class W_Ufunc(Wrappable):
_attrs_ = ["name", "promote_to_float", "promote_bools", "identity"]
@@ -121,11 +121,7 @@
"""
from pypy.module.micronumpy.interp_numarray import BaseArray
if w_axis is None:
- axis = 0
- elif space.is_w(w_axis, space.w_None):
- axis = -1
- else:
- axis = space.int_w(w_axis)
+ w_axis = space.wrap(0)
if space.is_w(w_out, space.w_None):
out = None
elif not isinstance(w_out, BaseArray):
@@ -133,9 +129,9 @@
'output must be an array'))
else:
out = w_out
- return self.reduce(space, w_obj, False, False, axis, keepdims, out)
+ return self.reduce(space, w_obj, False, False, w_axis, keepdims, out)
- def reduce(self, space, w_obj, multidim, promote_to_largest, axis,
+ def reduce(self, space, w_obj, multidim, promote_to_largest, w_axis,
keepdims=False, out=None):
from pypy.module.micronumpy.interp_numarray import convert_to_array, \
Scalar, ReduceArray, W_NDimArray
@@ -144,11 +140,11 @@
"supported for binary functions"))
assert isinstance(self, W_Ufunc2)
obj = convert_to_array(space, w_obj)
- if axis >= len(obj.shape):
- raise OperationError(space.w_ValueError, space.wrap("axis(=%d) out of bounds" % axis))
if isinstance(obj, Scalar):
raise OperationError(space.w_TypeError, space.wrap("cannot reduce "
"on a scalar"))
+ axis = unwrap_axis_arg(space, len(obj.shape), w_axis)
+ assert axis>=0
size = obj.size
if self.comparison_func:
dtype = interp_dtype.get_dtype_cache(space).w_booldtype
@@ -163,7 +159,7 @@
if self.identity is None and size == 0:
raise operationerrfmt(space.w_ValueError, "zero-size array to "
"%s.reduce without identity", self.name)
- if shapelen > 1 and axis >= 0:
+ if shapelen > 1 and axis < shapelen:
if keepdims:
shape = obj.shape[:axis] + [1] + obj.shape[axis + 1:]
else:
diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -1086,6 +1086,9 @@
assert (b == array(range(35, 70), dtype=float).reshape(5, 7)).all()
assert (a.mean(2) == array(range(0, 15), dtype=float).reshape(3, 5) * 7 + 3).all()
assert (arange(10).reshape(5, 2).mean(axis=1) == [0.5, 2.5, 4.5, 6.5, 8.5]).all()
+ assert (a.mean(axis=-1) == a.mean(axis=2)).all()
+ raises(ValueError, a.mean, -4)
+ raises(ValueError, a.mean, 3)
def test_sum(self):
from _numpypy import array
@@ -1096,7 +1099,8 @@
a = array([True] * 5, bool)
assert a.sum() == 5
- raises(TypeError, 'a.sum(2, 3)')
+ raises(TypeError, 'a.sum(axis=0, out=3)')
+ raises(ValueError, 'a.sum(axis=2)')
d = array(0.)
b = a.sum(out=d)
assert b == d
@@ -1112,6 +1116,10 @@
assert (a.sum(0) == [30, 35, 40]).all()
assert (a.sum(axis=0) == [30, 35, 40]).all()
assert (a.sum(1) == [3, 12, 21, 30, 39]).all()
+ assert (a.sum(-1) == a.sum(-1)).all()
+ assert (a.sum(-2) == a.sum(-2)).all()
+ raises(ValueError, a.sum, -3)
+ raises(ValueError, a.sum, 2)
assert (a.max(0) == [12, 13, 14]).all()
assert (a.max(1) == [2, 5, 8, 11, 14]).all()
assert ((a + a).max() == 28)
diff --git a/pypy/module/micronumpy/test/test_ufuncs.py b/pypy/module/micronumpy/test/test_ufuncs.py
--- a/pypy/module/micronumpy/test/test_ufuncs.py
+++ b/pypy/module/micronumpy/test/test_ufuncs.py
@@ -573,6 +573,7 @@
a = arange(12).reshape(3, 4)
assert (add.reduce(a, 0) == [12, 15, 18, 21]).all()
assert (add.reduce(a, 1) == [6.0, 22.0, 38.0]).all()
+ raises(ValueError, add.reduce, a, 2)
def test_reduce_keepdims(self):
from _numpypy import add, arange
@@ -636,6 +637,8 @@
assert count_reduce_items(a) == 24
assert count_reduce_items(a, 1) == 3
assert count_reduce_items(a, (1, 2)) == 3 * 4
+ raises(ValueError, count_reduce_items, a, -4)
+ raises(ValueError, count_reduce_items, a, (0, 2, -4))
def test_true_divide(self):
from _numpypy import arange, array, true_divide
diff --git a/pypy/objspace/std/boolobject.py b/pypy/objspace/std/boolobject.py
--- a/pypy/objspace/std/boolobject.py
+++ b/pypy/objspace/std/boolobject.py
@@ -1,6 +1,7 @@
from pypy.rlib.rbigint import rbigint
from pypy.rlib.rarithmetic import r_uint
from pypy.interpreter.error import OperationError
+from pypy.objspace.std import newformat
from pypy.objspace.std.model import registerimplementation, W_Object
from pypy.objspace.std.register_all import register_all
from pypy.objspace.std.intobject import W_IntObject
@@ -68,4 +69,9 @@
str__Bool = repr__Bool
+def format__Bool_ANY(space, w_bool, w_format_spec):
+ return newformat.run_formatter(
+ space, w_format_spec, "format_int_or_long", w_bool,
+ newformat.INT_KIND)
+
register_all(vars())
diff --git a/pypy/objspace/std/test/test_newformat.py b/pypy/objspace/std/test/test_newformat.py
--- a/pypy/objspace/std/test/test_newformat.py
+++ b/pypy/objspace/std/test/test_newformat.py
@@ -209,6 +209,23 @@
assert self.s("{!r}").format(x()) == self.s("32")
+class AppTestBoolFormat:
+
+ def test_str_format(self):
+ assert format(False) == "False"
+ assert format(True) == "True"
+ assert "{0}".format(True) == "True"
+ assert "{0}".format(False) == "False"
+ assert "{0} or {1}".format(True, False) == "True or False"
+ assert "{} or {}".format(True, False) == "True or False"
+
+ def test_int_delegation_format(self):
+ assert "{:f}".format(True) == "1.000000"
+ assert "{:05d}".format(False) == "00000"
+ assert "{:g}".format(True) == "1"
+
+
+
class BaseIntegralFormattingTest:
def test_simple(self):
diff --git a/pypy/objspace/std/test/test_setobject.py b/pypy/objspace/std/test/test_setobject.py
--- a/pypy/objspace/std/test/test_setobject.py
+++ b/pypy/objspace/std/test/test_setobject.py
@@ -425,6 +425,8 @@
s1 = set()
s1.update(set('abcd'))
assert s1 == set('abcd')
+ s1 = set([1, 2.0, "3"])
+ s1.update(set(["3", 4, 5.0]))
def test_recursive_repr(self):
class A(object):
diff --git a/pypy/rlib/parsing/parsing.py b/pypy/rlib/parsing/parsing.py
--- a/pypy/rlib/parsing/parsing.py
+++ b/pypy/rlib/parsing/parsing.py
@@ -107,14 +107,12 @@
error = None # for the annotator
if self.parser.is_nonterminal(symbol):
rule = self.parser.get_rule(symbol)
- lastexpansion = len(rule.expansions) - 1
subsymbol = None
error = None
for expansion in rule.expansions:
curr = i
children = []
- for j in range(len(expansion)):
- subsymbol = expansion[j]
+ for subsymbol in expansion:
node, next, error2 = self.match_symbol(curr, subsymbol)
if node is None:
error = combine_errors(error, error2)
diff --git a/pypy/rlib/rerased.py b/pypy/rlib/rerased.py
--- a/pypy/rlib/rerased.py
+++ b/pypy/rlib/rerased.py
@@ -48,6 +48,9 @@
def __repr__(self):
return 'ErasingPairIdentity(%r)' % self.name
+ def __deepcopy__(self, memo):
+ return self
+
def _getdict(self, bk):
try:
dict = bk._erasing_pairs_tunnel
diff --git a/pypy/rlib/rlocale.py b/pypy/rlib/rlocale.py
--- a/pypy/rlib/rlocale.py
+++ b/pypy/rlib/rlocale.py
@@ -29,7 +29,7 @@
HAVE_LIBINTL = False
class CConfig:
- includes = ['locale.h', 'limits.h', 'ctype.h']
+ includes = ['locale.h', 'limits.h', 'ctype.h', 'wchar.h']
libraries = libraries
if HAVE_LANGINFO:
diff --git a/pypy/rlib/test/test_rerased.py b/pypy/rlib/test/test_rerased.py
--- a/pypy/rlib/test/test_rerased.py
+++ b/pypy/rlib/test/test_rerased.py
@@ -1,5 +1,7 @@
import py
import sys
+import copy
+
from pypy.rlib.rerased import *
from pypy.annotation import model as annmodel
from pypy.annotation.annrpython import RPythonAnnotator
@@ -59,6 +61,13 @@
#assert is_integer(e) is False
assert unerase_list_X(e) is l
+def test_deepcopy():
+ x = "hello"
+ e = eraseX(x)
+ e2 = copy.deepcopy(e)
+ assert uneraseX(e) is x
+ assert uneraseX(e2) is x
+
def test_annotate_1():
def f():
return eraseX(X())
diff --git a/pypy/tool/sourcetools.py b/pypy/tool/sourcetools.py
--- a/pypy/tool/sourcetools.py
+++ b/pypy/tool/sourcetools.py
@@ -224,6 +224,7 @@
if func.func_dict:
f.func_dict = {}
f.func_dict.update(func.func_dict)
+ f.func_doc = func.func_doc
return f
def func_renamer(newname):
diff --git a/pypy/tool/test/test_sourcetools.py b/pypy/tool/test/test_sourcetools.py
--- a/pypy/tool/test/test_sourcetools.py
+++ b/pypy/tool/test/test_sourcetools.py
@@ -22,3 +22,15 @@
assert f.func_name == "g"
assert f.func_defaults == (5,)
assert f.prop is int
+
+def test_func_rename_decorator():
+ def bar():
+ 'doc'
+
+ bar2 = func_with_new_name(bar, 'bar2')
+ assert bar.func_doc == bar2.func_doc == 'doc'
+
+ bar.func_doc = 'new doc'
+ bar3 = func_with_new_name(bar, 'bar3')
+ assert bar3.func_doc == 'new doc'
+ assert bar2.func_doc != bar3.func_doc
diff --git a/pypy/translator/c/src/signals.h b/pypy/translator/c/src/signals.h
--- a/pypy/translator/c/src/signals.h
+++ b/pypy/translator/c/src/signals.h
@@ -46,6 +46,7 @@
void pypysig_default(int signum); /* signal will do default action (SIG_DFL) */
void pypysig_setflag(int signum); /* signal will set a flag which can be
queried with pypysig_poll() */
+void pypysig_reinstall(int signum);
int pypysig_set_wakeup_fd(int fd);
/* utility to poll for signals that arrived */
More information about the pypy-commit
mailing list