[pypy-commit] pypy object-dtype2: add tests, fixes for tests

2015-04-03 Thread mattip
Author: mattip matti.pi...@gmail.com
Branch: object-dtype2
Changeset: r76697:077446240bbd
Date: 2015-04-03 09:03 +0300
http://bitbucket.org/pypy/pypy/changeset/077446240bbd/

Log:add tests, fixes for tests

diff --git a/pypy/module/micronumpy/test/test_object_arrays.py 
b/pypy/module/micronumpy/test/test_object_arrays.py
--- a/pypy/module/micronumpy/test/test_object_arrays.py
+++ b/pypy/module/micronumpy/test/test_object_arrays.py
@@ -28,6 +28,23 @@
 res = a + b
 assert res[0] == foobar
 
+def test_bool_func(self):
+import numpy as np
+a = np.array([foo], dtype=object)
+b = a and complex(1, -1)
+assert b == complex(1, -1)
+b = complex(1, -1) and a
+assert (b == a).all()
+
+def test_logical_ufunc(self):
+import numpy as np
+a = np.array([foo], dtype=object)
+b = np.array([1], dtype=object)
+raises(TypeError, np.logical_and, a, 1)
+raises(TypeError, np.logical_and, b, complex(1, -1))
+c = b  1
+assert (c == b).all()
+
 def test_reduce(self):
 import numpy as np
 class O(object):
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -1697,6 +1697,11 @@
 cannot create object array/scalar from lltype)
 return self.BoxType(w_obj)
 
+@specialize.argtype(1, 2)
+def box_complex(self, real, imag):
+w_obj = self.space.newcomplex(real, imag)
+return self.BoxType(w_obj)
+
 def str_format(self, box):
 return 'Object as string'
 #return space.str_w(space.repr(self.unbox(box)))
@@ -1728,8 +1733,14 @@
 def arctan2(self, v1, v2):
 raise oefmt(self.space.w_AttributeError, 'arctan2')
 
-@specialize.argtype(1)
+@raw_unary_op
+def bool(self,v):
+return not self.space.is_w(v, self.space.w_None) and \
+   not self.space.eq_w(v, self.space.wrap(0)) and \
+   not self.space.len_w(v) == 0 
+
 def _bool(self, v):
+#assert isinstance(v, W_Root)
 return self.space.bool_w(v)
 
 @raw_binary_op
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy object-dtype2: add many ufuncs

2015-04-03 Thread mattip
Author: mattip matti.pi...@gmail.com
Branch: object-dtype2
Changeset: r76695:f8e674fa7afc
Date: 2015-04-03 00:23 +0300
http://bitbucket.org/pypy/pypy/changeset/f8e674fa7afc/

Log:add many ufuncs

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
@@ -397,7 +397,7 @@
 for i in range(3):
 assert min_c_b[i] == min(b[i], c)
 
-def test_scalar(self):
+def test_all_available(self):
 # tests that by calling all available ufuncs on scalars, none will
 # raise uncaught interp-level exceptions, (and crash the test)
 # and those that are uncallable can be accounted for.
@@ -412,6 +412,8 @@
 if isinstance(u, np.ufunc):
 try:
 u(* [array] * u.nin)
+except AttributeError:
+pass
 except TypeError:
 assert s not in uncallable
 uncallable.add(s)
@@ -427,7 +429,9 @@
  'fabs', 'fmod', 'invert', 'mod',
  'logaddexp', 'logaddexp2', 'left_shift', 'right_shift',
  'copysign', 'signbit', 'ceil', 'floor', 'trunc'])
-assert find_uncallable_ufuncs('object') == set()
+assert find_uncallable_ufuncs('object') == set(
+['isnan', 'logaddexp2', 'copysign', 'isfinite', 'signbit',
+ 'isinf', 'logaddexp'])
 
 def test_int_only(self):
 from numpy import bitwise_and, array
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -149,7 +149,9 @@
 return self.box(array[0])
 
 def unbox(self, box):
-assert isinstance(box, self.BoxType)
+if not isinstance(box, self.BoxType):
+# i.e. box is an ObjectBox
+raise oefmt(self.space.w_AttributeError, '')
 return box.value
 
 def coerce(self, space, dtype, w_item):
@@ -427,29 +429,25 @@
 def default_fromstring(self, space):
 return self.box(0)
 
-@specialize.argtype(1, 2)
-def div(self, b1, b2):
-v1 = self.for_computation(self.unbox(b1))
-v2 = self.for_computation(self.unbox(b2))
+@simple_binary_op
+def div(self, v1, v2):
 if v2 == 0:
-return self.box(0)
+return 0
 if (self.T is rffi.SIGNEDCHAR or self.T is rffi.SHORT or self.T is 
rffi.INT or
 self.T is rffi.LONG or self.T is rffi.LONGLONG):
 if v2 == -1 and v1 == 
self.for_computation(most_neg_value_of(self.T)):
-return self.box(0)
-return self.box(v1 / v2)
+return 0
+return v1 / v2
 
-@specialize.argtype(1, 2)
-def floordiv(self, b1, b2):
-v1 = self.for_computation(self.unbox(b1))
-v2 = self.for_computation(self.unbox(b2))
+@simple_binary_op
+def floordiv(self, v1, v2):
 if v2 == 0:
-return self.box(0)
+return 0
 if (self.T is rffi.SIGNEDCHAR or self.T is rffi.SHORT or self.T is 
rffi.INT or
 self.T is rffi.LONG or self.T is rffi.LONGLONG):
 if v2 == -1 and v1 == 
self.for_computation(most_neg_value_of(self.T)):
-return self.box(0)
-return self.box(v1 // v2)
+return 0
+return v1 // v2
 
 @simple_binary_op
 def mod(self, v1, v2):
@@ -485,7 +483,7 @@
 elif v  0:
 return -1
 else:
-assert v == 0
+#assert v == 0
 return 0
 
 @raw_unary_op
@@ -1711,16 +1709,134 @@
 def for_computation(v):
 return v
 
-@simple_binary_op
-def add(self, v1, v2):
-return v1
-#return self.space.add(v1, v2)
+@raw_binary_op
+def eq(self, v1, v2):
+return self.space.eq_w(v1, v2)
 
 @raw_binary_op
-def eq(self, v1, v2):
-return True
-#return self.space.eq_w(v1, v2)
+def max(self, v1, v2):
+if self.space.is_true(self.space.ge(v1, v2)):
+return v1
+return v2
 
+@raw_binary_op
+def min(self, v1, v2):
+if self.space.is_true(self.space.le(v1, v2)):
+return v1
+return v2
+
+def arctan2(self, v1, v2):
+raise oefmt(self.space.w_AttributeError, 'arctan2')
+
+@specialize.argtype(1)
+def _bool(self, v):
+return self.space.bool_w(v)
+
+@raw_binary_op
+def logical_and(self, v1, v2):
+return self._bool(v1) and self._bool(v2)
+
+@raw_binary_op
+def logical_or(self, v1, v2):
+return self._bool(v1) or self._bool(v2)
+
+@raw_unary_op
+def logical_not(self, v):
+return not self._bool(v)
+
+@raw_binary_op
+def logical_xor(self, v1, v2):
+a = 

[pypy-commit] pypy object-dtype2: add test

2015-04-03 Thread mattip
Author: mattip matti.pi...@gmail.com
Branch: object-dtype2
Changeset: r76696:7e5953936ded
Date: 2015-04-03 00:23 +0300
http://bitbucket.org/pypy/pypy/changeset/7e5953936ded/

Log:add test

diff --git a/pypy/module/micronumpy/test/test_object_arrays.py 
b/pypy/module/micronumpy/test/test_object_arrays.py
--- a/pypy/module/micronumpy/test/test_object_arrays.py
+++ b/pypy/module/micronumpy/test/test_object_arrays.py
@@ -24,7 +24,7 @@
 
 a = np.array([foo], dtype=object)
 b = np.array([bar], dtype=object)
-
+raises(TypeError, np.add, a, 1)
 res = a + b
 assert res[0] == foobar
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy object-dtype2: small tweaks to dtype name, customtrace; add (failing) tests

2015-04-03 Thread mattip
Author: mattip matti.pi...@gmail.com
Branch: object-dtype2
Changeset: r76694:be19ae2bdd93
Date: 2015-04-01 23:22 +0300
http://bitbucket.org/pypy/pypy/changeset/be19ae2bdd93/

Log:small tweaks to dtype name, customtrace; add (failing) tests

diff --git a/pypy/module/micronumpy/boxes.py b/pypy/module/micronumpy/boxes.py
--- a/pypy/module/micronumpy/boxes.py
+++ b/pypy/module/micronumpy/boxes.py
@@ -868,7 +868,7 @@
 __len__ = interp2app(W_UnicodeBox.descr_len),
 )
 
-W_ObjectBox.typedef = TypeDef(numpy.object, W_ObjectBox.typedef,
+W_ObjectBox.typedef = TypeDef(numpy.object_, W_ObjectBox.typedef,
 __new__ = interp2app(W_ObjectBox.descr__new__.im_func),
 __getattr__ = interp2app(W_ObjectBox.descr__getattr__),
 )
diff --git a/pypy/module/micronumpy/concrete.py 
b/pypy/module/micronumpy/concrete.py
--- a/pypy/module/micronumpy/concrete.py
+++ b/pypy/module/micronumpy/concrete.py
@@ -346,15 +346,12 @@
 
 def customtrace(gc, obj, callback, arg):
 #debug_print('in customtrace w/obj', obj)
-length = rffi.cast(rffi.SIGNEDP, obj + offset_of_length)[0]
-step = rffi.cast(rffi.SIGNEDP, obj + offset_of_step)[0]
+length = (obj + offset_of_length).signed[0]
+step = (obj + offset_of_step).signed[0]
 storage = (obj + offset_of_storage).address[0]
-debug_print('tracing', length, 'objects in ndarray.storage')
+#debug_print('tracing', length, 'objects in ndarray.storage')
 i = 0
 while i  length:
-#gcref = rffi.cast(llmemory.GCREF, storage)
-#w_obj = cast_gcref_to_instance(W_Root, gcref)
-#debug_print('tracing', w_obj) 
 gc._trace_callback(callback, arg, storage)
 storage += step
 i += 1
@@ -369,7 +366,7 @@
 gcstruct = lltype.malloc(OBJECTSTORE)
 # JIT does not support cast_ptr_to_adr
 gcstruct.storage = llmemory.cast_ptr_to_adr(storage)
-print 'create gcstruct',gcstruct,'with 
storage',storage,'as',gcstruct.storage
+#print 'create gcstruct',gcstruct,'with 
storage',storage,'as',gcstruct.storage
 gcstruct.length = length
 gcstruct.step = elsize
 return gcstruct
diff --git a/pypy/module/micronumpy/test/test_dtypes.py 
b/pypy/module/micronumpy/test/test_dtypes.py
--- a/pypy/module/micronumpy/test/test_dtypes.py
+++ b/pypy/module/micronumpy/test/test_dtypes.py
@@ -1350,42 +1350,4 @@
 assert a[0] == 1
 assert (a + a)[1] == 4
 
-class AppTestObjectDtypes(BaseNumpyAppTest):
-def test_scalar_from_object(self):
-from numpy import array
-import sys
-class Polynomial(object):
-def whatami(self):
-return 'an object'
-a = array(Polynomial())
-assert a.shape == ()
-assert a.sum().whatami() == 'an object'
 
-def test_uninitialized_object_array_is_filled_by_None(self):
-import numpy as np
-
-a = np.ndarray([5], dtype=O)
-
-assert a[0] == None
-
-def test_object_arrays_add(self):
-import numpy as np
-
-a = np.array([foo], dtype=object)
-b = np.array([bar], dtype=object)
-
-res = a + b
-assert res[0] == foobar
-
-def test_keep_object_alive(self):
-# XXX how can I run this test?
-import numpy as np
-import gc
-class O(object):
-def whatami(self):
-return 'an object'
-fiveOs = [O()] * 5
-a = np.array(fiveOs, dtype=object)
-del fiveOs
-gc.collect()
-assert a[2].whatami() == 'an object'
diff --git a/pypy/module/micronumpy/test/test_object_arrays.py 
b/pypy/module/micronumpy/test/test_object_arrays.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/micronumpy/test/test_object_arrays.py
@@ -0,0 +1,53 @@
+from pypy.module.micronumpy.test.test_base import BaseNumpyAppTest
+
+
+class AppTestObjectDtypes(BaseNumpyAppTest):
+def test_scalar_from_object(self):
+from numpy import array
+import sys
+class Polynomial(object):
+def whatami(self):
+return 'an object'
+a = array(Polynomial())
+assert a.shape == ()
+assert a.sum().whatami() == 'an object'
+
+def test_uninitialized_object_array_is_filled_by_None(self):
+import numpy as np
+
+a = np.ndarray([5], dtype=O)
+
+assert a[0] == None
+
+def test_object_arrays_add(self):
+import numpy as np
+
+a = np.array([foo], dtype=object)
+b = np.array([bar], dtype=object)
+
+res = a + b
+assert res[0] == foobar
+
+def test_reduce(self):
+import numpy as np
+class O(object):
+def whatami(self):
+return 'an object'
+fiveOs = [O()] * 5
+a = np.array(fiveOs, dtype=object)
+print np.maximum
+b = np.maximum.reduce(a)
+assert b is not None
+
+def test_keep_object_alive(self):
+# only translated does it really test the gc
+import numpy as np
+import gc
+

[pypy-commit] pypy default: merge heads

2015-04-03 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r76699:25109032512b
Date: 2015-04-03 14:37 +0200
http://bitbucket.org/pypy/pypy/changeset/25109032512b/

Log:merge heads

diff --git a/pypy/module/cpyext/longobject.py b/pypy/module/cpyext/longobject.py
--- a/pypy/module/cpyext/longobject.py
+++ b/pypy/module/cpyext/longobject.py
@@ -186,6 +186,17 @@
 pend[0] = rffi.ptradd(str, len(s))
 return space.call_function(space.w_long, w_str, w_base)
 
+@cpython_api([rffi.CWCHARP, Py_ssize_t, rffi.INT_real], PyObject)
+def PyLong_FromUnicode(space, u, length, base):
+Convert a sequence of Unicode digits to a Python long integer value.
+The first parameter, u, points to the first character of the Unicode
+string, length gives the number of characters, and base is the radix
+for the conversion.  The radix must be in the range [2, 36]; if it is
+out of range, ValueError will be raised.
+w_value = space.wrap(rffi.wcharpsize2unicode(u, length))
+w_base = space.wrap(rffi.cast(lltype.Signed, base))
+return space.call_function(space.w_long, w_value, w_base)
+
 @cpython_api([rffi.VOIDP], PyObject)
 def PyLong_FromVoidPtr(space, p):
 Create a Python integer or long integer from the pointer p. The pointer 
value
diff --git a/pypy/module/cpyext/stubs.py b/pypy/module/cpyext/stubs.py
--- a/pypy/module/cpyext/stubs.py
+++ b/pypy/module/cpyext/stubs.py
@@ -1395,18 +1395,6 @@
 
 raise NotImplementedError
 
-@cpython_api([rffi.CWCHARP, Py_ssize_t, rffi.INT_real], PyObject)
-def PyLong_FromUnicode(space, u, length, base):
-Convert a sequence of Unicode digits to a Python long integer value.  
The first
-parameter, u, points to the first character of the Unicode string, length
-gives the number of characters, and base is the radix for the conversion.  
The
-radix must be in the range [2, 36]; if it is out of range, ValueError
-will be raised.
-
-This function used an int for length. This might require
-changes in your code for properly supporting 64-bit systems.
-raise NotImplementedError
-
 @cpython_api([PyObject, rffi.CCHARP], rffi.INT_real, error=-1)
 def PyMapping_DelItemString(space, o, key):
 Remove the mapping for object key from the object o. Return -1 on
diff --git a/pypy/module/cpyext/test/test_longobject.py 
b/pypy/module/cpyext/test/test_longobject.py
--- a/pypy/module/cpyext/test/test_longobject.py
+++ b/pypy/module/cpyext/test/test_longobject.py
@@ -180,3 +180,16 @@
 assert module.from_bytearray(False, False) == 0xBC9A
 assert module.from_bytearray(False, True) == -0x4365
 
+def test_fromunicode(self):
+module = self.import_extension('foo', [
+(from_unicode, METH_O,
+ 
+ Py_UNICODE* u = PyUnicode_AsUnicode(args);
+ return Py_BuildValue(NN,
+ PyLong_FromUnicode(u, 6, 10),
+ PyLong_FromUnicode(u, 6, 16));
+ ),
+])
+# A string with arabic digits. 'BAD' is after the 6th character.
+assert module.from_unicode(u'  1\u0662\u0663\u0664BAD') == (1234, 4660)
+
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Tentative fix for issue #2015. Didn't manage to write a test...

2015-04-03 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r76698:d6e8469e06ee
Date: 2015-04-03 11:32 +0200
http://bitbucket.org/pypy/pypy/changeset/d6e8469e06ee/

Log:Tentative fix for issue #2015. Didn't manage to write a test...

diff --git a/rpython/jit/metainterp/optimizeopt/unroll.py 
b/rpython/jit/metainterp/optimizeopt/unroll.py
--- a/rpython/jit/metainterp/optimizeopt/unroll.py
+++ b/rpython/jit/metainterp/optimizeopt/unroll.py
@@ -438,6 +438,9 @@
 if op.is_ovf():
 guard = ResOperation(rop.GUARD_NO_OVERFLOW, [], None)
 optimizer.send_extra_operation(guard)
+if op.is_call_pure_with_exception():
+guard = ResOperation(rop.GUARD_NO_EXCEPTION, [], None)
+optimizer.send_extra_operation(guard)
 
 def add_op_to_short(self, op, emit=True, guards_needed=False):
 if op is None:
@@ -471,6 +474,9 @@
 # FIXME: ensure that GUARD_OVERFLOW:ed ops not end up here
 guard = ResOperation(rop.GUARD_NO_OVERFLOW, [], None)
 self.add_op_to_short(guard, emit, guards_needed)
+if op.is_call_pure_with_exception():
+guard = ResOperation(rop.GUARD_NO_EXCEPTION, [], None)
+self.add_op_to_short(guard, emit, guards_needed)
 for guard in value_guards:
 self.add_op_to_short(guard, emit, guards_needed)
 
diff --git a/rpython/jit/metainterp/resoperation.py 
b/rpython/jit/metainterp/resoperation.py
--- a/rpython/jit/metainterp/resoperation.py
+++ b/rpython/jit/metainterp/resoperation.py
@@ -176,6 +176,12 @@
 def returns_bool_result(self):
 return self._cls_has_bool_result
 
+def is_call_pure_with_exception(self):
+if self.getopnum() == rop.CALL_PURE:
+effectinfo = self.getdescr().get_extra_info()
+return effectinfo.check_can_raise()
+return False
+
 
 # ===
 # Top of the hierachy
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: A systematic fix for slow get_printable_location(): if we call

2015-04-03 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r76700:c3223de868fa
Date: 2015-04-03 15:09 +0200
http://bitbucket.org/pypy/pypy/changeset/c3223de868fa/

Log:A systematic fix for slow get_printable_location(): if we call
get_location_str() while debug_prints are disabled, it will just
return a disabled string now.

diff --git a/rpython/jit/metainterp/warmstate.py 
b/rpython/jit/metainterp/warmstate.py
--- a/rpython/jit/metainterp/warmstate.py
+++ b/rpython/jit/metainterp/warmstate.py
@@ -4,6 +4,7 @@
 from rpython.jit.codewriter import support, heaptracker, longlong
 from rpython.jit.metainterp import history
 from rpython.rlib.debug import debug_start, debug_stop, debug_print
+from rpython.rlib.debug import have_debug_prints
 from rpython.rlib.jit import PARAMETERS
 from rpython.rlib.nonconst import NonConstant
 from rpython.rlib.objectmodel import specialize, we_are_translated, r_dict
@@ -619,21 +620,28 @@
 self.get_assembler_token = get_assembler_token
 
 #
+jitdriver = self.jitdriver_sd.jitdriver
+if self.jitdriver_sd.jitdriver:
+drivername = jitdriver.name
+else:
+drivername = 'unknown jitdriver'
 get_location_ptr = self.jitdriver_sd._get_printable_location_ptr
 if get_location_ptr is None:
-jitdriver = self.jitdriver_sd.jitdriver
-if self.jitdriver_sd.jitdriver:
-drivername = jitdriver.name
-else:
-drivername = 'unknown jitdriver'
 missing = '(%s: no get_printable_location)' % drivername
 def get_location_str(greenkey):
 return missing
 else:
 rtyper = self.warmrunnerdesc.rtyper
 unwrap_greenkey = self.make_unwrap_greenkey()
+# the following missing text should not be seen, as it is
+# returned only if debug_prints are currently not enabled,
+# but it may show up anyway (consider it bugs)
+missing = ('(%s: get_printable_location '
+   'disabled, no debug_print)' % drivername)
 #
 def get_location_str(greenkey):
+if not have_debug_prints():
+return missing
 greenargs = unwrap_greenkey(greenkey)
 fn = support.maybe_on_top_of_llinterp(rtyper, get_location_ptr)
 llres = fn(*greenargs)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Issue #2015 second attempt: don't put 'call_pure' in short preamble, not

2015-04-03 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r76701:56eebe9dd813
Date: 2015-04-03 15:28 +0200
http://bitbucket.org/pypy/pypy/changeset/56eebe9dd813/

Log:Issue #2015 second attempt: don't put 'call_pure' in short preamble,
not at all, if they can raise. I *think* the issue is that an
exception that we'd get then would be propagated outside, uncaught.

diff --git a/rpython/jit/metainterp/optimizeopt/pure.py 
b/rpython/jit/metainterp/optimizeopt/pure.py
--- a/rpython/jit/metainterp/optimizeopt/pure.py
+++ b/rpython/jit/metainterp/optimizeopt/pure.py
@@ -80,7 +80,13 @@
 args = op.getarglist()
 self.emit_operation(ResOperation(rop.CALL, args, op.result,
  op.getdescr()))
-self.call_pure_positions.append(len(self.optimizer._newoperations) - 1)
+
+# don't move call_pure_with_exception in the short preamble...
+# issue #2015
+effectinfo = op.getdescr().get_extra_info()
+if not effectinfo.check_can_raise():
+self.call_pure_positions.append(
+len(self.optimizer._newoperations) - 1)
 
 def optimize_GUARD_NO_EXCEPTION(self, op):
 if self.last_emitted_operation is REMOVED:
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
@@ -3605,7 +3605,7 @@
 ops = '''
 [p1, i1, i4]
 setfield_gc(p1, i1, descr=valuedescr)
-i3 = call_pure(p1, descr=plaincalldescr)
+i3 = call_pure(p1, descr=cannotraisecalldescr)
 setfield_gc(p1, i3, descr=valuedescr)
 jump(p1, i4, i3)
 '''
@@ -3617,7 +3617,7 @@
 preamble = '''
 [p1, i1, i4]
 setfield_gc(p1, i1, descr=valuedescr)
-i3 = call(p1, descr=plaincalldescr)
+i3 = call(p1, descr=cannotraisecalldescr)
 setfield_gc(p1, i3, descr=valuedescr)
 i148 = same_as(i3)
 i147 = same_as(i3)
@@ -3630,7 +3630,7 @@
 ops = '''
 [p1, i1, i4]
 setfield_gc(p1, i1, descr=valuedescr)
-i3 = call_pure(p1, descr=plaincalldescr)
+i3 = call_pure(p1, descr=cannotraisecalldescr)
 setfield_gc(p1, i1, descr=valuedescr)
 jump(p1, i4, i3)
 '''
@@ -3642,7 +3642,7 @@
 preamble = '''
 [p1, i1, i4]
 setfield_gc(p1, i1, descr=valuedescr)
-i3 = call(p1, descr=plaincalldescr)
+i3 = call(p1, descr=cannotraisecalldescr)
 setfield_gc(p1, i1, descr=valuedescr)
 i151 = same_as(i3)
 jump(p1, i4, i3, i151)
@@ -3656,15 +3656,15 @@
 [i0, i1, i2]
 escape(i1)
 escape(i2)
-i3 = call_pure(123456, 4, 5, 6, descr=plaincalldescr)
-i4 = call_pure(123456, 4, i0, 6, descr=plaincalldescr)
+i3 = call_pure(123456, 4, 5, 6, descr=cannotraisecalldescr)
+i4 = call_pure(123456, 4, i0, 6, descr=cannotraisecalldescr)
 jump(i0, i3, i4)
 '''
 preamble = '''
 [i0, i1, i2]
 escape(i1)
 escape(i2)
-i4 = call(123456, 4, i0, 6, descr=plaincalldescr)
+i4 = call(123456, 4, i0, 6, descr=cannotraisecalldescr)
 i153 = same_as(i4)
 jump(i0, i4, i153)
 '''
@@ -3678,6 +3678,8 @@
 
 def test_call_pure_constant_folding_exc(self):
 # CALL_PURE may be followed by GUARD_NO_EXCEPTION
+# XXX maybe temporary, but we can't remove such call_pures from
+# the loop, because the short preamble can't call them safely.
 arg_consts = [ConstInt(i) for i in (123456, 4, 5, 6)]
 call_pure_results = {tuple(arg_consts): ConstInt(42)}
 ops = '''
@@ -3696,14 +3698,15 @@
 escape(i2)
 i4 = call(123456, 4, i0, 6, descr=plaincalldescr)
 guard_no_exception() []
-i155 = same_as(i4)
-jump(i0, i4, i155)
+jump(i0, i4)
 '''
 expected = '''
-[i0, i2, i3]
+[i0, i2]
 escape(42)
 escape(i2)
-jump(i0, i3, i3)
+i4 = call(123456, 4, i0, 6, descr=plaincalldescr)
+guard_no_exception() []
+jump(i0, i4)
 '''
 self.optimize_loop(ops, expected, preamble, call_pure_results)
 
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
@@ -182,6 +182,9 @@
 FUNC = lltype.FuncType([lltype.Signed], lltype.Signed)
 plaincalldescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
  EffectInfo.MOST_GENERAL)
+cannotraisecalldescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
+EffectInfo([], [], [], 

[pypy-commit] pypy default: 'fix' test

2015-04-03 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r76702:b58c996fdef5
Date: 2015-04-03 16:15 +0200
http://bitbucket.org/pypy/pypy/changeset/b58c996fdef5/

Log:'fix' test

diff --git a/rpython/jit/metainterp/test/test_string.py 
b/rpython/jit/metainterp/test/test_string.py
--- a/rpython/jit/metainterp/test/test_string.py
+++ b/rpython/jit/metainterp/test/test_string.py
@@ -897,7 +897,9 @@
 m -= 1
 return 42
 self.meta_interp(f, [6, 7])
-self.check_resops(unicodesetitem=2, newunicode=2, call=4,
+# xxx used to be 'call=4', but the two extra calls in the loop
+# are not safe to remove; see 56eebe9dd813
+self.check_resops(unicodesetitem=2, newunicode=2, call=6,
   copyunicodecontent=2, unicodegetitem=0)
 
 def test_str2unicode_fold(self):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy vmprof: API change: _vmprof.enable() second argument is now measured in seconds,

2015-04-03 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: vmprof
Changeset: r76704:6fd836a1af7b
Date: 2015-04-03 19:17 +0200
http://bitbucket.org/pypy/pypy/changeset/6fd836a1af7b/

Log:API change: _vmprof.enable() second argument is now measured in
seconds, given as a float, as customary in Python

diff --git a/pypy/module/_vmprof/interp_vmprof.py 
b/pypy/module/_vmprof/interp_vmprof.py
--- a/pypy/module/_vmprof/interp_vmprof.py
+++ b/pypy/module/_vmprof/interp_vmprof.py
@@ -134,12 +134,12 @@
 self.fileno = -1
 self.current_codes = []
 
-def enable(self, space, fileno, period):
+def enable(self, space, fileno, period_usec):
 if self.is_enabled:
 raise oefmt(space.w_ValueError, _vmprof already enabled)
 self.fileno = fileno
 self.is_enabled = True
-self.write_header(fileno, period)
+self.write_header(fileno, period_usec)
 if not self.ever_enabled:
 if we_are_translated():
 pypy_vmprof_init()
@@ -148,7 +148,7 @@
 space.register_code_callback(vmprof_register_code)
 if we_are_translated():
 # does not work untranslated
-res = vmprof_enable(fileno, period, 0,
+res = vmprof_enable(fileno, period_usec, 0,
 lltype.nullptr(rffi.CCHARP.TO), 0)
 else:
 res = 0
@@ -161,11 +161,8 @@
 for code in all_code_objs:
 self.register_code(space, code)
 
-def write_header(self, fileno, period):
-if period == -1:
-period_usec = 100 / 100 #  100hz
-else:
-period_usec = period
+def write_header(self, fileno, period_usec):
+assert period_usec  0
 b = StringBuilder()
 write_long_to_string_builder(0, b)
 write_long_to_string_builder(3, b)
@@ -217,13 +214,22 @@
 mod_vmprof = space.getbuiltinmodule('_vmprof')
 assert isinstance(mod_vmprof, Module)
 mod_vmprof.vmprof.register_code(space, code)
-
-@unwrap_spec(fileno=int, period=int)
-def enable(space, fileno, period=-1):
+
+@unwrap_spec(fileno=int, period=float)
+def enable(space, fileno, period=0.01):   # default 100 Hz
 from pypy.module._vmprof import Module
 mod_vmprof = space.getbuiltinmodule('_vmprof')
 assert isinstance(mod_vmprof, Module)
-mod_vmprof.vmprof.enable(space, fileno, period)
+#
+try:
+period_usec = int(period * 100.0 + 0.5)
+if period_usec = 0:
+raise ValueError
+except (ValueError, OverflowError):
+raise OperationError(self.w_ValueError,
+ self.wrap('period' too large or non positive))
+#
+mod_vmprof.vmprof.enable(space, fileno, period_usec)
 
 def disable(space):
 from pypy.module._vmprof import Module
diff --git a/pypy/module/_vmprof/src/vmprof.c b/pypy/module/_vmprof/src/vmprof.c
--- a/pypy/module/_vmprof/src/vmprof.c
+++ b/pypy/module/_vmprof/src/vmprof.c
@@ -65,6 +65,7 @@
 }
 
 static void prof_header(long period_usec) {
+// XXX never used here?
 prof_word(0);
 prof_word(3);
 prof_word(0);
@@ -351,8 +352,7 @@
 int vmprof_enable(int fd, long period_usec, int write_header, char *s,
  int slen)
 {
-if (period_usec == -1)
-period_usec = 100 / 100; /* 100hz */
+assert(period_usec  0);
 if (open_profile(fd, period_usec, write_header, s, slen) == -1) {
return -1;
}
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy vmprof: API change

2015-04-03 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: vmprof
Changeset: r76705:cd020116336a
Date: 2015-04-03 19:18 +0200
http://bitbucket.org/pypy/pypy/changeset/cd020116336a/

Log:API change

diff --git a/rpython/bin/rpython-vmprof b/rpython/bin/rpython-vmprof
--- a/rpython/bin/rpython-vmprof
+++ b/rpython/bin/rpython-vmprof
@@ -19,7 +19,7 @@
 
 import _vmprof, subprocess
 x = subprocess.Popen('gzip  vmprof.log.gz', shell=True, stdin=subprocess.PIPE)
-_vmprof.enable(x.stdin.fileno(), 1000)
+_vmprof.enable(x.stdin.fileno(), 0.001)
 try:
 main()
 finally:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy.org extradoc: update the values

2015-04-03 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: extradoc
Changeset: r593:90cced881ed2
Date: 2015-04-03 19:48 +0200
http://bitbucket.org/pypy/pypy.org/changeset/90cced881ed2/

Log:update the values

diff --git a/don1.html b/don1.html
--- a/don1.html
+++ b/don1.html
@@ -15,7 +15,7 @@
 /script
 
!-- Income:PyPy:Donations:Py3k / 0.95 --
-   $59106 of $105000 (56.3%)
+   $59130 of $105000 (56.3%)
div id=progressbar
/div
 
diff --git a/don4.html b/don4.html
--- a/don4.html
+++ b/don4.html
@@ -17,7 +17,7 @@
2nd call:
!-- Income:PyPy:Donations:Transactional Memory from April 8, 2014,
divided by 0.9 --
-   $22663 of $8 (28.3%)
+   $22674 of $8 (28.3%)
div id=progressbar
/div
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy vmprof: Kill recursive, with comment

2015-04-03 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: vmprof
Changeset: r76703:8ef1c41ed611
Date: 2015-04-03 19:06 +0200
http://bitbucket.org/pypy/pypy/changeset/8ef1c41ed611/

Log:Kill recursive, with comment

diff --git a/pypy/module/_vmprof/src/vmprof.c b/pypy/module/_vmprof/src/vmprof.c
--- a/pypy/module/_vmprof/src/vmprof.c
+++ b/pypy/module/_vmprof/src/vmprof.c
@@ -140,29 +140,25 @@
  * *
  */
 
-// stolen from pprof:
-// Sometimes, we can try to get a stack trace from within a stack
-// trace, because libunwind can call mmap (maybe indirectly via an
-// internal mmap based memory allocator), and that mmap gets trapped
-// and causes a stack-trace request.  If were to try to honor that
-// recursive request, we'd end up with infinite recursion or deadlock.
-// Luckily, it's safe to ignore those subsequent traces.  In such
-// cases, we return 0 to indicate the situation.
+// The original code here has a comment, stolen from pprof,
+// about a __thread int recursive.  But general __thread
+// variables are not really supposed to be accessed from a
+// signal handler.  Moreover, we are using SIGPROF, which
+// should not be recursively called on the same thread.
 //static __thread int recursive;
-static int recursive; // XXX antocuni: removed __thread
 
 int get_stack_trace(void** result, int max_depth, ucontext_t *ucontext) {
 void *ip;
 int n = 0;
 unw_cursor_t cursor;
 unw_context_t uc = *ucontext;
-if (recursive) {
+//if (recursive) {
+//return 0;
+//}
+if (!custom_sanity_check()) {
 return 0;
 }
-   if (!custom_sanity_check()) {
-   return 0;
-   }
-++recursive;
+//++recursive;
 
 int ret = unw_init_local(cursor, uc);
 assert(ret = 0);
@@ -209,7 +205,7 @@
 }
first_run = 0;
 }
---recursive;
+//--recursive;
 return n;
 }
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit