Author: Maciej Fijalkowski <fij...@gmail.com> Branch: fileops2 Changeset: r67183:44224be36e53 Date: 2013-10-07 17:18 +0200 http://bitbucket.org/pypy/pypy/changeset/44224be36e53/
Log: merge default diff --git a/pypy/TODO b/pypy/TODO deleted file mode 100644 --- a/pypy/TODO +++ /dev/null @@ -1,2 +0,0 @@ - -* ARM diff --git a/pypy/module/cpyext/ndarrayobject.py b/pypy/module/cpyext/ndarrayobject.py --- a/pypy/module/cpyext/ndarrayobject.py +++ b/pypy/module/cpyext/ndarrayobject.py @@ -149,14 +149,17 @@ only used if the array is constructed that way. Almost always this parameter is NULL. """ - if min_depth !=0 or max_depth != 0: - raise OperationError(space.w_NotImplementedError, space.wrap( - '_PyArray_FromAny called with not-implemented min_dpeth or max_depth argument')) if requirements not in (0, NPY_DEFAULT): raise OperationError(space.w_NotImplementedError, space.wrap( '_PyArray_FromAny called with not-implemented requirements argument')) w_array = array(space, w_obj, w_dtype=w_dtype, copy=False) - if w_array.is_scalar(): + if min_depth !=0 and len(w_array.get_shape()) < min_depth: + raise OperationError(space.w_ValueError, space.wrap( + 'object of too small depth for desired array')) + elif max_depth !=0 and len(w_array.get_shape()) > max_depth: + raise OperationError(space.w_ValueError, space.wrap( + 'object of too deep for desired array')) + elif w_array.is_scalar(): # since PyArray_DATA() fails on scalars, create a 1D array and set empty # shape. So the following combination works for *reading* scalars: # PyObject *arr = PyArray_FromAny(obj); diff --git a/pypy/module/cpyext/test/test_ndarrayobject.py b/pypy/module/cpyext/test/test_ndarrayobject.py --- a/pypy/module/cpyext/test/test_ndarrayobject.py +++ b/pypy/module/cpyext/test/test_ndarrayobject.py @@ -90,15 +90,16 @@ def test_FromAny(self, space, api): a = array(space, [10, 5, 3]) assert api._PyArray_FromAny(a, NULL, 0, 0, 0, NULL) is a - self.raises(space, api, NotImplementedError, api._PyArray_FromAny, - a, NULL, 0, 3, 0, NULL) + assert api._PyArray_FromAny(a, NULL, 1, 4, 0, NULL) is a + self.raises(space, api, ValueError, api._PyArray_FromAny, + a, NULL, 4, 5, 0, NULL) def test_FromObject(self, space, api): a = array(space, [10, 5, 3]) assert api._PyArray_FromObject(a, a.get_dtype().num, 0, 0) is a - exc = self.raises(space, api, NotImplementedError, api._PyArray_FromObject, - a, 11, 0, 3) - assert exc.errorstr(space).find('FromObject') >= 0 + exc = self.raises(space, api, ValueError, api._PyArray_FromObject, + a, 11, 4, 5) + assert exc.errorstr(space).find('desired') >= 0 def test_list_from_fixedptr(self, space, api): A = lltype.GcArray(lltype.Float) diff --git a/pypy/module/pypyjit/test_pypy_c/test_ffi.py b/pypy/module/pypyjit/test_pypy_c/test_ffi.py --- a/pypy/module/pypyjit/test_pypy_c/test_ffi.py +++ b/pypy/module/pypyjit/test_pypy_c/test_ffi.py @@ -277,3 +277,28 @@ f1 = call_release_gil(..., descr=<Calli 4 ii EF=6 OS=62>) ... """) + + def test__cffi_bug1(self): + from rpython.rlib.test.test_clibffi import get_libm_name + def main(libm_name): + try: + import _cffi_backend + except ImportError: + sys.stderr.write('SKIP: cannot import _cffi_backend\n') + return 0 + + libm = _cffi_backend.load_library(libm_name) + BDouble = _cffi_backend.new_primitive_type("double") + BSin = _cffi_backend.new_function_type([BDouble], BDouble) + sin = libm.load_function(BSin, 'sin') + + def f(*args): + for i in range(300): + sin(*args) + + f(1.0) + f(1) + # + libm_name = get_libm_name(sys.platform) + log = self.run(main, [libm_name]) + # assert did not crash diff --git a/pypy/objspace/std/floatobject.py b/pypy/objspace/std/floatobject.py --- a/pypy/objspace/std/floatobject.py +++ b/pypy/objspace/std/floatobject.py @@ -424,21 +424,24 @@ x = w_float1.floatval y = w_float2.floatval + return W_FloatObject(_pow(space, x, y)) + +def _pow(space, x, y): # Sort out special cases here instead of relying on pow() - if y == 2.0: # special case for performance: - return W_FloatObject(x * x) # x * x is always correct + if y == 2.0: # special case for performance: + return x * x # x * x is always correct if y == 0.0: # x**0 is 1, even 0**0 - return W_FloatObject(1.0) + return 1.0 if isnan(x): # nan**y = nan, unless y == 0 - return W_FloatObject(x) + return x if isnan(y): # x**nan = nan, unless x == 1; x**nan = x if x == 1.0: - return W_FloatObject(1.0) + return 1.0 else: - return W_FloatObject(y) + return y if isinf(y): # x**inf is: 0.0 if abs(x) < 1; 1.0 if abs(x) == 1; inf if # abs(x) > 1 (including case where x infinite) @@ -447,11 +450,11 @@ # abs(x) > 1 (including case where v infinite) x = abs(x) if x == 1.0: - return W_FloatObject(1.0) + return 1.0 elif (y > 0.0) == (x > 1.0): - return W_FloatObject(INFINITY) + return INFINITY else: - return W_FloatObject(0.0) + return 0.0 if isinf(x): # (+-inf)**w is: inf for w positive, 0 for w negative; in oth # cases, we need to add the appropriate sign if w is an odd @@ -459,14 +462,14 @@ y_is_odd = math.fmod(abs(y), 2.0) == 1.0 if y > 0.0: if y_is_odd: - return W_FloatObject(x) + return x else: - return W_FloatObject(abs(x)) + return abs(x) else: if y_is_odd: - return W_FloatObject(copysign(0.0, x)) + return copysign(0.0, x) else: - return W_FloatObject(0.0) + return 0.0 if x == 0.0: if y < 0.0: @@ -480,7 +483,7 @@ # - pipermail/python-bugs-list/2003-March/016795.html if x < 0.0: if isnan(y): - return W_FloatObject(NAN) + return NAN if math.floor(y) != y: raise OperationError(space.w_ValueError, space.wrap("negative number cannot be " @@ -494,9 +497,9 @@ if x == 1.0: # (-1) ** large_integer also ends up here if negate_result: - return W_FloatObject(-1.0) + return -1.0 else: - return W_FloatObject(1.0) + return 1.0 try: # We delegate to our implementation of math.pow() the error detection. @@ -510,7 +513,7 @@ if negate_result: z = -z - return W_FloatObject(z) + return z def neg__Float(space, w_float1): diff --git a/rpython/jit/backend/llgraph/runner.py b/rpython/jit/backend/llgraph/runner.py --- a/rpython/jit/backend/llgraph/runner.py +++ b/rpython/jit/backend/llgraph/runner.py @@ -381,6 +381,8 @@ res = self.llinterp.eval_graph(ptr._obj.graph, args) else: res = ptr._obj._callable(*args) + if RESULT is lltype.Void: + return None return support.cast_result(RESULT, res) def _do_call(self, func, args_i, args_r, args_f, calldescr): diff --git a/rpython/jit/metainterp/optimizeopt/virtualize.py b/rpython/jit/metainterp/optimizeopt/virtualize.py --- a/rpython/jit/metainterp/optimizeopt/virtualize.py +++ b/rpython/jit/metainterp/optimizeopt/virtualize.py @@ -45,6 +45,15 @@ return value return OptValue(self.force_box(optforce)) + def get_args_for_fail(self, modifier): + # checks for recursion: it is False unless + # we have already seen the very same keybox + if self.box is None and not modifier.already_seen_virtual(self.keybox): + self._get_args_for_fail(modifier) + + def _get_args_for_fail(self, modifier): + raise NotImplementedError("abstract base") + def make_virtual_info(self, modifier, fieldnums): if fieldnums is None: return self._make_virtual(modifier) @@ -193,16 +202,13 @@ self._cached_sorted_fields = lst return lst - def get_args_for_fail(self, modifier): - if self.box is None and not modifier.already_seen_virtual(self.keybox): - # checks for recursion: it is False unless - # we have already seen the very same keybox - lst = self._get_field_descr_list() - fieldboxes = [self._fields[ofs].get_key_box() for ofs in lst] - modifier.register_virtual_fields(self.keybox, fieldboxes) - for ofs in lst: - fieldvalue = self._fields[ofs] - fieldvalue.get_args_for_fail(modifier) + def _get_args_for_fail(self, modifier): + lst = self._get_field_descr_list() + fieldboxes = [self._fields[ofs].get_key_box() for ofs in lst] + modifier.register_virtual_fields(self.keybox, fieldboxes) + for ofs in lst: + fieldvalue = self._fields[ofs] + fieldvalue.get_args_for_fail(modifier) class VirtualValue(AbstractVirtualStructValue): level = optimizer.LEVEL_KNOWNCLASS @@ -254,18 +260,15 @@ def set_item_value(self, i, newval): raise NotImplementedError - def get_args_for_fail(self, modifier): - if self.box is None and not modifier.already_seen_virtual(self.keybox): - # checks for recursion: it is False unless - # we have already seen the very same keybox - itemboxes = [] - for i in range(self.getlength()): - itemvalue = self.get_item_value(i) - itemboxes.append(itemvalue.get_key_box()) - modifier.register_virtual_fields(self.keybox, itemboxes) - for i in range(self.getlength()): - itemvalue = self.get_item_value(i) - itemvalue.get_args_for_fail(modifier) + def _get_args_for_fail(self, modifier): + itemboxes = [] + for i in range(self.getlength()): + itemvalue = self.get_item_value(i) + itemboxes.append(itemvalue.get_key_box()) + modifier.register_virtual_fields(self.keybox, itemboxes) + for i in range(self.getlength()): + itemvalue = self.get_item_value(i) + itemvalue.get_args_for_fail(modifier) class VArrayValue(AbstractVArrayValue): @@ -370,17 +373,16 @@ descrs.append(item_descrs) return descrs - def get_args_for_fail(self, modifier): - if self.box is None and not modifier.already_seen_virtual(self.keybox): - itemdescrs = self._get_list_of_descrs() - itemboxes = [] - for i in range(len(self._items)): - for descr in itemdescrs[i]: - itemboxes.append(self._items[i][descr].get_key_box()) - modifier.register_virtual_fields(self.keybox, itemboxes) - for i in range(len(self._items)): - for descr in itemdescrs[i]: - self._items[i][descr].get_args_for_fail(modifier) + def _get_args_for_fail(self, modifier): + itemdescrs = self._get_list_of_descrs() + itemboxes = [] + for i in range(len(self._items)): + for descr in itemdescrs[i]: + itemboxes.append(self._items[i][descr].get_key_box()) + modifier.register_virtual_fields(self.keybox, itemboxes) + for i in range(len(self._items)): + for descr in itemdescrs[i]: + self._items[i][descr].get_args_for_fail(modifier) def force_at_end_of_preamble(self, already_forced, optforce): if self in already_forced: @@ -481,6 +483,15 @@ def getitem_raw(self, offset, length, descr): return self.rawbuffer_value.getitem_raw(self.offset+offset, length, descr) + def _get_args_for_fail(self, modifier): + box = self.rawbuffer_value.get_key_box() + modifier.register_virtual_fields(self.keybox, [box]) + self.rawbuffer_value.get_args_for_fail(modifier) + + def _make_virtual(self, modifier): + return modifier.make_vrawslice(self.offset) + + class OptVirtualize(optimizer.Optimization): "Virtualize objects until they escape." diff --git a/rpython/jit/metainterp/resume.py b/rpython/jit/metainterp/resume.py --- a/rpython/jit/metainterp/resume.py +++ b/rpython/jit/metainterp/resume.py @@ -284,7 +284,10 @@ return VArrayStructInfo(arraydescr, fielddescrs) def make_vrawbuffer(self, size, offsets, descrs): - return VRawBufferStateInfo(size, offsets, descrs) + return VRawBufferInfo(size, offsets, descrs) + + def make_vrawslice(self, offset): + return VRawSliceInfo(offset) def make_vstrplain(self, is_unicode=False): if is_unicode: @@ -554,10 +557,13 @@ debug_print("\t\t", str(untag(i))) -class VRawBufferStateInfo(AbstractVirtualInfo): +class VAbstractRawInfo(AbstractVirtualInfo): kind = INT is_about_raw = True + +class VRawBufferInfo(VAbstractRawInfo): + def __init__(self, size, offsets, descrs): self.size = size self.offsets = offsets @@ -580,6 +586,25 @@ debug_print("\t\t", str(untag(i))) +class VRawSliceInfo(VAbstractRawInfo): + + def __init__(self, offset): + self.offset = offset + + @specialize.argtype(1) + def allocate_int(self, decoder, index): + assert len(self.fieldnums) == 1 + base_buffer = decoder.decode_int(self.fieldnums[0]) + buffer = decoder.int_add_const(base_buffer, self.offset) + decoder.virtuals_cache.set_int(index, buffer) + return buffer + + def debug_prints(self): + debug_print("\tvrawsliceinfo", " at ", compute_unique_id(self)) + for i in self.fieldnums: + debug_print("\t\t", str(untag(i))) + + class VArrayStructInfo(AbstractVirtualInfo): def __init__(self, arraydescr, fielddescrs): self.arraydescr = arraydescr @@ -783,7 +808,8 @@ v = self.virtuals_cache.get_int(index) if not v: v = self.rd_virtuals[index] - assert v.is_about_raw and isinstance(v, VRawBufferStateInfo) + ll_assert(bool(v), "resume.py: null rd_virtuals[index]") + assert v.is_about_raw and isinstance(v, VAbstractRawInfo) v = v.allocate_int(self, index) ll_assert(v == self.virtuals_cache.get_int(index), "resume.py: bad cache") return v @@ -1116,6 +1142,10 @@ def write_a_float(self, index, box): self.boxes_f[index] = box + def int_add_const(self, intbox, offset): + return self.metainterp.execute_and_record(rop.INT_ADD, None, intbox, + ConstInt(offset)) + # ---------- when resuming for blackholing, get direct values ---------- def blackhole_from_resumedata(blackholeinterpbuilder, jitdriver_sd, storage, @@ -1407,6 +1437,9 @@ def write_a_float(self, index, float): self.blackholeinterp.setarg_f(index, float) + def int_add_const(self, base, offset): + return base + offset + # ____________________________________________________________ def dump_storage(storage, liveboxes): diff --git a/rpython/jit/metainterp/test/test_fficall.py b/rpython/jit/metainterp/test/test_fficall.py --- a/rpython/jit/metainterp/test/test_fficall.py +++ b/rpython/jit/metainterp/test/test_fficall.py @@ -86,15 +86,17 @@ data = rffi.ptradd(exchange_buffer, ofs) rffi.cast(lltype.Ptr(TYPE), data)[0] = write_rvalue - def f(): + def f(i): exbuf = lltype.malloc(rffi.CCHARP.TO, (len(avalues)+2) * 16, - flavor='raw', zero=True) - ofs = 16 + flavor='raw') + + targetptr = rffi.ptradd(exbuf, 16) for avalue in unroll_avalues: TYPE = rffi.CArray(lltype.typeOf(avalue)) - data = rffi.ptradd(exbuf, ofs) - rffi.cast(lltype.Ptr(TYPE), data)[0] = avalue - ofs += 16 + if i >= 9: # a guard that can fail + pass + rffi.cast(lltype.Ptr(TYPE), targetptr)[0] = avalue + targetptr = rffi.ptradd(targetptr, 16) jit_ffi_call(cif_description, func_addr, exbuf) @@ -102,8 +104,7 @@ res = 654321 else: TYPE = rffi.CArray(lltype.typeOf(rvalue)) - data = rffi.ptradd(exbuf, ofs) - res = rffi.cast(lltype.Ptr(TYPE), data)[0] + res = rffi.cast(lltype.Ptr(TYPE), targetptr)[0] lltype.free(exbuf, flavor='raw') if lltype.typeOf(res) is lltype.SingleFloat: res = float(res) @@ -117,9 +118,9 @@ return res == rvalue with FakeFFI(fake_call_impl_any): - res = f() + res = f(-42) assert matching_result(res, rvalue) - res = self.interp_operations(f, [], + res = self.interp_operations(f, [-42], supports_floats = supports_floats, supports_longlong = supports_longlong, supports_singlefloats = supports_singlefloats) @@ -132,6 +133,19 @@ self.check_operations_history(call_may_force=0, call_release_gil=expected_call_release_gil) + ################################################## + driver = jit.JitDriver(reds=['i'], greens=[]) + def main(): + i = 0 + while 1: + driver.jit_merge_point(i=i) + res = f(i) + i += 1 + if i == 12: + return res + self.meta_interp(main, []) + + def test_simple_call_int(self): self._run([types.signed] * 2, types.signed, [456, 789], -42) diff --git a/rpython/memory/support.py b/rpython/memory/support.py --- a/rpython/memory/support.py +++ b/rpython/memory/support.py @@ -121,13 +121,15 @@ cur = next free_non_gc_object(self) - def _length_estimate(self): + def length(self): chunk = self.chunk + result = 0 count = self.used_in_last_chunk while chunk: + result += count chunk = chunk.next - count += chunk_size - return count + count = chunk_size + return result def foreach(self, callback, arg): """Invoke 'callback(address, arg)' for all addresses in the stack. @@ -144,7 +146,7 @@ foreach._annspecialcase_ = 'specialize:arg(1)' def stack2dict(self): - result = AddressDict(self._length_estimate()) + result = AddressDict(self.length()) self.foreach(_add_in_dict, result) return result diff --git a/rpython/memory/test/test_support.py b/rpython/memory/test/test_support.py --- a/rpython/memory/test/test_support.py +++ b/rpython/memory/test/test_support.py @@ -94,6 +94,18 @@ assert a == addrs[i] assert not ll.non_empty() + def test_length(self): + AddressStack = get_address_stack(10) + ll = AddressStack() + a = raw_malloc(llmemory.sizeof(lltype.Signed)) + for i in range(42): + assert ll.length() == i + ll.append(a) + for i in range(42-1, -1, -1): + b = ll.pop() + assert b == a + assert ll.length() == i + class TestAddressDeque: def test_big_access(self): diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py --- a/rpython/rlib/rbigint.py +++ b/rpython/rlib/rbigint.py @@ -731,10 +731,16 @@ if c.numdigits() == 1 and c._digits[0] == ONEDIGIT: return NULLRBIGINT - # if base < 0: - # base = base % modulus - # Having the base positive just makes things easier. - if a.sign < 0: + # Reduce base by modulus in some cases: + # 1. If base < 0. Forcing the base non-neg makes things easier. + # 2. If base is obviously larger than the modulus. The "small + # exponent" case later can multiply directly by base repeatedly, + # while the "large exponent" case multiplies directly by base 31 + # times. It can be unboundedly faster to multiply by + # base % modulus instead. + # We could _always_ do this reduction, but mod() isn't cheap, + # so we only do it when it buys something. + if a.sign < 0 or a.numdigits() > c.numdigits(): a = a.mod(c) elif b.sign == 0: diff --git a/rpython/rlib/rpath.py b/rpython/rlib/rpath.py --- a/rpython/rlib/rpath.py +++ b/rpython/rlib/rpath.py @@ -23,3 +23,41 @@ return path else: raise ImportError('Unsupported os: %s' % os.name) + + +def dirname(p): + """Returns the directory component of a pathname""" + i = p.rfind('/') + 1 + assert i >= 0 + head = p[:i] + if head and head != '/' * len(head): + head = head.rstrip('/') + return head + + +def basename(p): + """Returns the final component of a pathname""" + i = p.rfind('/') + 1 + assert i >= 0 + return p[i:] + + +def split(p): + """Split a pathname. Returns tuple "(head, tail)" where "tail" is + everything after the final slash. Either part may be empty.""" + i = p.rfind('/') + 1 + assert i >= 0 + head, tail = p[:i], p[i:] + if head and head != '/' * len(head): + head = head.rstrip('/') + return head, tail + + +def exists(path): + """Test whether a path exists. Returns False for broken symbolic links""" + try: + assert path is not None + os.stat(path) + except os.error: + return False + return True diff --git a/rpython/rlib/test/test_rstacklet.py b/rpython/rlib/test/test_rstacklet.py --- a/rpython/rlib/test/test_rstacklet.py +++ b/rpython/rlib/test/test_rstacklet.py @@ -1,5 +1,6 @@ import gc, sys import py +import platform from rpython.rtyper.tool.rffi_platform import CompilationError try: from rpython.rlib import rstacklet @@ -332,6 +333,10 @@ gc = 'minimark' gcrootfinder = 'asmgcc' + @py.test.mark.skipif("sys.platform != 'linux2' or platform.machine().startswith('arm')") + def test_demo1(self): + BaseTestStacklet.test_demo1(self) + class TestStackletShadowStack(BaseTestStacklet): gc = 'minimark' gcrootfinder = 'shadowstack' diff --git a/rpython/translator/c/src/stacklet/switch_arm_gcc.h b/rpython/translator/c/src/stacklet/switch_arm_gcc.h --- a/rpython/translator/c/src/stacklet/switch_arm_gcc.h +++ b/rpython/translator/c/src/stacklet/switch_arm_gcc.h @@ -1,3 +1,10 @@ +#if __ARM_ARCH__ >= 5 +# define call_reg(x) "blx " #x "\n" +#elif defined (__ARM_ARCH_4T__) +# define call_reg(x) "mov lr, pc ; bx " #x "\n" +#else +# define call_reg(x) "mov lr, pc ; mov pc, " #x "\n" +#endif static void __attribute__((optimize("O3"))) *slp_switch(void *(*save_state)(void*, void*), void *(*restore_state)(void*, void*), @@ -11,7 +18,7 @@ "mov r5, %[extra]\n" "mov r0, sp\n" /* arg 1: current (old) stack pointer */ "mov r1, r5\n" /* arg 2: extra */ - "blx r3\n" /* call save_state() */ + call_reg(r3) /* call save_state() */ /* skip the rest if the return value is null */ "cmp r0, #0\n" @@ -23,7 +30,7 @@ stack is not restored yet. It contains only garbage here. */ "mov r1, r5\n" /* arg 2: extra */ /* arg 1: current (new) stack pointer is already in r0*/ - "blx r4\n" /* call restore_state() */ + call_reg(r4) /* call restore_state() */ /* The stack's content is now restored. */ "zero:\n" _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit