[pypy-commit] pypy default: Make this variable #defined to , like CPython did when

2011-08-03 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r46228:13db7e546d76
Date: 2011-08-03 08:02 +0200
http://bitbucket.org/pypy/pypy/changeset/13db7e546d76/

Log:Make this variable #defined to , like CPython did when migrating
to Mercurial.

diff --git a/pypy/module/cpyext/include/patchlevel.h 
b/pypy/module/cpyext/include/patchlevel.h
--- a/pypy/module/cpyext/include/patchlevel.h
+++ b/pypy/module/cpyext/include/patchlevel.h
@@ -31,8 +31,9 @@
 /* PyPy version as a string */
 #define PYPY_VERSION 1.6.0
 
-/* Subversion Revision number of this file (not of the repository) */
-#define PY_PATCHLEVEL_REVISION  $Revision: 77872 $
+/* Subversion Revision number of this file (not of the repository).
+ * Empty since Mercurial migration. */
+#define PY_PATCHLEVEL_REVISION  
 
 /* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2.
Use this for numeric comparisons, e.g. #if PY_VERSION_HEX = ... */
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy numpy-dtype: dtype can be specified as keyword to array()

2011-08-03 Thread justinpeel
Author: Justin Peel notmuchtot...@gmail.com
Branch: numpy-dtype
Changeset: r46229:313d75d25bbf
Date: 2011-08-03 00:06 -0600
http://bitbucket.org/pypy/pypy/changeset/313d75d25bbf/

Log:dtype can be specified as keyword to array()

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
@@ -268,7 +268,6 @@
 # part of itself. can be improved.
 if (concrete.get_root_storage() ==
 w_value.get_concrete().get_root_storage()):
-# XXX: Need to fill in dtype
 w_value = new_numarray(space, w_value, self.dtype)
 else:
 w_value = convert_to_array(space, w_value)
@@ -582,12 +581,16 @@
 
 def descr_new_numarray(space, w_type, __args__):
 # this isn't such a great check. We should improve it including exceptions.
-# Also needs to be able to handle keywords
+# Also needs to be able to handle keywords better
 iterable = __args__.arguments_w[0]
-if len(__args__.arguments_w) == 2:
+if __args__.keywords:
+if __args__.keywords[0] == 'dtype':
+dtype = __args__.keywords_w[0]
+else:
+msg = array() got unexpected keyword argument
+raise OperationError(space.w_TypeError, space.wrap(msg))
+elif len(__args__.arguments_w) == 2:
 dtype = __args__.arguments_w[1]
-return space.wrap(new_numarray(space, __args__.arguments_w[0],
-__args__.arguments_w[1]))
 else:
 # can just use the dtype for float for now. We need to actually be
 # able to determine the base dtype of an iterable
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
@@ -18,10 +18,10 @@
 
 def test_bool_array(self):
 from numpy import array
-a = array([0, 1, 2, 2.5], '?')
-assert a[0] == False
+a = array([0, 1, 2, 2.5], dtype='?')
+assert a[0] is False
 for i in xrange(1, 4):
-assert a[i] == True
+assert a[i] is True
 
 def test_overflow(self):
 from numpy import array
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Skip this test here.

2011-08-03 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r46230:88d80aef1433
Date: 2011-08-03 08:07 +0200
http://bitbucket.org/pypy/pypy/changeset/88d80aef1433/

Log:Skip this test here.

diff --git a/pypy/jit/backend/llgraph/test/test_llgraph.py 
b/pypy/jit/backend/llgraph/test/test_llgraph.py
--- a/pypy/jit/backend/llgraph/test/test_llgraph.py
+++ b/pypy/jit/backend/llgraph/test/test_llgraph.py
@@ -19,6 +19,9 @@
 def setup_method(self, _):
 self.cpu = self.cpu_type(None)
 
+def test_memoryerror(self):
+py.test.skip(does not make much sense on the llgraph backend)
+
 
 def test_cast_adr_to_int_and_back():
 X = lltype.Struct('X', ('foo', lltype.Signed))
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Fix tests, and a clean up, by not reusing a Descr across various loops.

2011-08-03 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r46231:7f3f578cb546
Date: 2011-08-03 08:26 +0200
http://bitbucket.org/pypy/pypy/changeset/7f3f578cb546/

Log:Fix tests, and a clean up, by not reusing a Descr across various
loops.

diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py
--- a/pypy/jit/metainterp/compile.py
+++ b/pypy/jit/metainterp/compile.py
@@ -671,8 +671,6 @@
 assert exception, PropagateExceptionDescr: no exception??
 raise metainterp_sd.ExitFrameWithExceptionRef(cpu, exception)
 
-propagate_exception_descr = PropagateExceptionDescr()
-
 def compile_tmp_callback(cpu, jitdriver_sd, greenboxes, redboxes,
  memory_manager=None):
 Make a LoopToken that corresponds to assembler code that just
@@ -706,7 +704,7 @@
 finishargs = []
 #
 jd = jitdriver_sd
-faildescr = propagate_exception_descr
+faildescr = PropagateExceptionDescr()
 operations = [
 ResOperation(rop.CALL, callargs, result, descr=jd.portal_calldescr),
 ResOperation(rop.GUARD_NO_EXCEPTION, [], None, descr=faildescr),
diff --git a/pypy/jit/metainterp/pyjitpl.py b/pypy/jit/metainterp/pyjitpl.py
--- a/pypy/jit/metainterp/pyjitpl.py
+++ b/pypy/jit/metainterp/pyjitpl.py
@@ -1379,7 +1379,7 @@
 num = self.cpu.get_fail_descr_number(tokens[0].finishdescr)
 setattr(self.cpu, 'done_with_this_frame_%s_v' % name, num)
 #
-exc_descr = compile.propagate_exception_descr
+exc_descr = compile.PropagateExceptionDescr()
 num = self.cpu.get_fail_descr_number(exc_descr)
 self.cpu.propagate_exception_v = num
 #
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy numpy-dtype: change array repr and str to format ints and bools correctly. still need to show dtype.

2011-08-03 Thread justinpeel
Author: Justin Peel notmuchtot...@gmail.com
Branch: numpy-dtype
Changeset: r46234:21b2605606ce
Date: 2011-08-03 01:13 -0600
http://bitbucket.org/pypy/pypy/changeset/21b2605606ce/

Log:change array repr and str to format ints and bools correctly. still
need to show dtype.

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
@@ -200,19 +200,24 @@
 return self.descr_mul(space, w_other)
 
 def _getnums(self, comma):
+kind = self.find_dtype().kind
+if kind == 'f':
+format_func = float2string
+else:
+format_func = str
 if self.find_size()  1000:
 nums = [
-float2string(self.eval(index))
+format_func(self.eval(index))
 for index in range(3)
 ]
 nums.append(... + , * comma)
 nums.extend([
-float2string(self.eval(index))
+format_func(self.eval(index))
 for index in range(self.find_size() - 3, self.find_size())
 ])
 else:
 nums = [
-float2string(self.eval(index))
+format_func(self.eval(index))
 for index in range(self.find_size())
 ]
 return nums
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
@@ -56,6 +56,10 @@
 assert repr(a) == array([0.0, 1.0, 2.0, 3.0, 4.0])
 a = zeros(1001)
 assert repr(a) == array([0.0, 0.0, 0.0, ..., 0.0, 0.0, 0.0])
+a = array(range(5), 'l')
+assert repr(a) == array([0, 1, 2, 3, 4])
+a = array([True, False, True, False], '?')
+assert repr(a) == array([True, False, True, False])
 
 def test_repr_slice(self):
 from numpy import array, zeros
@@ -73,6 +77,10 @@
 assert str((2*a)[:]) == [0.0 2.0 4.0 6.0 8.0]
 a = zeros(1001)
 assert str(a) == [0.0 0.0 0.0 ..., 0.0 0.0 0.0]
+a = array(range(5), 'l')
+assert str(a) == [0 1 2 3 4]
+a = array([True, False, True, False], '?')
+assert str(a) == [True False True False]
 
 def test_str_slice(self):
 from numpy import array, zeros
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy numpy-dtype: dtypes repr and str

2011-08-03 Thread justinpeel
Author: Justin Peel notmuchtot...@gmail.com
Branch: numpy-dtype
Changeset: r46235:b0f23dc4ccac
Date: 2011-08-03 01:32 -0600
http://bitbucket.org/pypy/pypy/changeset/b0f23dc4ccac/

Log:dtypes repr and str

diff --git a/pypy/module/micronumpy/interp_dtype.py 
b/pypy/module/micronumpy/interp_dtype.py
--- a/pypy/module/micronumpy/interp_dtype.py
+++ b/pypy/module/micronumpy/interp_dtype.py
@@ -67,13 +67,14 @@
 # fields, names, f?, metadata. I'll just implement the base minimum for 
 # now. This will include type, kind, typeobj?, byteorder, type_num, elsize,
 # 
-def __init__(self, castfunc, unwrapfunc, num, kind):
+def __init__(self, name, castfunc, unwrapfunc, num, kind):
 # doesn't handle align and copy parameters yet
 # only deals with simple strings e.g., 'uint32', and type objects
 self.cast = castfunc
 self.unwrap = unwrapfunc
 self.num = num
 self.kind = kind
+self.name = name
 
 def descr_num(self, space):
 return space.wrap(self.num)
@@ -81,6 +82,14 @@
 def descr_kind(self, space):
 return space.wrap(self.kind)
 
+def descr_name(self, space):
+return space.wrap(self.name)
+
+def descr_repr(self, space):
+return space.wrap(dtype('%s') % self.name)
+
+descr_str = descr_name
+
 def unwrap_float(space, val):
 return space.float_w(space.float(val))
 
@@ -132,20 +141,22 @@
 def cast_float96(val):
 return rffi.cast(lltype.LongFloat, val)
 
-Bool_dtype = Dtype(cast_bool, unwrap_bool, Bool_num, BOOLLTR)
-Int8_dtype = Dtype(cast_int8, unwrap_int, Int8_num, SIGNEDLTR)
-UInt8_dtype = Dtype(cast_uint8, unwrap_int, UInt8_num, UNSIGNEDLTR)
-Int16_dtype = Dtype(cast_int16, unwrap_int, Int16_num, SIGNEDLTR)
-UInt16_dtype = Dtype(cast_uint16, unwrap_int, UInt16_num, UNSIGNEDLTR)
-Int32_dtype = Dtype(cast_int32, unwrap_int, Int32_num, SIGNEDLTR)
-UInt32_dtype = Dtype(cast_uint32, unwrap_int, UInt32_num, UNSIGNEDLTR)
-Long_dtype = Dtype(cast_long, unwrap_int, Long_num, SIGNEDLTR)
-ULong_dtype = Dtype(cast_ulong, unwrap_int, ULong_num, UNSIGNEDLTR)
-Int64_dtype = Dtype(cast_int64, unwrap_int, Int64_num, SIGNEDLTR)
-UInt64_dtype = Dtype(cast_uint64, unwrap_int, UInt64_num, UNSIGNEDLTR)
-Float32_dtype = Dtype(cast_float32, unwrap_float, Float32_num, FLOATINGLTR)
-Float64_dtype = Dtype(cast_float64, unwrap_float, Float64_num, FLOATINGLTR)
-Float96_dtype = Dtype(cast_float96, unwrap_float, Float96_num, FLOATINGLTR)
+Bool_dtype = Dtype('bool', cast_bool, unwrap_bool, Bool_num, BOOLLTR)
+Int8_dtype = Dtype('int8', cast_int8, unwrap_int, Int8_num, SIGNEDLTR)
+UInt8_dtype = Dtype('uint8', cast_uint8, unwrap_int, UInt8_num, UNSIGNEDLTR)
+Int16_dtype = Dtype('int16', cast_int16, unwrap_int, Int16_num, SIGNEDLTR)
+UInt16_dtype = Dtype('uint16', cast_uint16, unwrap_int, UInt16_num, 
UNSIGNEDLTR)
+Int32_dtype = Dtype('int32', cast_int32, unwrap_int, Int32_num, SIGNEDLTR)
+UInt32_dtype = Dtype('uint32', cast_uint32, unwrap_int, UInt32_num, 
UNSIGNEDLTR)
+Long_dtype = Dtype('int32' if LONG_BIT == 32 else 'int64', 
+cast_long, unwrap_int, Long_num, SIGNEDLTR)
+ULong_dtype = Dtype('uint32' if LONG_BIT == 32 else 'uint64',
+cast_ulong, unwrap_int, ULong_num, UNSIGNEDLTR)
+Int64_dtype = Dtype('int64', cast_int64, unwrap_int, Int64_num, SIGNEDLTR)
+UInt64_dtype = Dtype('uint64', cast_uint64, unwrap_int, UInt64_num, 
UNSIGNEDLTR)
+Float32_dtype = Dtype('float32', cast_float32, unwrap_float, Float32_num, 
FLOATINGLTR)
+Float64_dtype = Dtype('float64', cast_float64, unwrap_float, Float64_num, 
FLOATINGLTR)
+Float96_dtype = Dtype('float96', cast_float96, unwrap_float, Float96_num, 
FLOATINGLTR)
 
 _dtype_list = (Bool_dtype,
Int8_dtype,
@@ -241,4 +252,8 @@
 
 num = GetSetProperty(Dtype.descr_num),
 kind = GetSetProperty(Dtype.descr_kind),
+name = GetSetProperty(Dtype.descr_name),
+
+__repr__ = interp2app(Dtype.descr_repr),
+__str__ = interp2app(Dtype.descr_str),
 )
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
@@ -17,6 +17,12 @@
 assert dtype(int).num == 7
 assert dtype(long).num == 9
 assert dtype(float).num == 12
+
+def test_repr_str(self):
+from numpy import dtype
+d = dtype('?')
+assert repr(d) == dtype('bool')
+assert str(d) == bool
 
 def test_bool_array(self):
 from numpy import array
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Fix this test.

2011-08-03 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r46236:3a789ffe42d2
Date: 2011-08-03 10:03 +0200
http://bitbucket.org/pypy/pypy/changeset/3a789ffe42d2/

Log:Fix this test.

diff --git a/pypy/module/pypyjit/test_pypy_c/test_string.py 
b/pypy/module/pypyjit/test_pypy_c/test_string.py
--- a/pypy/module/pypyjit/test_pypy_c/test_string.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_string.py
@@ -90,12 +90,12 @@
 i46 = call(ConstClass(ll_startswith__rpy_stringPtr_rpy_stringPtr), 
p28, ConstPtr(ptr45), descr=BoolCallDescr)
 guard_false(i46, descr=...)
 p51 = new_with_vtable(21136408)
-setfield_gc(p51, p28, descr=GcPtrFieldDescr 
.*NumberStringParser.inst_literal .*)
-setfield_gc(p51, ConstPtr(ptr51), descr=GcPtrFieldDescr 
pypy.objspace.std.strutil.NumberStringParser.inst_fname .*)
-setfield_gc(p51, 1, descr=SignedFieldDescr 
.*NumberStringParser.inst_sign .*)
-setfield_gc(p51, 16, descr=SignedFieldDescr 
.*NumberStringParser.inst_base .*)
-setfield_gc(p51, p28, descr=GcPtrFieldDescr 
.*NumberStringParser.inst_s .*)
-setfield_gc(p51, i29, descr=SignedFieldDescr 
.*NumberStringParser.inst_n .*)
+setfield_gc(p51, _, descr=...)# 6 setfields, but the order is 
dict-order-dependent
+setfield_gc(p51, _, descr=...)
+setfield_gc(p51, _, descr=...)
+setfield_gc(p51, _, descr=...)
+setfield_gc(p51, _, descr=...)
+setfield_gc(p51, _, descr=...)
 p55 = call(ConstClass(parse_digit_string), p51, 
descr=GcPtrCallDescr)
 guard_no_exception(descr=...)
 i57 = call(ConstClass(rbigint.toint), p55, descr=SignedCallDescr)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Fix on 64-bit.

2011-08-03 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r46237:4f04cbd0fdec
Date: 2011-08-03 10:06 +0200
http://bitbucket.org/pypy/pypy/changeset/4f04cbd0fdec/

Log:Fix on 64-bit.

diff --git a/pypy/jit/backend/llsupport/test/test_ffisupport.py 
b/pypy/jit/backend/llsupport/test/test_ffisupport.py
--- a/pypy/jit/backend/llsupport/test/test_ffisupport.py
+++ b/pypy/jit/backend/llsupport/test/test_ffisupport.py
@@ -1,4 +1,5 @@
 from pypy.rlib.libffi import types
+from pypy.jit.codewriter.longlong import is_64_bit
 from pypy.jit.backend.llsupport.ffisupport import *
 
 
@@ -34,11 +35,14 @@
 assert descr.get_result_size(False) == 1
 assert descr.is_result_signed() == False
 
-descr = get_call_descr_dynamic(FakeCPU(), [], types.slonglong)
-assert descr is None   # missing longlongs
-descr = get_call_descr_dynamic(FakeCPU(supports_longlong=True),
-   [], types.slonglong)
-assert isinstance(descr, LongLongCallDescr)
+if not is_64_bit:
+descr = get_call_descr_dynamic(FakeCPU(), [], types.slonglong)
+assert descr is None   # missing longlongs
+descr = get_call_descr_dynamic(FakeCPU(supports_longlong=True),
+   [], types.slonglong)
+assert isinstance(descr, LongLongCallDescr)
+else:
+assert types.slonglong is types.slong
 
 descr = get_call_descr_dynamic(FakeCPU(), [], types.float)
 assert descr is None   # missing singlefloats
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Fix on 64-bit.

2011-08-03 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r46238:883e8d58e5ff
Date: 2011-08-03 10:08 +0200
http://bitbucket.org/pypy/pypy/changeset/883e8d58e5ff/

Log:Fix on 64-bit.

diff --git a/pypy/jit/backend/x86/test/test_regloc.py 
b/pypy/jit/backend/x86/test/test_regloc.py
--- a/pypy/jit/backend/x86/test/test_regloc.py
+++ b/pypy/jit/backend/x86/test/test_regloc.py
@@ -62,7 +62,7 @@
 assert mc.relocations == [5]
 expected = \xE8 + struct.pack('i', target - (rawstart + 5))
 elif IS_X86_64:
-assert mc.relocations == []
+assert mc.relocations is None
 if 0 = target = 0x:
 assert length == 9
 expected = (
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: A failing test.

2011-08-03 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r46239:ac3bce776870
Date: 2011-08-03 10:23 +0200
http://bitbucket.org/pypy/pypy/changeset/ac3bce776870/

Log:A failing test.

diff --git a/pypy/module/itertools/test/test_itertools.py 
b/pypy/module/itertools/test/test_itertools.py
--- a/pypy/module/itertools/test/test_itertools.py
+++ b/pypy/module/itertools/test/test_itertools.py
@@ -266,6 +266,13 @@
 raises(StopIteration, islc.next)  # drops the 6th and raise
 assert it.next() == j
 
+it = iter(abcdefghij)
+islc = itertools.islice(it, 3, 4, 3)
+assert islc.next() == d# drops 0, 1, 2, returns item #3
+assert it.next() == e
+raises(StopIteration, islc.next)  # item #4 is 'stop', so just raise
+assert it.next() == f
+
 def test_islice_overflow(self):
 import itertools
 import sys
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Fix.

2011-08-03 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r46240:cfe2dcf79e90
Date: 2011-08-03 10:35 +0200
http://bitbucket.org/pypy/pypy/changeset/cfe2dcf79e90/

Log:Fix.

diff --git a/pypy/module/itertools/interp_itertools.py 
b/pypy/module/itertools/interp_itertools.py
--- a/pypy/module/itertools/interp_itertools.py
+++ b/pypy/module/itertools/interp_itertools.py
@@ -339,16 +339,21 @@
 start = 0
 else:
 start = space.int_w(w_startstop)
+if start  0:
+raise OperationError(space.w_ValueError, space.wrap(
+   Indicies for islice() must be non-negative integers.))
 w_stop = args_w[0]
 else:
 raise OperationError(space.w_TypeError, space.wrap(islice() takes 
at most 4 arguments ( + str(num_args) +  given)))
 
 if space.is_w(w_stop, space.w_None):
 stop = -1
-stoppable = False
 else:
 stop = space.int_w(w_stop)
-stoppable = True
+if stop  0:
+raise OperationError(space.w_ValueError, space.wrap(
+Stop argument must be a non-negative integer or None.))
+stop = max(start, stop)# for obscure CPython compatibility
 
 if num_args == 2:
 w_step = args_w[1]
@@ -356,38 +361,37 @@
 step = 1
 else:
 step = space.int_w(w_step)
+if step  1:
+raise OperationError(space.w_ValueError, space.wrap(
+Step must be one or lager for islice().))
 else:
 step = 1
 
-if start  0:
-raise OperationError(space.w_ValueError, space.wrap(Indicies for 
islice() must be non-negative integers.))
-if stoppable and stop  0:
-raise OperationError(space.w_ValueError, space.wrap(Stop argument 
must be a non-negative integer or None.))
-if step  1:
-raise OperationError(space.w_ValueError, space.wrap(Step must be 
one or lager for islice().))
-
+self.ignore = step - 1
 self.start = start
 self.stop = stop
-self.step = step
 
 def iter_w(self):
 return self.space.wrap(self)
 
 def next_w(self):
 if self.start = 0:   # first call only
-consume = self.start + 1
+ignore = self.start
 self.start = -1
 else: # all following calls
-consume = self.step
-if consume  1:
-self._ignore_items(consume-1)
-if self.stop = 0:
-if self.stop  consume:
+ignore = self.ignore
+stop = self.stop
+if stop = 0:
+if stop = ignore:
 self.stop = 0   # reset the state so that a following next_w()
-self.step = 1   # has no effect any more
+# has no effect any more
+if stop  0:
+self._ignore_items(stop)
 raise OperationError(self.space.w_StopIteration,
  self.space.w_None)
-self.stop -= consume
+self.stop = stop - (ignore + 1)
+if ignore  0:
+self._ignore_items(ignore)
 return self.space.next(self.iterable)
 
 def _ignore_items(self, num):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy release-1.6.x: merge default

2011-08-03 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: release-1.6.x
Changeset: r46241:5fadf40d80b0
Date: 2011-08-03 13:34 +0200
http://bitbucket.org/pypy/pypy/changeset/5fadf40d80b0/

Log:merge default

diff --git a/pypy/jit/backend/llgraph/test/test_llgraph.py 
b/pypy/jit/backend/llgraph/test/test_llgraph.py
--- a/pypy/jit/backend/llgraph/test/test_llgraph.py
+++ b/pypy/jit/backend/llgraph/test/test_llgraph.py
@@ -19,6 +19,9 @@
 def setup_method(self, _):
 self.cpu = self.cpu_type(None)
 
+def test_memoryerror(self):
+py.test.skip(does not make much sense on the llgraph backend)
+
 
 def test_cast_adr_to_int_and_back():
 X = lltype.Struct('X', ('foo', lltype.Signed))
diff --git a/pypy/jit/backend/llsupport/gc.py b/pypy/jit/backend/llsupport/gc.py
--- a/pypy/jit/backend/llsupport/gc.py
+++ b/pypy/jit/backend/llsupport/gc.py
@@ -544,18 +544,19 @@
 assert self.GCClass.inline_simple_malloc
 assert self.GCClass.inline_simple_malloc_varsize
 
-# make a malloc function, with three arguments
+# make a malloc function, with two arguments
 def malloc_basic(size, tid):
 type_id = llop.extract_ushort(llgroup.HALFWORD, tid)
 has_finalizer = bool(tid  (1llgroup.HALFSHIFT))
 check_typeid(type_id)
-try:
-res = llop1.do_malloc_fixedsize_clear(llmemory.GCREF,
-  type_id, size, True,
-  has_finalizer, False)
-except MemoryError:
-fatalerror(out of memory (from JITted code))
-res = lltype.nullptr(llmemory.GCREF.TO)
+res = llop1.do_malloc_fixedsize_clear(llmemory.GCREF,
+  type_id, size, True,
+  has_finalizer, False)
+# In case the operation above failed, we are returning NULL
+# from this function to assembler.  There is also an RPython
+# exception set, typically MemoryError; but it's easier and
+# faster to check for the NULL return value, as done by
+# translator/exceptiontransform.py.
 #llop.debug_print(lltype.Void, \tmalloc_basic, size, type_id,
 # --, res)
 return res
@@ -571,14 +572,10 @@
 def malloc_array(itemsize, tid, num_elem):
 type_id = llop.extract_ushort(llgroup.HALFWORD, tid)
 check_typeid(type_id)
-try:
-return llop1.do_malloc_varsize_clear(
-llmemory.GCREF,
-type_id, num_elem, self.array_basesize, itemsize,
-self.array_length_ofs, True)
-except MemoryError:
-fatalerror(out of memory (from JITted code))
-return lltype.nullptr(llmemory.GCREF.TO)
+return llop1.do_malloc_varsize_clear(
+llmemory.GCREF,
+type_id, num_elem, self.array_basesize, itemsize,
+self.array_length_ofs, True)
 self.malloc_array = malloc_array
 self.GC_MALLOC_ARRAY = lltype.Ptr(lltype.FuncType(
 [lltype.Signed] * 3, llmemory.GCREF))
@@ -591,23 +588,15 @@
 unicode_type_id = self.layoutbuilder.get_type_id(rstr.UNICODE)
 #
 def malloc_str(length):
-try:
-return llop1.do_malloc_varsize_clear(
-llmemory.GCREF,
-str_type_id, length, str_basesize, str_itemsize,
-str_ofs_length, True)
-except MemoryError:
-fatalerror(out of memory (from JITted code))
-return lltype.nullptr(llmemory.GCREF.TO)
+return llop1.do_malloc_varsize_clear(
+llmemory.GCREF,
+str_type_id, length, str_basesize, str_itemsize,
+str_ofs_length, True)
 def malloc_unicode(length):
-try:
-return llop1.do_malloc_varsize_clear(
-llmemory.GCREF,
-unicode_type_id, length, unicode_basesize,unicode_itemsize,
-unicode_ofs_length, True)
-except MemoryError:
-fatalerror(out of memory (from JITted code))
-return lltype.nullptr(llmemory.GCREF.TO)
+return llop1.do_malloc_varsize_clear(
+llmemory.GCREF,
+unicode_type_id, length, unicode_basesize,unicode_itemsize,
+unicode_ofs_length, True)
 self.malloc_str = malloc_str
 self.malloc_unicode = malloc_unicode
 self.GC_MALLOC_STR_UNICODE = lltype.Ptr(lltype.FuncType(
@@ -628,16 +617,12 @@
 if self.DEBUG:
 random_usage_of_xmm_registers()
 assert size = self.minimal_size_in_nursery
-try:
-# NB. although we call 

[pypy-commit] pypy default: (arigo, antocuni): test and fix for an obscure bug when deleting attributes inside slots(), which caused random segfaults because you could end up with a NULL instead of an

2011-08-03 Thread antocuni
Author: Antonio Cuni anto.c...@gmail.com
Branch: 
Changeset: r46242:34f36be0f080
Date: 2011-08-03 15:05 +0200
http://bitbucket.org/pypy/pypy/changeset/34f36be0f080/

Log:(arigo, antocuni): test and fix for an obscure bug when deleting
attributes inside slots(), which caused random segfaults because you
could end up with a NULL instead of an actual W_Root

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -111,6 +111,9 @@
 def setslotvalue(self, index, w_val):
 raise NotImplementedError
 
+def delslotvalue(self, index):
+raise NotImplementedError
+
 def descr_call_mismatch(self, space, opname, RequiredClass, args):
 if RequiredClass is None:
 classname = '?'
diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py
--- a/pypy/interpreter/typedef.py
+++ b/pypy/interpreter/typedef.py
@@ -258,6 +258,11 @@
 self.slots_w = [None] * nslots
 def setslotvalue(self, index, w_value):
 self.slots_w[index] = w_value
+def delslotvalue(self, index):
+if self.slots_w[index] is None:
+return False
+self.slots_w[index] = None
+return True
 def getslotvalue(self, index):
 return self.slots_w[index]
 add(Proto)
@@ -530,11 +535,10 @@
 member.__delete__(obj)
 Delete the value of the slot 'member' from the given 'obj'.
 self.typecheck(space, w_obj)
-w_oldresult = w_obj.getslotvalue(self.index)
-if w_oldresult is None:
+success = w_obj.delslotvalue(self.index)
+if not success:
 raise OperationError(space.w_AttributeError,
  space.wrap(self.name)) # XXX better message
-w_obj.setslotvalue(self.index, None)
 
 Member.typedef = TypeDef(
 member_descriptor,
diff --git a/pypy/objspace/std/mapdict.py b/pypy/objspace/std/mapdict.py
--- a/pypy/objspace/std/mapdict.py
+++ b/pypy/objspace/std/mapdict.py
@@ -421,6 +421,14 @@
 key = (slot, SLOTS_STARTING_FROM + index)
 self._get_mapdict_map().write(self, key, w_value)
 
+def delslotvalue(self, index):
+key = (slot, SLOTS_STARTING_FROM + index)
+new_obj = self._get_mapdict_map().delete(self, key)
+if new_obj is None:
+return False
+self._become(new_obj)
+return True
+
 # used by _weakref implemenation
 
 def getweakref(self):
diff --git a/pypy/objspace/std/test/test_mapdict.py 
b/pypy/objspace/std/test/test_mapdict.py
--- a/pypy/objspace/std/test/test_mapdict.py
+++ b/pypy/objspace/std/test/test_mapdict.py
@@ -210,6 +210,12 @@
 assert obj2.storage == [501, 601, 701, 51, 61, 71]
 assert obj.map is obj2.map
 
+assert obj2.getslotvalue(b) == 601
+assert obj2.delslotvalue(b)
+assert obj2.getslotvalue(b) is None
+assert obj2.storage == [501, 701, 51, 61, 71]
+assert not obj2.delslotvalue(b)
+
 
 def test_slots_no_dict():
 cls = Class(hasdict=False)
@@ -631,6 +637,14 @@
 a.__dict__ = {}
 a.__dict__ = {}
 
+def test_delete_slot(self):
+class A(object):
+__slots__ = ['x']
+
+a = A()
+a.x = 42
+del a.x
+raises(AttributeError, a.x)
 
 class AppTestWithMapDictAndCounters(object):
 def setup_class(cls):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] buildbot default: use python on win/os x

2011-08-03 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: 
Changeset: r547:2cf882b10d4b
Date: 2011-08-03 15:16 +0200
http://bitbucket.org/pypy/buildbot/changeset/2cf882b10d4b/

Log:use python on win/os x

diff --git a/bot2/pypybuildbot/builds.py b/bot2/pypybuildbot/builds.py
--- a/bot2/pypybuildbot/builds.py
+++ b/bot2/pypybuildbot/builds.py
@@ -56,19 +56,20 @@
 description = [translating]
 descriptionDone = [translation]
 
-command = [pypy, translate.py, --batch]
+command = [translate.py, --batch]
 translationTarget = targetpypystandalone
 haltOnFailure = True
 
 def __init__(self, translationArgs, targetArgs,
  workdir=build/pypy/translator/goal,
+ interpreter='pypy',
  *a, **kw):
 add_args = {'translationArgs': translationArgs,
 'targetArgs': targetArgs}
 kw['timeout'] = 3600
 ShellCmd.__init__(self, workdir, *a, **kw)
 self.addFactoryArguments(**add_args)
-self.command = (self.command + translationArgs +
+self.command = ([interpreter] + self.command + translationArgs +
 [self.translationTarget] + targetArgs)
 #self.command = ['cp', '/tmp/pypy-c', '.']
 
diff --git a/bot2/pypybuildbot/master.py b/bot2/pypybuildbot/master.py
--- a/bot2/pypybuildbot/master.py
+++ b/bot2/pypybuildbot/master.py
@@ -125,7 +125,8 @@
 pypyTranslatedAppLevelTestFactoryWin = pypybuilds.Translated(
 platform=win32,
 lib_python=True,
-app_tests=True)
+app_tests=True,
+interpreter='python')
 
 jit_translation_args = ['-Ojit']
 
@@ -152,6 +153,7 @@
 lib_python=True,
 pypyjit=True,
 app_tests=True,
+interpreter='python',
 )
 
 pypyJITTranslatedTestFactoryOSX64 = pypybuilds.Translated(
@@ -161,6 +163,7 @@
 lib_python=True,
 pypyjit=True,
 app_tests=True,
+interpreter='python',
 )
 
 pypyJITTranslatedTestFactoryWin = pypybuilds.Translated(
@@ -170,6 +173,7 @@
 lib_python=True,
 pypyjit=True,
 app_tests=True,
+interpreter='python',
 )
 
 pypy_OjitTranslatedTestFactory = pypybuilds.Translated(
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] buildbot default: merge

2011-08-03 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: 
Changeset: r548:1b4c4c52f405
Date: 2011-08-03 15:18 +0200
http://bitbucket.org/pypy/buildbot/changeset/1b4c4c52f405/

Log:merge

diff --git a/.hgignore b/.hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -14,18 +14,13 @@
 httpd.log*
 
 # ignore all the builders dir (which can be both in master/ and in slave/)
-jit-benchmark-linux-x86-32
-jitonly-own-linux-x86-32
-own-linux-x86-32
-own-linux-x86-64
-own-macosx-x86-32
-pypy-c-Ojit-no-jit-linux-x86-32
-pypy-c-app-level-linux-x86-32
-pypy-c-app-level-linux-x86-64
-pypy-c-app-level-win-x86-32
-pypy-c-jit-linux-x86-32
-pypy-c-jit-linux-x86-64
-pypy-c-jit-macosx-x86-64
-pypy-c-jit-win-x86-32
-pypy-c-stackless-app-level-freebsd-7-x86-64
-pypy-c-stackless-app-level-linux-x86-32
+*-linux-x86-32
+*-linux-x86-32vm
+*-linux-x86-64
+*-macosx-x86-32
+*-macosx-x86-64
+*-win-x86-32
+*-win-32
+*-freebsd-7-x86-64
+*-maemo
+*-maemo-build
diff --git a/bbhook/run.py b/bbhook/run.py
--- a/bbhook/run.py
+++ b/bbhook/run.py
@@ -16,8 +16,11 @@
 #HOST_NAME = 'wyvern.cs.uni-duesseldorf.de'
 HOST_NAME = ''
 PORT_NUMBER = 9237
+# WARNING:
+# deply is meant as a argument for running public facing,
+# its not supposed to be used when running a proxy setup
 main.app.run(
-host = HOST_NAME if 'deploy' in sys.argv else 'localhost',
+host = HOST_NAME if 'deploy' in sys.argv else '127.0.0.1',
 debug = 'debug' in sys.argv,
 port=PORT_NUMBER)
 
diff --git a/bbhook/scm.py b/bbhook/scm.py
--- a/bbhook/scm.py
+++ b/bbhook/scm.py
@@ -1,6 +1,7 @@
 import sys
 from subprocess import Popen, PIPE
 
+MAX_DIFF_LINES = 1
 
 def _hgexe(argv):
 proc = Popen(['hg'] + list(argv), stdout=PIPE, stderr=PIPE)
@@ -21,8 +22,11 @@
 
 def get_diff(local_repo, hgid):
 out = hg('-R', local_repo, 'diff', '--git', '-c', hgid)
-out = out.splitlines(True)
-out_iter = iter(out)
+lines = out.splitlines(True)
+return filter_diff(lines)
+
+def filter_diff(lines):
+out_iter = iter(lines)
 lines = []
 for line in out_iter:
 lines.append(line)
@@ -34,6 +38,9 @@
 if item[0]!='z':
 break  # binary patches end with a empty line
 
+if len(lines)  MAX_DIFF_LINES:
+msg = 'diff too long, truncating to %d out of %d lines\n\n' % 
(MAX_DIFF_LINES, len(lines))
+lines = [msg] + lines[:MAX_DIFF_LINES]
 
 return u''.join(lines)
 
diff --git a/bbhook/test/test_scm.py b/bbhook/test/test_scm.py
--- a/bbhook/test/test_scm.py
+++ b/bbhook/test/test_scm.py
@@ -32,3 +32,24 @@
 with pytest.raises(Exception):
 print scm.hg
 scm.hg('uhmwrong')
+
+
+def test_huge_diff(monkeypatch):
+monkeypatch.setattr(scm, 'MAX_DIFF_LINES', 4)
+lines = \
+one
+two
+three
+for
+five
+six
+.splitlines(True)
+diff = scm.filter_diff(lines)
+assert diff == \
+diff too long, truncating to 4 out of 6 lines
+
+one
+two
+three
+for
+
diff --git a/bot2/pypybuildbot/builds.py b/bot2/pypybuildbot/builds.py
--- a/bot2/pypybuildbot/builds.py
+++ b/bot2/pypybuildbot/builds.py
@@ -2,9 +2,25 @@
 from buildbot.steps import source, shell, transfer, master
 from buildbot.status.builder import SUCCESS
 from buildbot.process.properties import WithProperties
+from buildbot import locks
 from pypybuildbot.util import symlink_force
 import os
 
+# buildbot supports SlaveLocks, which can be used to limit the amout of builds
+# to be run on each slave in parallel.  However, they assume that each
+# buildslave is on a differen physical machine, which is not the case for
+# tannit32 and tannit64.  As a result, we have to use a global lock, and
+# manually tell each builder that uses tannit to acquire it.
+#
+# Look at the various locks session in master.py/BuildmasterConfig.  For
+# benchmarks, the locks is aquired for the single steps: this way we can run
+# translations in parallel, but then the actual benchmarks are run in
+# sequence.
+
+# there are 8 logical CPUs, but only 4 physical ones
+TannitCPU = locks.MasterLock('tannit_cpu', maxCount=6)
+
+
 class ShellCmd(shell.ShellCommand):
 # our own version that can distinguish abort cases (rc == -1)
 
@@ -143,7 +159,7 @@
 repourl = 'https://bitbucket.org/pypy/pypy/'
 if getpass.getuser() == 'antocuni':
 # for debugging
-repourl = '/home/antocuni/pypy/pypy-hg'
+repourl = '/home/antocuni/pypy/default'
 #
 if platform == 'win32':
 command = if not exist .hg rmdir /q /s .
@@ -260,8 +276,12 @@
 else:
 if '--stackless' in translationArgs:
 kind = 'stackless'
+elif '-Ojit' in translationArgs:
+kind = 'jitnojit'
+elif '-O2' in translationArgs:
+kind = 'nojit'
 else:
-kind = 'nojit'
+kind = 'unknown'
 name = 'pypy-c-' + kind + '-%(final_file_name)s-' + platform
 self.addStep(ShellCmd(
 

[pypy-commit] pypy default: enable the fastpath also for functions which are constructed through a CFUNCTYPE; this considerably speeds up memmove and memset

2011-08-03 Thread antocuni
Author: Antonio Cuni anto.c...@gmail.com
Branch: 
Changeset: r46243:b4cd45e7402e
Date: 2011-08-03 15:20 +0200
http://bitbucket.org/pypy/pypy/changeset/b4cd45e7402e/

Log:enable the fastpath also for functions which are constructed through
a CFUNCTYPE; this considerably speeds up memmove and memset

diff --git a/lib_pypy/_ctypes/function.py b/lib_pypy/_ctypes/function.py
--- a/lib_pypy/_ctypes/function.py
+++ b/lib_pypy/_ctypes/function.py
@@ -91,13 +91,15 @@
 raise TypeError(
 item %d in _argtypes_ has no from_param method % (
 i + 1,))
-#
-if all([hasattr(argtype, '_ffiargshape') for argtype in argtypes]):
-fastpath_cls = make_fastpath_subclass(self.__class__)
-fastpath_cls.enable_fastpath_maybe(self)
 self._argtypes_ = list(argtypes)
+self._check_argtypes_for_fastpath()
 argtypes = property(_getargtypes, _setargtypes)
 
+def _check_argtypes_for_fastpath(self):
+if all([hasattr(argtype, '_ffiargshape') for argtype in 
self._argtypes_]):
+fastpath_cls = make_fastpath_subclass(self.__class__)
+fastpath_cls.enable_fastpath_maybe(self)
+
 def _getparamflags(self):
 return self._paramflags
 
@@ -216,6 +218,7 @@
 import ctypes
 restype = ctypes.c_int
 self._ptr = self._getfuncptr_fromaddress(self._argtypes_, restype)
+self._check_argtypes_for_fastpath()
 return
 
 
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_fastpath.py 
b/pypy/module/test_lib_pypy/ctypes_tests/test_fastpath.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_fastpath.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_fastpath.py
@@ -1,4 +1,4 @@
-from ctypes import CDLL, POINTER, pointer, c_byte, c_int, c_char_p
+from ctypes import CDLL, POINTER, pointer, c_byte, c_int, c_char_p, CFUNCTYPE, 
c_void_p, c_size_t
 import sys
 import py
 from support import BaseCTypesTestChecker
@@ -46,6 +46,12 @@
 tf_b.argtypes = (c_byte,)
 assert tf_b(-126) == -42
 
+def test_from_cfunctype(self):
+from _ctypes import _memmove_addr
+functype = CFUNCTYPE(c_void_p, c_void_p, c_void_p, c_size_t)
+my_memmove = functype(_memmove_addr)
+assert my_memmove._is_fastpath
+
 def test_undeclared_restype(self):
 # make sure we get a fresh function
 try:
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy release-1.6.x: merge default

2011-08-03 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: release-1.6.x
Changeset: r46244:627d599f4c82
Date: 2011-08-03 15:29 +0200
http://bitbucket.org/pypy/pypy/changeset/627d599f4c82/

Log:merge default

diff --git a/lib_pypy/_ctypes/function.py b/lib_pypy/_ctypes/function.py
--- a/lib_pypy/_ctypes/function.py
+++ b/lib_pypy/_ctypes/function.py
@@ -91,13 +91,15 @@
 raise TypeError(
 item %d in _argtypes_ has no from_param method % (
 i + 1,))
-#
-if all([hasattr(argtype, '_ffiargshape') for argtype in argtypes]):
-fastpath_cls = make_fastpath_subclass(self.__class__)
-fastpath_cls.enable_fastpath_maybe(self)
 self._argtypes_ = list(argtypes)
+self._check_argtypes_for_fastpath()
 argtypes = property(_getargtypes, _setargtypes)
 
+def _check_argtypes_for_fastpath(self):
+if all([hasattr(argtype, '_ffiargshape') for argtype in 
self._argtypes_]):
+fastpath_cls = make_fastpath_subclass(self.__class__)
+fastpath_cls.enable_fastpath_maybe(self)
+
 def _getparamflags(self):
 return self._paramflags
 
@@ -216,6 +218,7 @@
 import ctypes
 restype = ctypes.c_int
 self._ptr = self._getfuncptr_fromaddress(self._argtypes_, restype)
+self._check_argtypes_for_fastpath()
 return
 
 
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -111,6 +111,9 @@
 def setslotvalue(self, index, w_val):
 raise NotImplementedError
 
+def delslotvalue(self, index):
+raise NotImplementedError
+
 def descr_call_mismatch(self, space, opname, RequiredClass, args):
 if RequiredClass is None:
 classname = '?'
diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py
--- a/pypy/interpreter/typedef.py
+++ b/pypy/interpreter/typedef.py
@@ -258,6 +258,11 @@
 self.slots_w = [None] * nslots
 def setslotvalue(self, index, w_value):
 self.slots_w[index] = w_value
+def delslotvalue(self, index):
+if self.slots_w[index] is None:
+return False
+self.slots_w[index] = None
+return True
 def getslotvalue(self, index):
 return self.slots_w[index]
 add(Proto)
@@ -530,11 +535,10 @@
 member.__delete__(obj)
 Delete the value of the slot 'member' from the given 'obj'.
 self.typecheck(space, w_obj)
-w_oldresult = w_obj.getslotvalue(self.index)
-if w_oldresult is None:
+success = w_obj.delslotvalue(self.index)
+if not success:
 raise OperationError(space.w_AttributeError,
  space.wrap(self.name)) # XXX better message
-w_obj.setslotvalue(self.index, None)
 
 Member.typedef = TypeDef(
 member_descriptor,
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_fastpath.py 
b/pypy/module/test_lib_pypy/ctypes_tests/test_fastpath.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_fastpath.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_fastpath.py
@@ -1,4 +1,4 @@
-from ctypes import CDLL, POINTER, pointer, c_byte, c_int, c_char_p
+from ctypes import CDLL, POINTER, pointer, c_byte, c_int, c_char_p, CFUNCTYPE, 
c_void_p, c_size_t
 import sys
 import py
 from support import BaseCTypesTestChecker
@@ -46,6 +46,12 @@
 tf_b.argtypes = (c_byte,)
 assert tf_b(-126) == -42
 
+def test_from_cfunctype(self):
+from _ctypes import _memmove_addr
+functype = CFUNCTYPE(c_void_p, c_void_p, c_void_p, c_size_t)
+my_memmove = functype(_memmove_addr)
+assert my_memmove._is_fastpath
+
 def test_undeclared_restype(self):
 # make sure we get a fresh function
 try:
diff --git a/pypy/objspace/std/mapdict.py b/pypy/objspace/std/mapdict.py
--- a/pypy/objspace/std/mapdict.py
+++ b/pypy/objspace/std/mapdict.py
@@ -421,6 +421,14 @@
 key = (slot, SLOTS_STARTING_FROM + index)
 self._get_mapdict_map().write(self, key, w_value)
 
+def delslotvalue(self, index):
+key = (slot, SLOTS_STARTING_FROM + index)
+new_obj = self._get_mapdict_map().delete(self, key)
+if new_obj is None:
+return False
+self._become(new_obj)
+return True
+
 # used by _weakref implemenation
 
 def getweakref(self):
diff --git a/pypy/objspace/std/test/test_mapdict.py 
b/pypy/objspace/std/test/test_mapdict.py
--- a/pypy/objspace/std/test/test_mapdict.py
+++ b/pypy/objspace/std/test/test_mapdict.py
@@ -210,6 +210,12 @@
 assert obj2.storage == [501, 601, 701, 51, 61, 71]
 assert obj.map is obj2.map
 
+assert obj2.getslotvalue(b) == 601
+assert 

[pypy-commit] pypy default: Use asmgcc by default only on Linux. On other platforms,

2011-08-03 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r46245:320dcd7c2fbd
Date: 2011-08-03 15:30 +0200
http://bitbucket.org/pypy/pypy/changeset/320dcd7c2fbd/

Log:Use asmgcc by default only on Linux. On other platforms, use the
shadowstack by default.

diff --git a/pypy/config/translationoption.py b/pypy/config/translationoption.py
--- a/pypy/config/translationoption.py
+++ b/pypy/config/translationoption.py
@@ -13,6 +13,10 @@
 DEFL_LOW_INLINE_THRESHOLD = DEFL_INLINE_THRESHOLD / 2.0
 
 DEFL_GC = minimark
+if sys.platform.startswith(linux):
+DEFL_ROOTFINDER_WITHJIT = asmgcc
+else:
+DEFL_ROOTFINDER_WITHJIT = shadowstack
 
 IS_64_BITS = sys.maxint  2147483647
 
@@ -109,7 +113,7 @@
 BoolOption(jit, generate a JIT,
default=False,
suggests=[(translation.gc, DEFL_GC),
- (translation.gcrootfinder, asmgcc),
+ (translation.gcrootfinder, DEFL_ROOTFINDER_WITHJIT),
  (translation.list_comprehension_operations, True)]),
 ChoiceOption(jit_backend, choose the backend for the JIT,
  [auto, x86, x86-without-sse2, llvm],
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: merge heads

2011-08-03 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r46246:263ef79f483f
Date: 2011-08-03 15:30 +0200
http://bitbucket.org/pypy/pypy/changeset/263ef79f483f/

Log:merge heads

diff --git a/lib_pypy/_ctypes/function.py b/lib_pypy/_ctypes/function.py
--- a/lib_pypy/_ctypes/function.py
+++ b/lib_pypy/_ctypes/function.py
@@ -91,13 +91,15 @@
 raise TypeError(
 item %d in _argtypes_ has no from_param method % (
 i + 1,))
-#
-if all([hasattr(argtype, '_ffiargshape') for argtype in argtypes]):
-fastpath_cls = make_fastpath_subclass(self.__class__)
-fastpath_cls.enable_fastpath_maybe(self)
 self._argtypes_ = list(argtypes)
+self._check_argtypes_for_fastpath()
 argtypes = property(_getargtypes, _setargtypes)
 
+def _check_argtypes_for_fastpath(self):
+if all([hasattr(argtype, '_ffiargshape') for argtype in 
self._argtypes_]):
+fastpath_cls = make_fastpath_subclass(self.__class__)
+fastpath_cls.enable_fastpath_maybe(self)
+
 def _getparamflags(self):
 return self._paramflags
 
@@ -216,6 +218,7 @@
 import ctypes
 restype = ctypes.c_int
 self._ptr = self._getfuncptr_fromaddress(self._argtypes_, restype)
+self._check_argtypes_for_fastpath()
 return
 
 
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_fastpath.py 
b/pypy/module/test_lib_pypy/ctypes_tests/test_fastpath.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_fastpath.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_fastpath.py
@@ -1,4 +1,4 @@
-from ctypes import CDLL, POINTER, pointer, c_byte, c_int, c_char_p
+from ctypes import CDLL, POINTER, pointer, c_byte, c_int, c_char_p, CFUNCTYPE, 
c_void_p, c_size_t
 import sys
 import py
 from support import BaseCTypesTestChecker
@@ -46,6 +46,12 @@
 tf_b.argtypes = (c_byte,)
 assert tf_b(-126) == -42
 
+def test_from_cfunctype(self):
+from _ctypes import _memmove_addr
+functype = CFUNCTYPE(c_void_p, c_void_p, c_void_p, c_size_t)
+my_memmove = functype(_memmove_addr)
+assert my_memmove._is_fastpath
+
 def test_undeclared_restype(self):
 # make sure we get a fresh function
 try:
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] buildbot default: Revert this part of the change: use the default options on all

2011-08-03 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r550:4eb5a8b112cf
Date: 2011-08-03 15:31 +0200
http://bitbucket.org/pypy/buildbot/changeset/4eb5a8b112cf/

Log:Revert this part of the change: use the default options on all
platforms.

diff --git a/bot2/pypybuildbot/master.py b/bot2/pypybuildbot/master.py
--- a/bot2/pypybuildbot/master.py
+++ b/bot2/pypybuildbot/master.py
@@ -130,7 +130,6 @@
 interpreter='python')
 
 jit_translation_args = ['-Ojit']
-jit_translation_args_shadowstack = ['-Ojit', '--gcrootfinder=shadowstack']
 
 pypyJITTranslatedTestFactory = pypybuilds.Translated(
 translationArgs=jit_translation_args,
@@ -150,7 +149,7 @@
 
 pypyJITTranslatedTestFactoryOSX = pypybuilds.Translated(
 platform='osx',
-translationArgs=jit_translation_args_shadowstack,
+translationArgs=jit_translation_args,
 targetArgs=[],
 lib_python=True,
 pypyjit=True,
@@ -160,7 +159,7 @@
 
 pypyJITTranslatedTestFactoryOSX64 = pypybuilds.Translated(
 platform='osx64',
-translationArgs=jit_translation_args_shadowstack,
+translationArgs=jit_translation_args,
 targetArgs=[],
 lib_python=True,
 pypyjit=True,
@@ -170,7 +169,7 @@
 
 pypyJITTranslatedTestFactoryWin = pypybuilds.Translated(
 platform=win32,
-translationArgs=jit_translation_args_shadowstack,
+translationArgs=jit_translation_args,
 targetArgs=[],
 lib_python=True,
 pypyjit=True,
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] buildbot default: oops pass this around

2011-08-03 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: 
Changeset: r551:6050cc5f5f7c
Date: 2011-08-03 15:52 +0200
http://bitbucket.org/pypy/buildbot/changeset/6050cc5f5f7c/

Log:oops pass this around

diff --git a/bot2/pypybuildbot/builds.py b/bot2/pypybuildbot/builds.py
--- a/bot2/pypybuildbot/builds.py
+++ b/bot2/pypybuildbot/builds.py
@@ -220,6 +220,7 @@
 def __init__(self, platform='linux',
  translationArgs=['-O2'], targetArgs=[],
  app_tests=False,
+ interpreter='pypy',
  lib_python=False,
  pypyjit=False
  ):
@@ -227,7 +228,8 @@
 
 setup_steps(platform, self)
 
-self.addStep(Translate(translationArgs, targetArgs))
+self.addStep(Translate(translationArgs, targetArgs,
+   interpreter=interpreter))
 
 if app_tests:
 if app_tests == True:
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] buildbot default: merge

2011-08-03 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: 
Changeset: r552:d4b311b0e72d
Date: 2011-08-03 15:53 +0200
http://bitbucket.org/pypy/buildbot/changeset/d4b311b0e72d/

Log:merge

diff --git a/bot2/pypybuildbot/master.py b/bot2/pypybuildbot/master.py
--- a/bot2/pypybuildbot/master.py
+++ b/bot2/pypybuildbot/master.py
@@ -169,7 +169,7 @@
 
 pypyJITTranslatedTestFactoryWin = pypybuilds.Translated(
 platform=win32,
-translationArgs=['-Ojit', '--gcrootfinder=shadowstack'],
+translationArgs=jit_translation_args,
 targetArgs=[],
 lib_python=True,
 pypyjit=True,
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] buildbot default: Maybe we need to add it as a factory argument.

2011-08-03 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r554:25dfadc9eafb
Date: 2011-08-03 16:06 +0200
http://bitbucket.org/pypy/buildbot/changeset/25dfadc9eafb/

Log:Maybe we need to add it as a factory argument.

diff --git a/bot2/pypybuildbot/builds.py b/bot2/pypybuildbot/builds.py
--- a/bot2/pypybuildbot/builds.py
+++ b/bot2/pypybuildbot/builds.py
@@ -81,7 +81,8 @@
  interpreter='pypy',
  *a, **kw):
 add_args = {'translationArgs': translationArgs,
-'targetArgs': targetArgs}
+'targetArgs': targetArgs,
+'interpreter': interpreter}
 kw['timeout'] = 3600
 ShellCmd.__init__(self, workdir, *a, **kw)
 self.addFactoryArguments(**add_args)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: The next OpenBSD64 fix...

2011-08-03 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r46248:65f7df526fc1
Date: 2011-08-03 17:44 +0200
http://bitbucket.org/pypy/pypy/changeset/65f7df526fc1/

Log:The next OpenBSD64 fix...

diff --git a/pypy/module/rctime/interp_time.py 
b/pypy/module/rctime/interp_time.py
--- a/pypy/module/rctime/interp_time.py
+++ b/pypy/module/rctime/interp_time.py
@@ -320,7 +320,7 @@
 def _gettmarg(space, w_tup, allowNone=True):
 if allowNone and space.is_w(w_tup, space.w_None):
 # default to the current local time
-tt = rffi.r_time_t(pytime.time())
+tt = rffi.r_time_t(int(pytime.time()))
 t_ref = lltype.malloc(rffi.TIME_TP.TO, 1, flavor='raw')
 t_ref[0] = tt
 pbuf = c_localtime(t_ref)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy numpy-dtype: code clean-up and add one test

2011-08-03 Thread justinpeel
Author: Justin Peel notmuchtot...@gmail.com
Branch: numpy-dtype
Changeset: r46249:c9320ca675c9
Date: 2011-08-03 10:58 -0600
http://bitbucket.org/pypy/pypy/changeset/c9320ca675c9/

Log:code clean-up and add one test

diff --git a/pypy/module/micronumpy/interp_dtype.py 
b/pypy/module/micronumpy/interp_dtype.py
--- a/pypy/module/micronumpy/interp_dtype.py
+++ b/pypy/module/micronumpy/interp_dtype.py
@@ -180,33 +180,6 @@
 if space.is_true(space.isinstance(scalar, space.w_float)):
 return Float64_dtype
 
-def get_dtype(space, w_type, w_string_or_type):
-if space.is_true(space.isinstance(w_string_or_type, 
space.gettypeobject(Dtype.typedef))):
-return w_string_or_type
-if space.is_true(space.isinstance(w_string_or_type, space.w_str)):
-s = space.str_w(w_string_or_type)
-if len(s) == 1:
-typenum = _letters_to_nums[ord(s)]
-dtype = _dtype_list[typenum]
-if typenum != -1 and dtype is not None:
-return _dtype_list[typenum]
-# XXX: can improve this part. will need to for endianness
-if s in num_dict:
-return _dtype_list[num_dict[s]]
-raise OperationError(space.w_ValueError,
-space.wrap(type not recognized))
-elif space.is_true(space.isinstance(w_string_or_type, space.w_type)):
-if space.is_w(w_string_or_type, 
space.gettypeobject(W_IntObject.typedef)):
-return Long_dtype
-if space.is_w(w_string_or_type, 
space.gettypeobject(W_LongObject.typedef)):
-return Int64_dtype
-if space.is_w(w_string_or_type, 
space.gettypeobject(W_FloatObject.typedef)):
-return Float64_dtype
-if space.is_w(w_string_or_type, 
space.gettypeobject(W_BoolObject.typedef)):
-return Bool_dtype
-raise OperationError(space.w_TypeError,
-space.wrap(data type not understood))
-
 def find_result_dtype(d1, d2):
 # this function is for determining the result dtype of bin ops, etc.
 # it is kind of a mess so feel free to improve it
@@ -243,8 +216,35 @@
 return Float64_dtype
 return dtype2
 
+def get_dtype(space, str_or_type):
+if space.is_true(space.isinstance(str_or_type, 
space.gettypeobject(Dtype.typedef))):
+return str_or_type
+if space.is_true(space.isinstance(str_or_type, space.w_str)):
+s = space.str_w(str_or_type)
+if len(s) == 1:
+typenum = _letters_to_nums[ord(s)]
+dtype = _dtype_list[typenum]
+if typenum != -1 and dtype is not None:
+return _dtype_list[typenum]
+# XXX: can improve this part. will need to for endianness
+if s in num_dict:
+return _dtype_list[num_dict[s]]
+raise OperationError(space.w_ValueError,
+space.wrap(type not recognized))
+elif space.is_true(space.isinstance(str_or_type, space.w_type)):
+if space.is_w(str_or_type, space.gettypeobject(W_IntObject.typedef)):
+return Long_dtype
+if space.is_w(str_or_type, space.gettypeobject(W_LongObject.typedef)):
+return Int64_dtype
+if space.is_w(str_or_type, space.gettypeobject(W_FloatObject.typedef)):
+return Float64_dtype
+if space.is_w(str_or_type, space.gettypeobject(W_BoolObject.typedef)):
+return Bool_dtype
+raise OperationError(space.w_TypeError,
+space.wrap(data type not understood))
+
 def descr_new_dtype(space, w_type, w_string_or_type):
-return space.wrap(get_dtype(space, w_type, w_string_or_type))
+return space.wrap(get_dtype(space, w_string_or_type))
 
 Dtype.typedef = TypeDef(
 'numpy.dtype',
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
@@ -574,7 +574,7 @@
 
 def new_numarray(space, iterable, dtype):
 l = space.listview(iterable)
-dtype = get_dtype(space, Dtype, dtype)
+dtype = get_dtype(space, dtype)
 arr = SingleDimArray(len(l), dtype)
 i = 0
 unwrap = dtype.unwrap
@@ -588,14 +588,14 @@
 # this isn't such a great check. We should improve it including exceptions.
 # Also needs to be able to handle keywords better
 iterable = __args__.arguments_w[0]
-if __args__.keywords:
+if len(__args__.arguments_w) == 2:
+dtype = __args__.arguments_w[1]
+elif __args__.keywords:
 if __args__.keywords[0] == 'dtype':
 dtype = __args__.keywords_w[0]
 else:
 msg = array() got unexpected keyword argument
 raise OperationError(space.w_TypeError, space.wrap(msg))
-elif len(__args__.arguments_w) == 2:
-dtype = __args__.arguments_w[1]
 else:
 # can just use the dtype for float for now. We need to actually be
 # able to determine the base dtype 

[pypy-commit] pypy jit-short_from_state: fix test

2011-08-03 Thread hakanardo
Author: Hakan Ardo ha...@debian.org
Branch: jit-short_from_state
Changeset: r46250:b9c1fec7c7d6
Date: 2011-08-02 18:47 +0200
http://bitbucket.org/pypy/pypy/changeset/b9c1fec7c7d6/

Log:fix test

diff --git a/pypy/jit/metainterp/test/test_virtualstate.py 
b/pypy/jit/metainterp/test/test_virtualstate.py
--- a/pypy/jit/metainterp/test/test_virtualstate.py
+++ b/pypy/jit/metainterp/test/test_virtualstate.py
@@ -1,5 +1,5 @@
 import py
-from pypy.jit.metainterp.optimizeutil import InvalidLoop
+from pypy.jit.metainterp.optimize import InvalidLoop
 from pypy.jit.metainterp.optimizeopt.virtualstate import VirtualStateInfo, 
VStructStateInfo, \
  VArrayStateInfo, NotVirtualStateInfo
 from pypy.jit.metainterp.optimizeopt.optimizer import OptValue
@@ -134,6 +134,9 @@
 guards = []
 info1.generate_guards(info2, box, self.cpu, guards, {})
 loop = self.parse(expected)
+for op in loop.operations:
+if op.is_guard():
+op.setdescr(None)
 assert equaloplists(guards, loop.operations, False,
 {loop.inputargs[0]: box})
 def test_intbounds(self):
@@ -181,6 +184,9 @@
 guard_class(p0, ConstClass(node_vtable)) []
 
 loop = self.parse(expected)
+for op in loop.operations:
+if op.is_guard():
+op.setdescr(None)
 assert equaloplists(guards, loop.operations, False,
 {loop.inputargs[0]: box})
 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jit-short_from_state: constants

2011-08-03 Thread hakanardo
Author: Hakan Ardo ha...@debian.org
Branch: jit-short_from_state
Changeset: r46251:7941f47c4d85
Date: 2011-08-02 20:34 +0200
http://bitbucket.org/pypy/pypy/changeset/7941f47c4d85/

Log:constants

diff --git a/pypy/jit/metainterp/test/test_virtualstate.py 
b/pypy/jit/metainterp/test/test_virtualstate.py
--- a/pypy/jit/metainterp/test/test_virtualstate.py
+++ b/pypy/jit/metainterp/test/test_virtualstate.py
@@ -298,6 +298,31 @@
 
 self.optimize_bridge(loops, bridge, expected, 'Loop0', p0=self.myptr)
 
+def test_constant(self):
+loops = 
+[p0]
+p1 = same_as(ConstPtr(myptr))
+jump(p1)
+, 
+[p0]
+p1 = same_as(ConstPtr(myptr2))
+jump(p1)
+, 
+[p0]
+jump(p0)
+
+expected = 
+[p0]
+jump()
+
+self.optimize_bridge(loops, loops[0], expected, 'Loop0')
+self.optimize_bridge(loops, loops[1], expected, 'Loop1')
+expected = 
+[p0]
+jump(p0)
+
+self.optimize_bridge(loops, loops[2], expected, 'Loop2')
+
 class TestLLtypeGuards(BaseTestGenerateGuards, LLtypeMixin):
 pass
 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jit-short_from_state: virtual

2011-08-03 Thread hakanardo
Author: Hakan Ardo ha...@debian.org
Branch: jit-short_from_state
Changeset: r46252:ae3dc8168a0c
Date: 2011-08-02 20:44 +0200
http://bitbucket.org/pypy/pypy/changeset/ae3dc8168a0c/

Log:virtual

diff --git a/pypy/jit/metainterp/test/test_virtualstate.py 
b/pypy/jit/metainterp/test/test_virtualstate.py
--- a/pypy/jit/metainterp/test/test_virtualstate.py
+++ b/pypy/jit/metainterp/test/test_virtualstate.py
@@ -323,6 +323,38 @@
 
 self.optimize_bridge(loops, loops[2], expected, 'Loop2')
 
+def test_virtual(self):
+loops = 
+[p0, p1]
+p2 = new_with_vtable(ConstClass(node_vtable))
+setfield_gc(p2, p1, descr=nextdescr)
+setfield_gc(p2, 7, descr=adescr)
+setfield_gc(p2, 42, descr=bdescr)
+jump(p2, p1)
+
+expected = 
+[p0, p1]
+jump(p1)
+
+self.optimize_bridge(loops, loops, expected, 'Loop0')
+bridge = 
+[p0, p1]
+p2 = new_with_vtable(ConstClass(node_vtable))
+setfield_gc(p2, p1, descr=nextdescr)
+setfield_gc(p2, 42, descr=adescr)
+setfield_gc(p2, 7, descr=bdescr)
+jump(p2, p1)
+
+self.optimize_bridge(loops, bridge, RETRACE)
+bridge = 
+[p0, p1]
+p2 = new_with_vtable(ConstClass(node_vtable))
+setfield_gc(p2, p1, descr=nextdescr)
+setfield_gc(p2, 7, descr=adescr)
+jump(p2, p1)
+
+self.optimize_bridge(loops, bridge, RETRACE)
+
 class TestLLtypeGuards(BaseTestGenerateGuards, LLtypeMixin):
 pass
 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy unroll-if-alt: Use the decorators here.

2011-08-03 Thread alex_gaynor
Author: Alex Gaynor alex.gay...@gmail.com
Branch: unroll-if-alt
Changeset: r46256:cc4d128b64be
Date: 2011-08-03 12:54 -0700
http://bitbucket.org/pypy/pypy/changeset/cc4d128b64be/

Log:Use the decorators here.

diff --git a/pypy/objspace/std/bytearrayobject.py 
b/pypy/objspace/std/bytearrayobject.py
--- a/pypy/objspace/std/bytearrayobject.py
+++ b/pypy/objspace/std/bytearrayobject.py
@@ -250,7 +250,8 @@
 def repr__Bytearray(space, w_bytearray):
 s = w_bytearray.data
 
-buf = StringBuilder(50)
+# Good default if there are no replacements.
+buf = StringBuilder(len(bytearray(b'')) + len(s))
 
 buf.append(bytearray(b')
 
diff --git a/pypy/rlib/rgc.py b/pypy/rlib/rgc.py
--- a/pypy/rlib/rgc.py
+++ b/pypy/rlib/rgc.py
@@ -1,6 +1,9 @@
-import gc, types
+import gc
+import types
+
+from pypy.rlib import jit
+from pypy.rlib.objectmodel import we_are_translated, enforceargs, specialize
 from pypy.rpython.extregistry import ExtRegistryEntry
-from pypy.rlib.objectmodel import we_are_translated
 from pypy.rpython.lltypesystem import lltype, llmemory
 
 # 
@@ -74,7 +77,7 @@
 # when the gc policy doesn't support pools, just return
 # the argument (which is lltyped as Void anyway)
 opname = 'same_as'
-
+
 s_pool_ptr = annmodel.SomeExternalObject(GcPool)
 r_pool_ptr = hop.rtyper.getrepr(s_pool_ptr)
 vlist = hop.inputargs(r_pool_ptr)
@@ -156,7 +159,7 @@
 if len(hop.args_s) == 1:
 args_v = hop.inputargs(lltype.Signed)
 return hop.genop('gc__collect', args_v, resulttype=hop.r_result)
-
+
 class SetMaxHeapSizeEntry(ExtRegistryEntry):
 _about_ = set_max_heap_size
 
@@ -257,6 +260,9 @@
 hop.exception_cannot_occur()
 return hop.genop(opname, vlist, resulttype = hop.r_result.lowleveltype)
 
+@jit.oopspec('list.ll_arraycopy(source, dest, source_start, dest_start, 
length)')
+@specialize.ll()
+@enforceargs(None, None, int, int, int)
 def ll_arraycopy(source, dest, source_start, dest_start, length):
 from pypy.rpython.lltypesystem.lloperation import llop
 from pypy.rlib.objectmodel import keepalive_until_here
@@ -285,14 +291,11 @@
   llmemory.sizeof(TP.OF) * source_start)
 cp_dest_addr = (dest_addr + llmemory.itemoffsetof(TP, 0) +
 llmemory.sizeof(TP.OF) * dest_start)
-
+
 llmemory.raw_memcopy(cp_source_addr, cp_dest_addr,
  llmemory.sizeof(TP.OF) * length)
 keepalive_until_here(source)
 keepalive_until_here(dest)
-ll_arraycopy._annenforceargs_ = [None, None, int, int, int]
-ll_arraycopy._annspecialcase_ = 'specialize:ll'
-ll_arraycopy.oopspec = 'list.ll_arraycopy(source, dest, source_start, 
dest_start, length)'
 
 def ll_shrink_array(p, smallerlength):
 from pypy.rpython.lltypesystem.lloperation import llop
@@ -316,7 +319,7 @@
   llmemory.itemoffsetof(ARRAY, 0))
 source_addr = llmemory.cast_ptr_to_adr(p)+ offset
 dest_addr   = llmemory.cast_ptr_to_adr(newp) + offset
-llmemory.raw_memcopy(source_addr, dest_addr, 
+llmemory.raw_memcopy(source_addr, dest_addr,
  llmemory.sizeof(ARRAY.OF) * smallerlength)
 
 keepalive_until_here(p)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jit-short_from_state: test that cached getfields are properly guarded at end of bridge

2011-08-03 Thread hakanardo
Author: Hakan Ardo ha...@debian.org
Branch: jit-short_from_state
Changeset: r46257:e3e2080387af
Date: 2011-08-03 22:12 +0200
http://bitbucket.org/pypy/pypy/changeset/e3e2080387af/

Log:test that cached getfields are properly guarded at end of bridge

diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py 
b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py
--- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py
+++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py
@@ -61,7 +61,7 @@
 boxes = []
 boxes = []
 def clone_if_mutable(self):
-return self
+return FakeDescr()
 def __eq__(self, other):
 return isinstance(other, Storage) or isinstance(other, FakeDescr)
 
diff --git a/pypy/jit/metainterp/test/test_virtualstate.py 
b/pypy/jit/metainterp/test/test_virtualstate.py
--- a/pypy/jit/metainterp/test/test_virtualstate.py
+++ b/pypy/jit/metainterp/test/test_virtualstate.py
@@ -272,6 +272,64 @@
 
 self.optimize_bridge(loop, bridge, 'RETRACE', p0=self.nullptr)
 self.optimize_bridge(loop, bridge, expected, p0=self.myptr)
+self.optimize_bridge(loop, expected, expected, p0=self.myptr)
+self.optimize_bridge(loop, expected, expected, p0=self.nullptr)
+
+def test_cached_nonnull(self):
+loop = 
+[p0]
+p1 = getfield_gc(p0, descr=nextdescr)
+guard_nonnull(p1) []
+call(p1, descr=nonwritedescr)
+jump(p0)
+
+bridge = 
+[p0]
+jump(p0)
+
+expected = 
+[p0]
+guard_nonnull(p0) []
+p1 = getfield_gc(p0, descr=nextdescr)
+guard_nonnull(p1) []
+jump(p0, p1)
+
+self.optimize_bridge(loop, bridge, expected, p0=self.myptr)
+
+def test_cached_unused_nonnull(self):
+loop = 
+[p0]
+p1 = getfield_gc(p0, descr=nextdescr)
+guard_nonnull(p1) []
+jump(p0)
+
+bridge = 
+[p0]
+jump(p0)
+
+expected = 
+[p0]
+guard_nonnull(p0) []
+p1 = getfield_gc(p0, descr=nextdescr)
+guard_nonnull(p1) []
+jump(p0)
+
+self.optimize_bridge(loop, bridge, expected, p0=self.myptr)
+
+def test_cached_invalid_nonnull(self):
+loop = 
+[p0]
+p1 = getfield_gc(p0, descr=nextdescr)
+guard_nonnull(p1) []
+jump(p0)
+
+bridge = 
+[p0]
+p1 = getfield_gc(p0, descr=nextdescr)
+guard_value(p1, ConstPtr(nullptr)) []
+jump(p0)
+
+self.optimize_bridge(loop, bridge, bridge, 'Preamble', p0=self.myptr)
 
 def test_multiple_nonnull(self):
 loops = 
@@ -323,6 +381,26 @@
 
 self.optimize_bridge(loops, loops[2], expected, 'Loop2')
 
+def test_cached_constant(self):
+loop = 
+[p0]
+p1 = getfield_gc(p0, descr=nextdescr)
+guard_value(p1, ConstPtr(myptr)) []
+jump(p0)
+
+bridge = 
+[p0]
+jump(p0)
+
+expected = 
+[p0]
+guard_nonnull(p0) []
+p1 = getfield_gc(p0, descr=nextdescr)
+guard_value(p1, ConstPtr(myptr)) []   
+jump(p0)
+
+self.optimize_bridge(loop, bridge, expected, p0=self.myptr)
+
 def test_virtual(self):
 loops = 
 [p0, p1]
@@ -382,6 +460,27 @@
 self.optimize_bridge(loops, loops[0], loops[0], 'Loop0', 
p0=self.nullptr)
 self.optimize_bridge(loops, loops[1], loops[1], 'Loop1', 
p0=self.nullptr)
 
+def test_cached_known_class(self):
+loop = 
+[p0]
+p1 = getfield_gc(p0, descr=nextdescr)
+guard_class(p1, ConstClass(node_vtable)) []
+jump(p0)
+
+bridge = 
+[p0]
+jump(p0)
+
+expected = 
+[p0]
+guard_nonnull(p0) []
+p1 = getfield_gc(p0, descr=nextdescr)
+guard_nonnull_class(p1, ConstClass(node_vtable)) []
+jump(p0)
+
+self.optimize_bridge(loop, bridge, expected, p0=self.myptr)
+
+
 def test_lenbound_array(self):
 loop = 
 [p0]
@@ -420,6 +519,72 @@
 
 self.optimize_bridge(loop, bridge, 'RETRACE')
 
+def test_cached_lenbound_array(self):
+loop = 
+[p0]
+p1 = getfield_gc(p0, descr=nextdescr)
+i2 = getarrayitem_gc(p1, 10, descr=arraydescr)
+call(i2, descr=nonwritedescr)
+jump(p0)
+
+expected = 
+[p0]
+p1 = getfield_gc(p0, descr=nextdescr)
+i2 = getarrayitem_gc(p1, 10, descr=arraydescr)
+call(i2, descr=nonwritedescr)
+i3 = arraylen_gc(p1, descr=arraydescr) # Should be killed by backend
+jump(p0, i2)
+
+self.optimize_bridge(loop, loop, expected)
+bridge = 
+[p0]
+p1 = 

[pypy-commit] pypy default: Put bounds on the result of an int_mod.

2011-08-03 Thread alex_gaynor
Author: Alex Gaynor alex.gay...@gmail.com
Branch: 
Changeset: r46259:1ff61f9d4428
Date: 2011-08-03 16:49 -0700
http://bitbucket.org/pypy/pypy/changeset/1ff61f9d4428/

Log:Put bounds on the result of an int_mod.

diff --git a/pypy/jit/metainterp/optimizeopt/intbounds.py 
b/pypy/jit/metainterp/optimizeopt/intbounds.py
--- a/pypy/jit/metainterp/optimizeopt/intbounds.py
+++ b/pypy/jit/metainterp/optimizeopt/intbounds.py
@@ -125,6 +125,21 @@
 r = self.getvalue(op.result)
 r.intbound.intersect(v1.intbound.div_bound(v2.intbound))
 
+def optimize_INT_MOD(self, op):
+self.emit_operation(op)
+v2 = self.getvalue(op.getarg(1))
+if v2.is_constant():
+val = v2.box.getint()
+r = self.getvalue(op.result)
+if val  0:
+r.intbound.make_ge(IntBound(0, 0))
+r.intbound.make_lt(IntBound(val, val))
+elif val  0:
+r.intbound.make_gt(IntBound(val, val))
+r.intbound.make_le(IntBound(0, 0))
+# No optimizations if val == 0, that should probably even be an
+# error, that should never happen.
+
 def optimize_INT_LSHIFT(self, op):
 v1 = self.getvalue(op.getarg(0))
 v2 = self.getvalue(op.getarg(1))
diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py 
b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
--- a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
+++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
@@ -4621,6 +4621,29 @@
 
 self.optimize_strunicode_loop(ops, expected)
 
+def test_intmod_bounds(self):
+ops = 
+[i0, i1]
+i2 = int_mod(i0, 12)
+i3 = int_gt(i2, 12)
+guard_false(i3) []
+i4 = int_lt(i2, 0)
+guard_false(i4) []
+i5 = int_mod(i1, -12)
+i6 = int_lt(i5, -12)
+guard_false(i6) []
+i7 = int_gt(i5, 0)
+guard_false(i7) []
+jump(i2, i5)
+
+expected = 
+[i0, i1]
+i2 = int_mod(i0, 12)
+i5 = int_mod(i1, -12)
+jump(i2, i5)
+
+self.optimize_loop(ops, expected)
+
 
 class TestLLtype(BaseTestOptimizeBasic, LLtypeMixin):
 pass
diff --git a/pypy/jit/tool/oparser.py b/pypy/jit/tool/oparser.py
--- a/pypy/jit/tool/oparser.py
+++ b/pypy/jit/tool/oparser.py
@@ -53,7 +53,7 @@
 class OpParser(object):
 
 use_mock_model = False
-
+
 def __init__(self, input, cpu, namespace, type_system, boxkinds,
  invent_fail_descr=default_fail_descr,
  nonstrict=False):
@@ -187,7 +187,7 @@
 poss_descr = allargs[-1].strip()
 if poss_descr.startswith('descr='):
 descr = self.get_descr(poss_descr[len('descr='):])
-allargs = allargs[:-1]
+allargs = allargs[:-1]
 for arg in allargs:
 arg = arg.strip()
 try:
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: a commented out, failing, optimizeopt test. it fails because of how bounds are propogated. it is known that the result of the rshift is precisely bounded at 0, however it i

2011-08-03 Thread alex_gaynor
Author: Alex Gaynor alex.gay...@gmail.com
Branch: 
Changeset: r46260:22863ec20f46
Date: 2011-08-03 17:00 -0700
http://bitbucket.org/pypy/pypy/changeset/22863ec20f46/

Log:a commented out, failing, optimizeopt test. it fails because of how
bounds are propogated. it is known that the result of the rshift is
precisely bounded at 0, however it isn't actually a constant.

diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py 
b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
--- a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
+++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
@@ -4644,6 +4644,24 @@
 
 self.optimize_loop(ops, expected)
 
+# This the sequence of resoperations that is generated for a Python
+# app-level int % int, when the modulus is constant it should be
+# optimized to a single CPU instruction.
+# ops = 
+# [i0]
+# i1 = int_mod(i0, 2)
+# i2 = int_rshift(i1, 63)
+# i3 = int_and(2, i2)
+# i4 = int_add(i1, i3)
+# finish(i4)
+# 
+# expected = 
+# [i0]
+# i1 = int_mod(i0, 2)
+# finish(i1)
+# 
+# self.optimize_loop(ops, expected)
+
 
 class TestLLtype(BaseTestOptimizeBasic, LLtypeMixin):
 pass
diff --git a/pypy/jit/tool/oparser.py b/pypy/jit/tool/oparser.py
--- a/pypy/jit/tool/oparser.py
+++ b/pypy/jit/tool/oparser.py
@@ -240,7 +240,7 @@
 fail_args = None
 if opnum == rop.FINISH:
 if descr is None and self.invent_fail_descr:
-descr = self.invent_fail_descr(self.model)
+descr = self.invent_fail_descr(self.model, fail_args)
 elif opnum == rop.JUMP:
 if descr is None and self.invent_fail_descr:
 descr = self.looptoken
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] jitviewer default: Renamed log to log.pypylog, this is the extension I made up for pygments.

2011-08-03 Thread alex_gaynor
Author: Alex Gaynor alex.gay...@gmail.com
Branch: 
Changeset: r169:1be09fe09e54
Date: 2011-08-03 17:03 -0700
http://bitbucket.org/pypy/jitviewer/changeset/1be09fe09e54/

Log:Renamed log to log.pypylog, this is the extension I made up for
pygments.

diff --git a/log b/log.pypylog
rename from log
rename to log.pypylog
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] jitviewer default: consistantly use the exntesion

2011-08-03 Thread alex_gaynor
Author: Alex Gaynor alex.gay...@gmail.com
Branch: 
Changeset: r170:3b9994e2c9b0
Date: 2011-08-03 17:07 -0700
http://bitbucket.org/pypy/jitviewer/changeset/3b9994e2c9b0/

Log:consistantly use the exntesion

diff --git a/README b/README
--- a/README
+++ b/README
@@ -17,8 +17,8 @@
 
 Finally, run it:
 
-jitviewer.py log
+jitviewer.py log.pypylog
 
-where log is a logfile generated by
-PYPYLOG=jit-log-opt,jit-backend:log pypy args.
+where log.pypylog is a logfile generated by
+PYPYLOG=jit-log-opt,jit-backend:log.pypylog pypy args.
 An example log file comes with a checkout.
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit