[pypy-commit] pypy default: Merged in exctrans (pull request #390)
Author: Ronan Lamy Branch: Changeset: r81955:467f4a616ad1 Date: 2016-01-26 20:39 + http://bitbucket.org/pypy/pypy/changeset/467f4a616ad1/ Log:Merged in exctrans (pull request #390) Some refactoring of databasing diff --git a/rpython/memory/gctransform/boehm.py b/rpython/memory/gctransform/boehm.py --- a/rpython/memory/gctransform/boehm.py +++ b/rpython/memory/gctransform/boehm.py @@ -74,7 +74,7 @@ def gct_fv_gc_malloc_varsize(self, hop, flags, TYPE, v_length, c_const_size, c_item_size, c_offset_to_length): -# XXX same behavior for zero=True: in theory that's wrong +# XXX same behavior for zero=True: in theory that's wrong if c_offset_to_length is None: v_raw = hop.genop("direct_call", [self.malloc_varsize_no_length_ptr, v_length, @@ -156,6 +156,11 @@ resulttype = lltype.Signed) hop.genop('int_invert', [v_int], resultvar=hop.spaceop.result) +def gcheader_initdata(self, defnode): +hdr = lltype.malloc(self.HDR, immortal=True) +hdr.hash = lltype.identityhash_nocache(defnode.obj._as_ptr()) +return hdr._obj + ## weakrefs ## # Boehm: weakref objects are small structures containing only a Boehm diff --git a/rpython/memory/gctransform/framework.py b/rpython/memory/gctransform/framework.py --- a/rpython/memory/gctransform/framework.py +++ b/rpython/memory/gctransform/framework.py @@ -288,7 +288,6 @@ s_gcref = SomePtr(llmemory.GCREF) gcdata = self.gcdata -translator = self.translator #use the GC flag to find which malloc method to use #malloc_zero_filled == Ture -> malloc_fixedsize/varsize_clear #malloc_zero_filled == Flase -> malloc_fixedsize/varsize @@ -322,7 +321,7 @@ GCClass.malloc_varsize.im_func, [s_gc, s_typeid16] + [annmodel.SomeInteger(nonneg=True) for i in range(4)], s_gcref) - + self.collect_ptr = getfn(GCClass.collect.im_func, [s_gc, annmodel.SomeInteger()], annmodel.s_None) self.can_move_ptr = getfn(GCClass.can_move.im_func, @@ -1385,7 +1384,7 @@ [v] + previous_steps + [c_name, c_null]) else: llops.genop('bare_setfield', [v, c_name, c_null]) - + return elif isinstance(TYPE, lltype.Array): ITEM = TYPE.OF @@ -1412,6 +1411,25 @@ resulttype=llmemory.Address) llops.genop('raw_memclear', [v_adr, v_totalsize]) +def gcheader_initdata(self, defnode): +o = lltype.top_container(defnode.obj) +needs_hash = self.get_prebuilt_hash(o) is not None +hdr = self.gc_header_for(o, needs_hash) +return hdr._obj + +def get_prebuilt_hash(self, obj): +# for prebuilt objects that need to have their hash stored and +# restored. Note that only structures that are StructNodes all +# the way have their hash stored (and not e.g. structs with var- +# sized arrays at the end). 'obj' must be the top_container. +TYPE = lltype.typeOf(obj) +if not isinstance(TYPE, lltype.GcStruct): +return None +if TYPE._is_varsize(): +return None +return getattr(obj, '_hash_cache_', None) + + class TransformerLayoutBuilder(gctypelayout.TypeLayoutBuilder): diff --git a/rpython/memory/gctransform/refcounting.py b/rpython/memory/gctransform/refcounting.py --- a/rpython/memory/gctransform/refcounting.py +++ b/rpython/memory/gctransform/refcounting.py @@ -285,3 +285,7 @@ resulttype=llmemory.Address) hop.genop("direct_call", [self.identityhash_ptr, v_adr], resultvar=hop.spaceop.result) + +def gcheader_initdata(self, defnode): +top = lltype.top_container(defnode.obj) +return self.gcheaderbuilder.header_of_object(top)._obj diff --git a/rpython/memory/gctransform/test/test_framework.py b/rpython/memory/gctransform/test/test_framework.py --- a/rpython/memory/gctransform/test/test_framework.py +++ b/rpython/memory/gctransform/test/test_framework.py @@ -40,7 +40,7 @@ t.config.translation.gc = "minimark" cbuild = CStandaloneBuilder(t, entrypoint, t.config, gcpolicy=FrameworkGcPolicy2) -db = cbuild.generate_graphs_for_llinterp() +db = cbuild.build_database() entrypointptr = cbuild.getentrypointptr() entrygraph = entrypointptr._obj.graph @@ -69,7 +69,7 @@ return -x t = rtype(g, [int]) gg = graphof(t, g) -assert not CollectAnalyzer(t).analyze_direct_call(gg) +assert not CollectAnalyzer(t).analyze_direct_call(gg) def test_cancollect_external(): fext1 = rffi.llexternal('fext1', [], lltype.Void,
[pypy-commit] pypy exctrans: Close branch exctrans
Author: Ronan Lamy Branch: exctrans Changeset: r81954:e953e5f78446 Date: 2016-01-26 20:39 + http://bitbucket.org/pypy/pypy/changeset/e953e5f78446/ Log:Close branch exctrans ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Document branch 'exctrans'
Author: Ronan Lamy Branch: Changeset: r81982:a27b8ecd898e Date: 2016-01-27 18:23 + http://bitbucket.org/pypy/pypy/changeset/a27b8ecd898e/ Log:Document branch 'exctrans' diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst --- a/pypy/doc/whatsnew-head.rst +++ b/pypy/doc/whatsnew-head.rst @@ -133,4 +133,9 @@ `rpython/jit/metainterp/optimizeopt/pure.py`, which can result in better codegen for traces containing a large number of pure getfield operations. +.. branch: exctrans + +Try to ensure that no new functions get annotated during the 'source_c' phase. +Refactor sandboxing to operate at a higher level. + .. branch: cpyext-bootstrap ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy SomeRange: Separate bk.newrange() from bk.newlist()
Author: Ronan Lamy Branch: SomeRange Changeset: r82006:02f319beadff Date: 2016-01-30 04:47 + http://bitbucket.org/pypy/pypy/changeset/02f319beadff/ Log:Separate bk.newrange() from bk.newlist() diff --git a/rpython/annotator/bookkeeper.py b/rpython/annotator/bookkeeper.py --- a/rpython/annotator/bookkeeper.py +++ b/rpython/annotator/bookkeeper.py @@ -180,15 +180,18 @@ listdef.listitem.__dict__.update(flags_if_new) return listdef -def newlist(self, *s_values, **flags): +def newlist(self, *s_values): """Make a SomeList associated with the current position, general enough to contain the s_values as items.""" -listdef = self.getlistdef(**flags) +listdef = self.getlistdef() for s_value in s_values: listdef.generalize(s_value) -if flags: -assert flags.keys() == ['range_step'] -listdef.generalize_range_step(flags['range_step']) +return SomeList(listdef) + +def newrange(self, s_item, step): +listdef = self.getlistdef(range_step=step) +listdef.generalize(s_item) +listdef.generalize_range_step(step) return SomeList(listdef) def getdictdef(self, is_r_dict=False, force_non_null=False): diff --git a/rpython/annotator/builtin.py b/rpython/annotator/builtin.py --- a/rpython/annotator/builtin.py +++ b/rpython/annotator/builtin.py @@ -80,7 +80,7 @@ nonneg = s_stop.nonneg or (s_stop.is_constant() and s_stop.const >= -1) s_item = SomeInteger(nonneg=nonneg) -return getbookkeeper().newlist(s_item, range_step=step) +return getbookkeeper().newrange(s_item, step) builtin_xrange = builtin_range # xxx for now allow it ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy SomeRange: Make range() lists immutable
Author: Ronan Lamy Branch: SomeRange Changeset: r82009:3b3f8cea104f Date: 2016-01-30 18:16 + http://bitbucket.org/pypy/pypy/changeset/3b3f8cea104f/ Log:Make range() lists immutable diff --git a/rpython/annotator/binaryop.py b/rpython/annotator/binaryop.py --- a/rpython/annotator/binaryop.py +++ b/rpython/annotator/binaryop.py @@ -9,7 +9,7 @@ SomeDict, SomeUnicodeCodePoint, SomeUnicodeString, SomeException, SomeTuple, SomeImpossibleValue, s_ImpossibleValue, SomeInstance, SomeBuiltinMethod, SomeIterator, SomePBC, SomeNone, SomeFloat, s_None, -SomeByteArray, SomeWeakRef, SomeSingleFloat, +SomeByteArray, SomeWeakRef, SomeSingleFloat, SomeRange, SomeLongFloat, SomeType, SomeTypeOf, SomeConstantType, unionof, UnionError, read_can_only_throw, add_knowntypedata, merge_knowntypedata,) @@ -486,6 +486,12 @@ return lst1 inplace_mul.can_only_throw = [] +class __extend__(pairtype(SomeRange, SomeObject)): + +def inplace_mul((lst1, obj2)): +raise AnnotatorError( +"In RPython, lists returned by range() are immutable") + class __extend__(pairtype(SomeTuple, SomeTuple)): def union((tup1, tup2)): diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py --- a/rpython/annotator/unaryop.py +++ b/rpython/annotator/unaryop.py @@ -14,7 +14,7 @@ SomeUnicodeCodePoint, SomeInstance, SomeBuiltin, SomeBuiltinMethod, SomeFloat, SomeIterator, SomePBC, SomeNone, SomeTypeOf, s_ImpossibleValue, s_Bool, s_None, s_Int, unionof, add_knowntypedata, -SomeWeakRef, SomeUnicodeString, SomeByteArray) +SomeWeakRef, SomeUnicodeString, SomeByteArray, SomeRange) from rpython.annotator.bookkeeper import getbookkeeper, immutablevalue from rpython.annotator.binaryop import _clone ## XXX where to put this? from rpython.annotator.binaryop import _dict_can_only_throw_keyerror @@ -429,6 +429,32 @@ check_negative_slice(s_start, s_stop) self.listdef.resize() +class __extend__(SomeRange): + +def method_append(self, s_value): +raise AnnotatorError( +"In RPython, lists returned by range() are immutable") + +def method_extend(self, s_iterable): +raise AnnotatorError( +"In RPython, lists returned by range() are immutable") + +def method_reverse(self): +raise AnnotatorError( +"In RPython, lists returned by range() are immutable") + +def method_insert(self, s_index, s_value): +raise AnnotatorError( +"In RPython, lists returned by range() are immutable") + +def method_remove(self, s_value): +raise AnnotatorError( +"In RPython, lists returned by range() are immutable") + +def method_pop(self, s_index=None): +raise AnnotatorError( +"In RPython, lists returned by range() are immutable") + def check_negative_slice(s_start, s_stop, error="slicing"): if isinstance(s_start, SomeInteger) and not s_start.nonneg: raise AnnotatorError("%s: not proven to have non-negative start" % ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy SomeRange: Inline bk.getlistdef()
Author: Ronan Lamy Branch: SomeRange Changeset: r82007:b1921df13e50 Date: 2016-01-30 06:03 + http://bitbucket.org/pypy/pypy/changeset/b1921df13e50/ Log:Inline bk.getlistdef() diff --git a/rpython/annotator/bookkeeper.py b/rpython/annotator/bookkeeper.py --- a/rpython/annotator/bookkeeper.py +++ b/rpython/annotator/bookkeeper.py @@ -171,25 +171,23 @@ clsdefs = {self.getuniqueclassdef(cls) for cls in exc_classes} return SomeException(clsdefs) -def getlistdef(self, **flags_if_new): -"""Get the ListDef associated with the current position.""" +def newlist(self, *s_values): +"""Make a SomeList associated with the current position, general +enough to contain the s_values as items.""" try: listdef = self.listdefs[self.position_key] except KeyError: listdef = self.listdefs[self.position_key] = ListDef(self) -listdef.listitem.__dict__.update(flags_if_new) -return listdef - -def newlist(self, *s_values): -"""Make a SomeList associated with the current position, general -enough to contain the s_values as items.""" -listdef = self.getlistdef() for s_value in s_values: listdef.generalize(s_value) return SomeList(listdef) def newrange(self, s_item, step): -listdef = self.getlistdef(range_step=step) +try: +listdef = self.listdefs[self.position_key] +except KeyError: +listdef = self.listdefs[self.position_key] = ListDef(self) +listdef.listitem.range_step = step listdef.generalize(s_item) listdef.generalize_range_step(step) return SomeList(listdef) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy SomeRange: Merge rpython.rtyper.lltypesystem.rrange into rpython.rtyper.rrange
Author: Ronan Lamy Branch: SomeRange Changeset: r82005:d458d86b6ce2 Date: 2016-01-29 19:08 + http://bitbucket.org/pypy/pypy/changeset/d458d86b6ce2/ Log:Merge rpython.rtyper.lltypesystem.rrange into rpython.rtyper.rrange diff --git a/rpython/rtyper/lltypesystem/rrange.py b/rpython/rtyper/lltypesystem/rrange.py deleted file mode 100644 --- a/rpython/rtyper/lltypesystem/rrange.py +++ /dev/null @@ -1,98 +0,0 @@ -from rpython.rtyper.lltypesystem.lltype import Ptr, GcStruct, Signed, malloc, Void -from rpython.rtyper.rrange import AbstractRangeRepr, AbstractRangeIteratorRepr -from rpython.rtyper.error import TyperError - -# -# -# Concrete implementation of RPython lists that are returned by range() -# and never mutated afterwards: -# -#struct range { -#Signed start, stop;// step is always constant -#} -# -#struct rangest { -#Signed start, stop, step;// rare case, for completeness -#} - -def ll_length(l): -if l.step > 0: -lo = l.start -hi = l.stop -step = l.step -else: -lo = l.stop -hi = l.start -step = -l.step -if hi <= lo: -return 0 -n = (hi - lo - 1) // step + 1 -return n - -def ll_getitem_fast(l, index): -return l.start + index * l.step - -RANGEST = GcStruct("range", ("start", Signed), ("stop", Signed), ("step", Signed), -adtmeths = { -"ll_length":ll_length, -"ll_getitem_fast":ll_getitem_fast, -}, -hints = {'immutable': True}) -RANGESTITER = GcStruct("range", ("next", Signed), ("stop", Signed), ("step", Signed)) - -class RangeRepr(AbstractRangeRepr): - -RANGEST = Ptr(RANGEST) -RANGESTITER = Ptr(RANGESTITER) - -getfield_opname = "getfield" - -def __init__(self, step, *args): -self.RANGE = Ptr(GcStruct("range", ("start", Signed), ("stop", Signed), -adtmeths = { -"ll_length":ll_length, -"ll_getitem_fast":ll_getitem_fast, -"step":step, -}, -hints = {'immutable': True})) -self.RANGEITER = Ptr(GcStruct("range", ("next", Signed), ("stop", Signed))) -AbstractRangeRepr.__init__(self, step, *args) -self.ll_newrange = ll_newrange -self.ll_newrangest = ll_newrangest - -def make_iterator_repr(self, variant=None): -if variant is not None: -raise TyperError("unsupported %r iterator over a range list" % - (variant,)) -return RangeIteratorRepr(self) - - -def ll_newrange(RANGE, start, stop): -l = malloc(RANGE.TO) -l.start = start -l.stop = stop -return l - -def ll_newrangest(start, stop, step): -if step == 0: -raise ValueError -l = malloc(RANGEST) -l.start = start -l.stop = stop -l.step = step -return l - -class RangeIteratorRepr(AbstractRangeIteratorRepr): - -def __init__(self, *args): -AbstractRangeIteratorRepr.__init__(self, *args) -self.ll_rangeiter = ll_rangeiter - -def ll_rangeiter(ITERPTR, rng): -iter = malloc(ITERPTR.TO) -iter.next = rng.start -iter.stop = rng.stop -if ITERPTR.TO is RANGESTITER: -iter.step = rng.step -return iter - diff --git a/rpython/rtyper/rlist.py b/rpython/rtyper/rlist.py --- a/rpython/rtyper/rlist.py +++ b/rpython/rtyper/rlist.py @@ -44,7 +44,7 @@ s_value = listitem.s_value if (listitem.range_step is not None and not listitem.mutated and not isinstance(s_value, annmodel.SomeImpossibleValue)): -from rpython.rtyper.lltypesystem.rrange import RangeRepr +from rpython.rtyper.rrange import RangeRepr return RangeRepr(listitem.range_step) else: # cannot do the rtyper.getrepr() call immediately, for the case diff --git a/rpython/rtyper/rrange.py b/rpython/rtyper/rrange.py --- a/rpython/rtyper/rrange.py +++ b/rpython/rtyper/rrange.py @@ -1,19 +1,79 @@ from rpython.flowspace.model import Constant from rpython.rtyper.error import TyperError -from rpython.rtyper.lltypesystem.lltype import Signed, Void, Ptr +from rpython.rtyper.lltypesystem.lltype import ( +Ptr, GcStruct, Signed, malloc, Void) from rpython.rtyper.rlist import dum_nocheck, dum_checkidx from rpython.rtyper.rmodel import Repr, IteratorRepr from rpython.rtyper.rint import IntegerRepr from rpython.tool.pairtype import pairtype +# +# +# Concrete implementation of RPython lists that are returned by range() +# and never mutated afterwards: +# +#struct range { +#Signed start, stop;// step is always constant +#} +# +#struct rangest { +#Signed start, stop, step;// rare case, for completeness +#} -class AbstractRangeRepr(Repr): +def l
[pypy-commit] pypy SomeRange: Create SomeRange class
Author: Ronan Lamy Branch: SomeRange Changeset: r82008:273c3ace813a Date: 2016-01-30 17:40 + http://bitbucket.org/pypy/pypy/changeset/273c3ace813a/ Log:Create SomeRange class diff --git a/rpython/annotator/bookkeeper.py b/rpython/annotator/bookkeeper.py --- a/rpython/annotator/bookkeeper.py +++ b/rpython/annotator/bookkeeper.py @@ -13,7 +13,8 @@ SomeOrderedDict, SomeString, SomeChar, SomeFloat, unionof, SomeInstance, SomeDict, SomeBuiltin, SomePBC, SomeInteger, TLS, SomeUnicodeCodePoint, s_None, s_ImpossibleValue, SomeBool, SomeTuple, SomeException, -SomeImpossibleValue, SomeUnicodeString, SomeList, HarmlesslyBlocked, +SomeImpossibleValue, SomeUnicodeString, SomeList, SomeRange, +HarmlesslyBlocked, SomeWeakRef, SomeByteArray, SomeConstantType, SomeProperty) from rpython.annotator.classdesc import ClassDef, ClassDesc from rpython.annotator.listdef import ListDef, ListItem @@ -190,7 +191,7 @@ listdef.listitem.range_step = step listdef.generalize(s_item) listdef.generalize_range_step(step) -return SomeList(listdef) +return SomeRange(listdef) def getdictdef(self, is_r_dict=False, force_non_null=False): """Get the DictDef associated with the current position.""" diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py --- a/rpython/annotator/model.py +++ b/rpython/annotator/model.py @@ -359,6 +359,9 @@ def noneify(self): return SomeList(self.listdef) +class SomeRange(SomeList): +pass + class SomeTuple(SomeObject): "Stands for a tuple of known length." diff --git a/rpython/rtyper/rrange.py b/rpython/rtyper/rrange.py --- a/rpython/rtyper/rrange.py +++ b/rpython/rtyper/rrange.py @@ -89,6 +89,9 @@ v_step = self._getstep(v_rng, hop) return hop.gendirectcall(ll_rangelen, v_rng, v_step) +def __eq__(self, other): +return other.__class__ is self.__class__ and other.__dict__ == self.__dict__ + class __extend__(pairtype(RangeRepr, IntegerRepr)): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3k: fix
Author: Ronan Lamy Branch: py3k Changeset: r82035:2f9a601ed994 Date: 2016-02-01 16:29 + http://bitbucket.org/pypy/pypy/changeset/2f9a601ed994/ Log:fix diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py --- a/pypy/module/cpyext/api.py +++ b/pypy/module/cpyext/api.py @@ -445,8 +445,8 @@ TYPES = {} GLOBALS = { # this needs to include all prebuilt pto, otherwise segfaults occur '_Py_NoneStruct#': ('PyObject*', 'space.w_None'), -'_Py_TrueStruct#': ('PyIntObject*', 'space.w_True'), -'_Py_ZeroStruct#': ('PyIntObject*', 'space.w_False'), +'_Py_TrueStruct#': ('PyObject*', 'space.w_True'), +'_Py_ZeroStruct#': ('PyObject*', 'space.w_False'), '_Py_NotImplementedStruct#': ('PyObject*', 'space.w_NotImplemented'), '_Py_EllipsisObject#': ('PyObject*', 'space.w_Ellipsis'), 'PyDateTimeAPI': ('PyDateTime_CAPI*', 'None'), @@ -855,7 +855,7 @@ assert False, "Unknown static pointer: %s %s" % (typ, name) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value -elif typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*'): +elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyPyExc_') or name.startswith('cpyexttestExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, name) @@ -1149,7 +1149,7 @@ if name.startswith('PyExc_'): name = '_' + name w_obj = eval(expr) -if typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*'): +if typ in ('PyObject*', 'PyTypeObject*'): struct_ptr = make_ref(space, w_obj) elif typ == 'PyDateTime_CAPI*': continue ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3k: fix merge
Author: Ronan Lamy Branch: py3k Changeset: r82037:fbbd055f16fa Date: 2016-02-01 17:03 + http://bitbucket.org/pypy/pypy/changeset/fbbd055f16fa/ Log:fix merge diff --git a/pypy/objspace/std/dictmultiobject.py b/pypy/objspace/std/dictmultiobject.py --- a/pypy/objspace/std/dictmultiobject.py +++ b/pypy/objspace/std/dictmultiobject.py @@ -130,8 +130,8 @@ if ulist is not None: strategy = space.fromcache(UnicodeDictStrategy) storage = strategy.get_storage_fromkeys(ulist, w_fill) -w_dict = space.allocate_instance(W_DictMultiObject, w_type) -W_DictMultiObject.__init__(w_dict, space, strategy, storage) +w_dict = space.allocate_instance(W_DictObject, w_type) +W_DictObject.__init__(w_dict, space, strategy, storage) else: w_dict = W_DictMultiObject.allocate_and_init_instance(space, w_type) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3k: PyIntObject does not exist in py3k
Author: Ronan Lamy Branch: py3k Changeset: r82034:f57006f9cb96 Date: 2016-02-01 16:21 + http://bitbucket.org/pypy/pypy/changeset/f57006f9cb96/ Log:PyIntObject does not exist in py3k diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py --- a/pypy/module/cpyext/api.py +++ b/pypy/module/cpyext/api.py @@ -506,9 +506,7 @@ def get_structtype_for_ctype(ctype): from pypy.module.cpyext.typeobjectdefs import PyTypeObjectPtr from pypy.module.cpyext.cdatetime import PyDateTime_CAPI -from pypy.module.cpyext.intobject import PyIntObject return {"PyObject*": PyObject, "PyTypeObject*": PyTypeObjectPtr, -"PyIntObject*": PyIntObject, "PyDateTime_CAPI*": lltype.Ptr(PyDateTime_CAPI)}[ctype] PyTypeObject = lltype.ForwardReference() @@ -1097,7 +1095,7 @@ if not use_micronumpy: return use_micronumpy # import to register api functions by side-effect -import pypy.module.cpyext.ndarrayobject +import pypy.module.cpyext.ndarrayobject global GLOBALS, SYMBOLS_C, separate_module_files GLOBALS["PyArray_Type#"]= ('PyTypeObject*', "space.gettypeobject(W_NDimArray.typedef)") SYMBOLS_C += ['PyArray_Type', '_PyArray_FILLWBYTE', '_PyArray_ZEROS'] ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Make apptests more 3-friendly
Author: Ronan Lamy Branch: Changeset: r82049:babeead98057 Date: 2016-02-02 17:10 + http://bitbucket.org/pypy/pypy/changeset/babeead98057/ Log:Make apptests more 3-friendly diff --git a/pypy/module/_socket/test/test_sock_app.py b/pypy/module/_socket/test/test_sock_app.py --- a/pypy/module/_socket/test/test_sock_app.py +++ b/pypy/module/_socket/test/test_sock_app.py @@ -102,7 +102,7 @@ fd = space.appexec([w_socket, space.wrap(orig_fd.fileno()), space.wrap(socket.AF_INET), space.wrap(socket.SOCK_STREAM), space.wrap(0)], - """(_socket, fd, family, type, proto): + """(_socket, fd, family, type, proto): return _socket.fromfd(fd, family, type, proto)""") assert space.unwrap(space.call_method(fd, 'fileno')) @@ -326,7 +326,7 @@ def test_ntoa_exception(self): import _socket -raises(_socket.error, _socket.inet_ntoa, "ab") +raises(_socket.error, _socket.inet_ntoa, b"ab") def test_aton_exceptions(self): import _socket @@ -418,7 +418,7 @@ # it if there is no connection. try: s.connect(("www.python.org", 80)) -except _socket.gaierror, ex: +except _socket.gaierror as ex: skip("GAIError - probably no connection: %s" % str(ex.args)) name = s.getpeername() # Will raise socket.error if not connected assert name[1] == 80 @@ -465,7 +465,7 @@ sizes = {socket.htonl: 32, socket.ntohl: 32, socket.htons: 16, socket.ntohs: 16} for func, size in sizes.items(): -mask = (1L
[pypy-commit] pypy default: Kill randomly vendored obsolete version of pytest_cov
Author: Ronan Lamy Branch: Changeset: r82060:643912e63967 Date: 2016-02-03 16:56 + http://bitbucket.org/pypy/pypy/changeset/643912e63967/ Log:Kill randomly vendored obsolete version of pytest_cov diff --git a/pypy/test_all.py b/pypy/test_all.py --- a/pypy/test_all.py +++ b/pypy/test_all.py @@ -26,11 +26,10 @@ #Add toplevel repository dir to sys.path sys.path.insert(0,os.path.dirname(os.path.dirname(os.path.realpath(__file__ import pytest -import pytest_cov if sys.platform == 'win32': #Try to avoid opeing a dialog box if one of the tests causes a system error # We do this in runner.py, but buildbots run twisted which ruins inheritance -# in windows subprocesses. +# in windows subprocesses. import ctypes winapi = ctypes.windll.kernel32 SetErrorMode = winapi.SetErrorMode @@ -44,4 +43,4 @@ old_mode = SetErrorMode(flags) SetErrorMode(old_mode | flags) -sys.exit(pytest.main(plugins=[pytest_cov])) +sys.exit(pytest.main()) diff --git a/pytest_cov.py b/pytest_cov.py deleted file mode 100644 --- a/pytest_cov.py +++ /dev/null @@ -1,353 +0,0 @@ -"""produce code coverage reports using the 'coverage' package, including support for distributed testing. - -This plugin produces coverage reports. It supports centralised testing and distributed testing in -both load and each modes. It also supports coverage of subprocesses. - -All features offered by the coverage package should be available, either through pytest-cov or -through coverage's config file. - - -Installation - - -The `pytest-cov`_ package may be installed with pip or easy_install:: - -pip install pytest-cov -easy_install pytest-cov - -.. _`pytest-cov`: http://pypi.python.org/pypi/pytest-cov/ - - -Uninstallation --- - -Uninstalling packages is supported by pip:: - -pip uninstall pytest-cov - -However easy_install does not provide an uninstall facility. - -.. IMPORTANT:: - -Ensure that you manually delete the init_cov_core.pth file in your site-packages directory. - -This file starts coverage collection of subprocesses if appropriate during site initialisation -at python startup. - - -Usage -- - -Centralised Testing -~~~ - -Centralised testing will report on the combined coverage of the main process and all of it's -subprocesses. - -Running centralised testing:: - -py.test --cov myproj tests/ - -Shows a terminal report:: - - coverage: platform linux2, python 2.6.4-final-0 - -Name Stmts Miss Cover - -myproj/__init__ 2 0 100% -myproj/myproj 257 1394% -myproj/feature4286 94 792% - -TOTAL 353 2094% - - -Distributed Testing: Load -~ - -Distributed testing with dist mode set to load will report on the combined coverage of all slaves. -The slaves may be spread out over any number of hosts and each slave may be located anywhere on the -file system. Each slave will have it's subprocesses measured. - -Running distributed testing with dist mode set to load:: - -py.test --cov myproj -n 2 tests/ - -Shows a terminal report:: - - coverage: platform linux2, python 2.6.4-final-0 - -Name Stmts Miss Cover - -myproj/__init__ 2 0 100% -myproj/myproj 257 1394% -myproj/feature4286 94 792% - -TOTAL 353 2094% - - -Again but spread over different hosts and different directories:: - -py.test --cov myproj --dist load ---tx ssh=memedough@host1//chdir=testenv1 ---tx ssh=memedough@host2//chdir=/tmp/testenv2//python=/tmp/env1/bin/python ---rsyncdir myproj --rsyncdir tests --rsync examples -tests/ - -Shows a terminal report:: - - coverage: platform linux2, python 2.6.4-final-0 - -Name Stmts Miss Cover - -myproj/__init__ 2 0 100% -myproj/myproj 257 1394% -myproj/feature4286 94 792% - -TOTAL 353 2094% - - -Distributed Testing: Each -~ - -Distributed testing with dist mode set to each will report on the combined coverage of all slaves. -Since each slave is running all tests this allows generating a combined coverage report for multiple -environments. - -Running distributed testing with dist mode set to each:: - -py.test --cov myproj --dist each ---tx
[pypy-commit] pypy default: Handle pdb.set_trace() in rpython/annotator/builtin.py
Author: Ronan Lamy Branch: Changeset: r82074:e5eb901ac085 Date: 2016-02-04 16:33 + http://bitbucket.org/pypy/pypy/changeset/e5eb901ac085/ Log:Handle pdb.set_trace() in rpython/annotator/builtin.py diff --git a/rpython/annotator/builtin.py b/rpython/annotator/builtin.py --- a/rpython/annotator/builtin.py +++ b/rpython/annotator/builtin.py @@ -311,3 +311,14 @@ @analyzer_for(rpython.rlib.objectmodel.free_non_gc_object) def robjmodel_free_non_gc_object(obj): pass + +# +# pdb + +import pdb + +@analyzer_for(pdb.set_trace) +def pdb_set_trace(*args_s): +raise AnnotatorError( +"you left pdb.set_trace() in your interpreter! " +"If you want to attach a gdb instead, call rlib.debug.attach_gdb()") diff --git a/rpython/rtyper/extfuncregistry.py b/rpython/rtyper/extfuncregistry.py --- a/rpython/rtyper/extfuncregistry.py +++ b/rpython/rtyper/extfuncregistry.py @@ -11,7 +11,6 @@ import math from rpython.rtyper.lltypesystem.module import ll_math -from rpython.rtyper.module import ll_pdb from rpython.rlib import rfloat # the following functions all take one float, return one float diff --git a/rpython/rtyper/module/ll_pdb.py b/rpython/rtyper/module/ll_pdb.py deleted file mode 100644 --- a/rpython/rtyper/module/ll_pdb.py +++ /dev/null @@ -1,13 +0,0 @@ -""" -Complain if you leave in pdb.set_trace() in the code -""" - -import pdb -from rpython.rtyper.extfunc import ExtFuncEntry - - -class FunEntry(ExtFuncEntry): -_about_ = pdb.set_trace -def compute_result_annotation(self, *args_s): -raise Exception("you left pdb.set_trace() in your interpreter!" -"If you want to attach a gdb instead, call rlib.debug.attach_gdb()") ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Use the correct exceptions in rpython/annotator/builtin.py
Author: Ronan Lamy Branch: Changeset: r82075:b8933a584083 Date: 2016-02-04 16:46 + http://bitbucket.org/pypy/pypy/changeset/b8933a584083/ Log:Use the correct exceptions in rpython/annotator/builtin.py diff --git a/rpython/annotator/builtin.py b/rpython/annotator/builtin.py --- a/rpython/annotator/builtin.py +++ b/rpython/annotator/builtin.py @@ -39,8 +39,9 @@ return s_result s_realresult = immutablevalue(realresult) if not s_result.contains(s_realresult): -raise Exception("%s%r returned %r, which is not contained in %s" % ( -func, args, realresult, s_result)) +raise AnnotatorError( +"%s%r returned %r, which is not contained in %s" % ( +func, args, realresult, s_result)) return s_realresult # @@ -56,14 +57,14 @@ s_start, s_stop = args[:2] s_step = args[2] else: -raise Exception("range() takes 1 to 3 arguments") +raise AnnotatorError("range() takes 1 to 3 arguments") empty = False # so far if not s_step.is_constant(): step = 0 # this case signals a variable step else: step = s_step.const if step == 0: -raise Exception("range() with step zero") +raise AnnotatorError("range() with step zero") if s_start.is_constant() and s_stop.is_constant(): try: if len(xrange(s_start.const, s_stop.const, step)) == 0: @@ -285,7 +286,8 @@ else: @analyzer_for(unicodedata.decimal) def unicodedata_decimal(s_uchr): -raise TypeError("unicodedate.decimal() calls should not happen at interp-level") +raise AnnotatorError( +"unicodedate.decimal() calls should not happen at interp-level") @analyzer_for(OrderedDict) def analyze(): @@ -299,9 +301,9 @@ @analyzer_for(weakref.ref) def weakref_ref(s_obj): if not isinstance(s_obj, SomeInstance): -raise Exception("cannot take a weakref to %r" % (s_obj,)) +raise AnnotatorError("cannot take a weakref to %r" % (s_obj,)) if s_obj.can_be_None: -raise Exception("should assert that the instance we take " +raise AnnotatorError("should assert that the instance we take " "a weakref to cannot be None") return SomeWeakRef(s_obj.classdef) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Create rpython.rtyper.debug and move ll_assert() and fatalerror() there.
Author: Ronan Lamy Branch: Changeset: r82091:45cce2525cc9 Date: 2016-02-05 03:45 + http://bitbucket.org/pypy/pypy/changeset/45cce2525cc9/ Log:Create rpython.rtyper.debug and move ll_assert() and fatalerror() there. This reduces the number of imports from rpython/rtyper/ to rpython.rlib and avoids a cyclical import dependency. diff --git a/rpython/rlib/debug.py b/rpython/rlib/debug.py --- a/rpython/rlib/debug.py +++ b/rpython/rlib/debug.py @@ -1,76 +1,41 @@ -import sys, time +import sys +import time + from rpython.rtyper.extregistry import ExtRegistryEntry from rpython.rlib.objectmodel import we_are_translated from rpython.rlib.rarithmetic import is_valid_int from rpython.rtyper.extfunc import ExtFuncEntry from rpython.rtyper.lltypesystem import lltype +from rpython.rtyper.lltypesystem import rffi from rpython.translator.tool.cbuild import ExternalCompilationInfo - -def ll_assert(x, msg): -"""After translation to C, this becomes an RPyAssert.""" -assert type(x) is bool, "bad type! got %r" % (type(x),) -assert x, msg - -class Entry(ExtRegistryEntry): -_about_ = ll_assert - -def compute_result_annotation(self, s_x, s_msg): -assert s_msg.is_constant(), ("ll_assert(x, msg): " - "the msg must be constant") -return None - -def specialize_call(self, hop): -vlist = hop.inputargs(lltype.Bool, lltype.Void) -hop.exception_cannot_occur() -hop.genop('debug_assert', vlist) - -class FatalError(Exception): -pass - -def fatalerror(msg): -# print the RPython traceback and abort with a fatal error -if not we_are_translated(): -raise FatalError(msg) -from rpython.rtyper.lltypesystem import lltype -from rpython.rtyper.lltypesystem.lloperation import llop -llop.debug_print_traceback(lltype.Void) -llop.debug_fatalerror(lltype.Void, msg) -fatalerror._dont_inline_ = True -fatalerror._jit_look_inside_ = False -fatalerror._annenforceargs_ = [str] - -def fatalerror_notb(msg): -# a variant of fatalerror() that doesn't print the RPython traceback -if not we_are_translated(): -raise FatalError(msg) -from rpython.rtyper.lltypesystem import lltype -from rpython.rtyper.lltypesystem.lloperation import llop -llop.debug_fatalerror(lltype.Void, msg) -fatalerror_notb._dont_inline_ = True -fatalerror_notb._jit_look_inside_ = False -fatalerror_notb._annenforceargs_ = [str] +# Expose these here (public interface) +from rpython.rtyper.debug import ( +ll_assert, FatalError, fatalerror, fatalerror_notb) class DebugLog(list): def debug_print(self, *args): self.append(('debug_print',) + args) + def debug_start(self, category, time=None): self.append(('debug_start', category, time)) + def debug_stop(self, category, time=None): -for i in xrange(len(self)-1, -1, -1): +for i in xrange(len(self) - 1, -1, -1): if self[i][0] == 'debug_start': assert self[i][1] == category, ( "nesting error: starts with %r but stops with %r" % (self[i][1], category)) starttime = self[i][2] if starttime is not None or time is not None: -self[i:] = [(category, starttime, time, self[i+1:])] +self[i:] = [(category, starttime, time, self[i + 1:])] else: -self[i:] = [(category, self[i+1:])] +self[i:] = [(category, self[i + 1:])] return assert False, ("nesting error: no start corresponding to stop %r" % (category,)) + def __repr__(self): import pprint return pprint.pformat(list(self)) @@ -161,7 +126,6 @@ return self.bookkeeper.immutablevalue(False) def specialize_call(self, hop): -from rpython.rtyper.lltypesystem import lltype t = hop.rtyper.annotator.translator hop.exception_cannot_occur() if t.config.translation.log: @@ -189,7 +153,6 @@ return annmodel.SomeInteger() def specialize_call(self, hop): -from rpython.rtyper.lltypesystem import lltype hop.exception_cannot_occur() return hop.genop('debug_offset', [], resulttype=lltype.Signed) @@ -223,7 +186,6 @@ return None def specialize_call(self, hop): -from rpython.rtyper.lltypesystem import lltype vlist = hop.inputargs(lltype.Signed) hop.exception_cannot_occur() return hop.genop('debug_forked', vlist) @@ -244,7 +206,6 @@ def compute_result_annotation(self, s_RESTYPE, s_pythonfunction, *args_s): from rpython.annotator import model as annmodel from rpython.rtyper.llannotation import lltype_to_annotation -from rpython.rtyper.lltypesystem import lltype assert s_RESTYPE.is_constant() assert s_pythonfunction.is_co
[pypy-commit] pypy default: Use regular register_external() call for attach_gdb()
Author: Ronan Lamy Branch: Changeset: r82092:e415ef72b422 Date: 2016-02-05 17:26 + http://bitbucket.org/pypy/pypy/changeset/e415ef72b422/ Log:Use regular register_external() call for attach_gdb() diff --git a/rpython/rlib/debug.py b/rpython/rlib/debug.py --- a/rpython/rlib/debug.py +++ b/rpython/rlib/debug.py @@ -4,7 +4,7 @@ from rpython.rtyper.extregistry import ExtRegistryEntry from rpython.rlib.objectmodel import we_are_translated from rpython.rlib.rarithmetic import is_valid_int -from rpython.rtyper.extfunc import ExtFuncEntry +from rpython.rtyper.extfunc import register_external from rpython.rtyper.lltypesystem import lltype from rpython.rtyper.lltypesystem import rffi from rpython.translator.tool.cbuild import ExternalCompilationInfo @@ -397,12 +397,11 @@ import pdb; pdb.set_trace() if not sys.platform.startswith('win'): -def _make_impl_attach_gdb(): -if sys.platform.startswith('linux'): -# Only necessary on Linux -eci = ExternalCompilationInfo(includes=['string.h', 'assert.h', -'sys/prctl.h'], - post_include_bits=[""" +if sys.platform.startswith('linux'): +# Only necessary on Linux +eci = ExternalCompilationInfo(includes=['string.h', 'assert.h', +'sys/prctl.h'], +post_include_bits=[""" /* If we have an old Linux kernel (or compile with old system headers), the following two macros are not defined. But we would still like a pypy translated on such a system to run on a more modern system. */ @@ -416,55 +415,38 @@ prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY); } """]) -allow_attach = rffi.llexternal( -"pypy__allow_attach", [], lltype.Void, -compilation_info=eci, _nowrapper=True) +allow_attach = rffi.llexternal( +"pypy__allow_attach", [], lltype.Void, +compilation_info=eci, _nowrapper=True) +else: +# Do nothing, there's no prctl +def allow_attach(): +pass + +def impl_attach_gdb(): +import os +allow_attach() +pid = os.getpid() +gdbpid = os.fork() +if gdbpid == 0: +shell = os.environ.get("SHELL") or "/bin/sh" +sepidx = shell.rfind(os.sep) + 1 +if sepidx > 0: +argv0 = shell[sepidx:] +else: +argv0 = shell +try: +os.execv(shell, [argv0, "-c", "gdb -p %d" % pid]) +except OSError as e: +os.write(2, "Could not start GDB: %s" % ( +os.strerror(e.errno))) +raise SystemExit else: -# Do nothing, there's no prctl -def allow_attach(): -pass +time.sleep(1) # give the GDB time to attach -def impl_attach_gdb(): -import os -allow_attach() -pid = os.getpid() -gdbpid = os.fork() -if gdbpid == 0: -shell = os.environ.get("SHELL") or "/bin/sh" -sepidx = shell.rfind(os.sep) + 1 -if sepidx > 0: -argv0 = shell[sepidx:] -else: -argv0 = shell -try: -os.execv(shell, [argv0, "-c", "gdb -p %d" % pid]) -except OSError as e: -os.write(2, "Could not start GDB: %s" % ( -os.strerror(e.errno))) -raise SystemExit -else: -time.sleep(1) # give the GDB time to attach +else: +def impl_attach_gdb(): +print "Don't know how to attach GDB on Windows" -return impl_attach_gdb -else: -def _make_impl_attach_gdb(): -def impl_attach_gdb(): -print "Don't know how to attach GDB on Windows" -return impl_attach_gdb - - -class FunEntry(ExtFuncEntry): -_about_ = attach_gdb -signature_args = [] -#lltypeimpl = staticmethod(impl_attach_gdb) --- done lazily below -name = "impl_attach_gdb" - -@property -def lltypeimpl(self): -if not hasattr(self.__class__, '_lltypeimpl'): -self.__class__._lltypeimpl = staticmethod(_make_impl_attach_gdb()) -return self._lltypeimpl - -def compute_result_annotation(self, *args_s): -from rpython.annotator.model import s_None -return s_None +register_external(attach_gdb, [], result=None, + export_name="impl_attach_gdb", llimpl=impl_attach_gdb) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: forgot to add rpython/rtyper/debug.py
Author: Ronan Lamy Branch: Changeset: r82093:ca082804de94 Date: 2016-02-05 19:29 + http://bitbucket.org/pypy/pypy/changeset/ca082804de94/ Log:forgot to add rpython/rtyper/debug.py diff --git a/rpython/rtyper/debug.py b/rpython/rtyper/debug.py new file mode 100644 --- /dev/null +++ b/rpython/rtyper/debug.py @@ -0,0 +1,47 @@ +from rpython.rlib.objectmodel import we_are_translated +from rpython.rtyper.extregistry import ExtRegistryEntry +from rpython.rtyper.lltypesystem import lltype + +def ll_assert(x, msg): +"""After translation to C, this becomes an RPyAssert.""" +assert type(x) is bool, "bad type! got %r" % (type(x),) +assert x, msg + +class Entry(ExtRegistryEntry): +_about_ = ll_assert + +def compute_result_annotation(self, s_x, s_msg): +assert s_msg.is_constant(), ("ll_assert(x, msg): " + "the msg must be constant") +return None + +def specialize_call(self, hop): +vlist = hop.inputargs(lltype.Bool, lltype.Void) +hop.exception_cannot_occur() +hop.genop('debug_assert', vlist) + +class FatalError(Exception): +pass + +def fatalerror(msg): +# print the RPython traceback and abort with a fatal error +if not we_are_translated(): +raise FatalError(msg) +from rpython.rtyper.lltypesystem import lltype +from rpython.rtyper.lltypesystem.lloperation import llop +llop.debug_print_traceback(lltype.Void) +llop.debug_fatalerror(lltype.Void, msg) +fatalerror._dont_inline_ = True +fatalerror._jit_look_inside_ = False +fatalerror._annenforceargs_ = [str] + +def fatalerror_notb(msg): +# a variant of fatalerror() that doesn't print the RPython traceback +if not we_are_translated(): +raise FatalError(msg) +from rpython.rtyper.lltypesystem import lltype +from rpython.rtyper.lltypesystem.lloperation import llop +llop.debug_fatalerror(lltype.Void, msg) +fatalerror_notb._dont_inline_ = True +fatalerror_notb._jit_look_inside_ = False +fatalerror_notb._annenforceargs_ = [str] ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy llimpl: Hack the functionptr when passing an llexternal as llimpl in register_external()
Author: Ronan Lamy Branch: llimpl Changeset: r82104:58ecd8c5102c Date: 2016-02-07 02:00 + http://bitbucket.org/pypy/pypy/changeset/58ecd8c5102c/ Log:Hack the functionptr when passing an llexternal as llimpl in register_external() diff --git a/rpython/rtyper/extfunc.py b/rpython/rtyper/extfunc.py --- a/rpython/rtyper/extfunc.py +++ b/rpython/rtyper/extfunc.py @@ -1,10 +1,8 @@ from rpython.rtyper.extregistry import ExtRegistryEntry -from rpython.rtyper.lltypesystem.lltype import typeOf, FuncType, functionptr +from rpython.rtyper.lltypesystem.lltype import typeOf, FuncType, functionptr, _ptr from rpython.annotator.model import unionof from rpython.annotator.signature import annotation, SignatureError -import py - class ExtFuncEntry(ExtRegistryEntry): safe_not_sandboxed = False @@ -52,14 +50,17 @@ make_sandbox_trampoline) impl = make_sandbox_trampoline( self.name, signature_args, s_result) -# store some attributes to the 'impl' function, where -# the eventual call to rtyper.getcallable() will find them -# and transfer them to the final lltype.functionptr(). -impl._llfnobjattrs_ = {'_name': self.name} -if hasattr(self, 'lltypefakeimpl'): -impl._llfnobjattrs_['_fakeimpl'] = fakeimpl -obj = rtyper.getannmixlevel().delayedfunction( -impl, signature_args, hop.s_result) +if isinstance(impl, _ptr): +obj = impl +else: +# store some attributes to the 'impl' function, where +# the eventual call to rtyper.getcallable() will find them +# and transfer them to the final lltype.functionptr(). +impl._llfnobjattrs_ = {'_name': self.name} +if hasattr(self, 'lltypefakeimpl'): +impl._llfnobjattrs_['_fakeimpl'] = fakeimpl +obj = rtyper.getannmixlevel().delayedfunction( +impl, signature_args, hop.s_result) else: FT = FuncType(args_ll, ll_result) obj = functionptr(FT, name, _external_name=self.name, @@ -84,6 +85,10 @@ if export_name is None: export_name = function.__name__ +if isinstance(llimpl, _ptr) and llfakeimpl: +llimpl._obj.__dict__['_fakeimpl'] = llfakeimpl +llfakeimpl = None + class FunEntry(ExtFuncEntry): _about_ = function safe_not_sandboxed = sandboxsafe ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy llimpl: Create rtyper.backend and use it to choose the implementation when using register_external()
Author: Ronan Lamy Branch: llimpl Changeset: r82108:cea1893831f4 Date: 2016-02-07 18:40 + http://bitbucket.org/pypy/pypy/changeset/cea1893831f4/ Log:Create rtyper.backend and use it to choose the implementation when using register_external() diff --git a/rpython/memory/test/test_transformed_gc.py b/rpython/memory/test/test_transformed_gc.py --- a/rpython/memory/test/test_transformed_gc.py +++ b/rpython/memory/test/test_transformed_gc.py @@ -14,6 +14,7 @@ from rpython.conftest import option from rpython.rlib.rstring import StringBuilder from rpython.rlib.rarithmetic import LONG_BIT +from rpython.rtyper.rtyper import llinterp_backend WORD = LONG_BIT // 8 @@ -29,9 +30,11 @@ t.config.set(**extraconfigopts) ann = t.buildannotator() ann.build_types(func, inputtypes) +rtyper = t.buildrtyper() +rtyper.backend = llinterp_backend if specialize: -t.buildrtyper().specialize() +rtyper.specialize() if backendopt: from rpython.translator.backendopt.all import backend_optimizations backend_optimizations(t) diff --git a/rpython/rtyper/extfunc.py b/rpython/rtyper/extfunc.py --- a/rpython/rtyper/extfunc.py +++ b/rpython/rtyper/extfunc.py @@ -1,3 +1,4 @@ +from rpython.tool.sourcetools import func_with_new_name from rpython.rtyper.extregistry import ExtRegistryEntry from rpython.rtyper.lltypesystem.lltype import typeOf, FuncType, functionptr, _ptr from rpython.annotator.model import unionof @@ -33,6 +34,7 @@ return self.signature_result def specialize_call(self, hop): +from rpython.rtyper.rtyper import llinterp_backend rtyper = hop.rtyper signature_args = self.normalize_args(*hop.args_s) args_r = [rtyper.getrepr(s_arg) for s_arg in signature_args] @@ -49,14 +51,18 @@ if isinstance(impl, _ptr): obj = impl else: -# store some attributes to the 'impl' function, where -# the eventual call to rtyper.getcallable() will find them -# and transfer them to the final lltype.functionptr(). -impl._llfnobjattrs_ = {'_name': self.name} -if hasattr(self, 'lltypefakeimpl'): -impl._llfnobjattrs_['_fakeimpl'] = fakeimpl -obj = rtyper.getannmixlevel().delayedfunction( -impl, signature_args, hop.s_result) +if hasattr(self, 'lltypefakeimpl') and rtyper.backend is llinterp_backend: +FT = FuncType(args_ll, ll_result) +obj = functionptr(FT, name, _external_name=self.name, +_callable=fakeimpl, + _safe_not_sandboxed=self.safe_not_sandboxed) +else: +# store some attributes to the 'impl' function, where +# the eventual call to rtyper.getcallable() will find them +# and transfer them to the final lltype.functionptr(). +impl._llfnobjattrs_ = {'_name': self.name} +obj = rtyper.getannmixlevel().delayedfunction( +impl, signature_args, hop.s_result) else: FT = FuncType(args_ll, ll_result) obj = functionptr(FT, name, _external_name=self.name, diff --git a/rpython/rtyper/rtyper.py b/rpython/rtyper/rtyper.py --- a/rpython/rtyper/rtyper.py +++ b/rpython/rtyper/rtyper.py @@ -32,11 +32,24 @@ from rpython.translator.sandbox.rsandbox import make_sandbox_trampoline +class RTyperBackend(object): +pass + +class GenCBackend(RTyperBackend): +pass +genc_backend = GenCBackend() + +class LLInterpBackend(RTyperBackend): +pass +llinterp_backend = LLInterpBackend() + + class RPythonTyper(object): from rpython.rtyper.rmodel import log -def __init__(self, annotator): +def __init__(self, annotator, backend=genc_backend): self.annotator = annotator +self.backend = backend self.lowlevel_ann_policy = LowLevelAnnotatorPolicy(self) self.reprs = {} self._reprs_must_call_setup = [] diff --git a/rpython/rtyper/test/test_llinterp.py b/rpython/rtyper/test/test_llinterp.py --- a/rpython/rtyper/test/test_llinterp.py +++ b/rpython/rtyper/test/test_llinterp.py @@ -13,7 +13,7 @@ from rpython.rlib.rarithmetic import r_uint, ovfcheck from rpython.tool import leakfinder from rpython.conftest import option - +from rpython.rtyper.rtyper import llinterp_backend # switch on logging of interp to show more info on failing tests @@ -39,6 +39,7 @@ t.view() global typer # we need it for find_exception typer = t.buildrtyper() +typer.backend = llinterp_backend typer.specialize() #t.view() t.checkgraphs() diff --git a/rpython/translator/c/node.py b/rpython/translator/c/node.py --- a/rpython/translator/c/node.py +++ b/rpython/translator/c/node.py @@ -913,6 +913,7 @@
[pypy-commit] pypy llimpl: Extract some code out of ExtFuncEntry
Author: Ronan Lamy Branch: llimpl Changeset: r82107:ad357db1fd3f Date: 2016-02-07 02:01 + http://bitbucket.org/pypy/pypy/changeset/ad357db1fd3f/ Log:Extract some code out of ExtFuncEntry diff --git a/rpython/rtyper/extfunc.py b/rpython/rtyper/extfunc.py --- a/rpython/rtyper/extfunc.py +++ b/rpython/rtyper/extfunc.py @@ -44,12 +44,8 @@ impl = getattr(self, 'lltypeimpl', None) fakeimpl = getattr(self, 'lltypefakeimpl', self.instance) if impl: -if (rtyper.annotator.translator.config.translation.sandbox -and not self.safe_not_sandboxed): -from rpython.translator.sandbox.rsandbox import ( -make_sandbox_trampoline) -impl = make_sandbox_trampoline( -self.name, signature_args, s_result) +impl = make_impl(rtyper, impl, self.safe_not_sandboxed, self.name, + signature_args, s_result) if isinstance(impl, _ptr): obj = impl else: @@ -70,6 +66,13 @@ hop.exception_is_here() return hop.genop('direct_call', vlist, r_result) +def make_impl(rtyper, impl, sandboxsafe, name, args_s, s_result): +if (rtyper.annotator.translator.config.translation.sandbox +and not sandboxsafe): +from rpython.translator.sandbox.rsandbox import make_sandbox_trampoline +impl = make_sandbox_trampoline(name, args_s, s_result) +return impl + def register_external(function, args, result=None, export_name=None, llimpl=None, llfakeimpl=None, sandboxsafe=False): """ ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy llimpl: fix gctransform tests
Author: Ronan Lamy Branch: llimpl Changeset: r82109:d6f84983b21e Date: 2016-02-07 20:21 + http://bitbucket.org/pypy/pypy/changeset/d6f84983b21e/ Log:fix gctransform tests diff --git a/rpython/memory/gctransform/test/test_transform.py b/rpython/memory/gctransform/test/test_transform.py --- a/rpython/memory/gctransform/test/test_transform.py +++ b/rpython/memory/gctransform/test/test_transform.py @@ -5,6 +5,7 @@ from rpython.translator.exceptiontransform import ExceptionTransformer from rpython.rtyper.lltypesystem import lltype from rpython.conftest import option +from rpython.rtyper.rtyper import llinterp_backend class LLInterpedTranformerTests: @@ -131,8 +132,10 @@ def rtype(func, inputtypes, specialize=True): t = TranslationContext() t.buildannotator().build_types(func, inputtypes) +rtyper = t.buildrtyper() +rtyper.backend = llinterp_backend if specialize: -t.buildrtyper().specialize() +rtyper.specialize() if option.view: t.view() return t ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy llimpl: Don't hack the funcptr in register_external()
Author: Ronan Lamy Branch: llimpl Changeset: r82110:5c4c76a4b9c4 Date: 2016-02-07 20:42 + http://bitbucket.org/pypy/pypy/changeset/5c4c76a4b9c4/ Log:Don't hack the funcptr in register_external() diff --git a/rpython/rtyper/extfunc.py b/rpython/rtyper/extfunc.py --- a/rpython/rtyper/extfunc.py +++ b/rpython/rtyper/extfunc.py @@ -48,21 +48,19 @@ if impl: impl = make_impl(rtyper, impl, self.safe_not_sandboxed, self.name, signature_args, s_result) -if isinstance(impl, _ptr): +if hasattr(self, 'lltypefakeimpl') and rtyper.backend is llinterp_backend: +FT = FuncType(args_ll, ll_result) +obj = functionptr(FT, name, _external_name=self.name, +_callable=fakeimpl) +elif isinstance(impl, _ptr): obj = impl else: -if hasattr(self, 'lltypefakeimpl') and rtyper.backend is llinterp_backend: -FT = FuncType(args_ll, ll_result) -obj = functionptr(FT, name, _external_name=self.name, -_callable=fakeimpl, - _safe_not_sandboxed=self.safe_not_sandboxed) -else: -# store some attributes to the 'impl' function, where -# the eventual call to rtyper.getcallable() will find them -# and transfer them to the final lltype.functionptr(). -impl._llfnobjattrs_ = {'_name': self.name} -obj = rtyper.getannmixlevel().delayedfunction( -impl, signature_args, hop.s_result) +# store some attributes to the 'impl' function, where +# the eventual call to rtyper.getcallable() will find them +# and transfer them to the final lltype.functionptr(). +impl._llfnobjattrs_ = {'_name': self.name} +obj = rtyper.getannmixlevel().delayedfunction( +impl, signature_args, hop.s_result) else: FT = FuncType(args_ll, ll_result) obj = functionptr(FT, name, _external_name=self.name, @@ -94,10 +92,6 @@ if export_name is None: export_name = function.__name__ -if isinstance(llimpl, _ptr) and llfakeimpl: -llimpl._obj.__dict__['_fakeimpl'] = llfakeimpl -llfakeimpl = None - class FunEntry(ExtFuncEntry): _about_ = function safe_not_sandboxed = sandboxsafe ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy llimpl: ExtFuncEntry always has a .name defined
Author: Ronan Lamy Branch: llimpl Changeset: r82112:1a459b2a58cb Date: 2016-02-08 02:36 + http://bitbucket.org/pypy/pypy/changeset/1a459b2a58cb/ Log:ExtFuncEntry always has a .name defined diff --git a/rpython/rtyper/extfunc.py b/rpython/rtyper/extfunc.py --- a/rpython/rtyper/extfunc.py +++ b/rpython/rtyper/extfunc.py @@ -17,16 +17,10 @@ for i, expected in enumerate(signature_args): arg = unionof(args_s[i], expected) if not expected.contains(arg): -name = getattr(self, 'name', None) -if not name: -try: -name = self.instance.__name__ -except AttributeError: -name = '?' raise SignatureError("In call to external function %r:\n" "arg %d must be %s,\n" " got %s" % ( -name, i+1, expected, args_s[i])) +self.name, i+1, expected, args_s[i])) return signature_args def compute_result_annotation(self, *args_s): @@ -42,7 +36,6 @@ s_result = hop.s_result r_result = rtyper.getrepr(s_result) ll_result = r_result.lowleveltype -name = getattr(self, 'name', None) or self.instance.__name__ impl = getattr(self, 'lltypeimpl', None) fakeimpl = getattr(self, 'lltypefakeimpl', self.instance) if impl: @@ -50,7 +43,7 @@ signature_args, s_result) if hasattr(self, 'lltypefakeimpl') and rtyper.backend is llinterp_backend: FT = FuncType(args_ll, ll_result) -obj = functionptr(FT, name, _external_name=self.name, +obj = functionptr(FT, self.name, _external_name=self.name, _callable=fakeimpl) elif isinstance(impl, _ptr): obj = impl @@ -63,7 +56,7 @@ impl, signature_args, hop.s_result) else: FT = FuncType(args_ll, ll_result) -obj = functionptr(FT, name, _external_name=self.name, +obj = functionptr(FT, self.name, _external_name=self.name, _callable=fakeimpl, _safe_not_sandboxed=self.safe_not_sandboxed) vlist = [hop.inputconst(typeOf(obj), obj)] + hop.inputargs(*args_r) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy llimpl: '_fakeimpl' is not used any more
Author: Ronan Lamy Branch: llimpl Changeset: r82111:ec8879a186b6 Date: 2016-02-08 02:35 + http://bitbucket.org/pypy/pypy/changeset/ec8879a186b6/ Log:'_fakeimpl' is not used any more diff --git a/rpython/rtyper/llinterp.py b/rpython/rtyper/llinterp.py --- a/rpython/rtyper/llinterp.py +++ b/rpython/rtyper/llinterp.py @@ -667,14 +667,6 @@ return frame.eval() def op_direct_call(self, f, *args): -pythonfunction = getattr(f._obj, '_fakeimpl', None) -if pythonfunction is not None: -try: -return pythonfunction(*args) -except: -self.make_llexception() -return - FTYPE = lltype.typeOf(f).TO return self.perform_call(f, FTYPE.ARGS, args) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy llimpl: Remove undocumented and unused alternative input types for 'args' in register_external()
Author: Ronan Lamy Branch: llimpl Changeset: r82115:729ec6bd5cd5 Date: 2016-02-08 15:50 + http://bitbucket.org/pypy/pypy/changeset/729ec6bd5cd5/ Log:Remove undocumented and unused alternative input types for 'args' in register_external() diff --git a/rpython/rtyper/extfunc.py b/rpython/rtyper/extfunc.py --- a/rpython/rtyper/extfunc.py +++ b/rpython/rtyper/extfunc.py @@ -1,4 +1,3 @@ -from rpython.tool.sourcetools import func_with_new_name from rpython.rtyper.extregistry import ExtRegistryEntry from rpython.rtyper.lltypesystem.lltype import typeOf, FuncType, functionptr, _ptr from rpython.annotator.model import unionof @@ -88,16 +87,7 @@ class FunEntry(ExtFuncEntry): _about_ = function safe_not_sandboxed = sandboxsafe - -if args is None: -def normalize_args(self, *args_s): -return args_s# accept any argument unmodified -elif callable(args): -# custom annotation normalizer (see e.g. os.utime()) -normalize_args = staticmethod(args) -else: # use common case behavior -signature_args = args - +signature_args = args signature_result = annotation(result, None) name = export_name if llimpl: diff --git a/rpython/rtyper/test/test_extfunc.py b/rpython/rtyper/test/test_extfunc.py --- a/rpython/rtyper/test/test_extfunc.py +++ b/rpython/rtyper/test/test_extfunc.py @@ -121,23 +121,6 @@ s = a.build_types(f, []) assert isinstance(s, SomeInteger) -def test_register_external_specialcase(self): -""" -When args=None, the external function accepts any arguments unmodified. -""" -def function_withspecialcase(arg): -return repr(arg) -register_external(function_withspecialcase, args=None, result=str) - -def f(): -x = function_withspecialcase -return x(33) + x("aaa") + x([]) + "\n" - -policy = AnnotatorPolicy() -a = RPythonAnnotator(policy=policy) -s = a.build_types(f, []) -assert isinstance(s, SomeString) - def test_str0(self): str0 = SomeString(no_nul=True) def os_open(s): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy llimpl: Test register_external(), not its internal implementation
Author: Ronan Lamy Branch: llimpl Changeset: r82116:d159c6726d45 Date: 2016-02-08 17:04 + http://bitbucket.org/pypy/pypy/changeset/d159c6726d45/ Log:Test register_external(), not its internal implementation diff --git a/rpython/rtyper/test/test_extfunc.py b/rpython/rtyper/test/test_extfunc.py --- a/rpython/rtyper/test/test_extfunc.py +++ b/rpython/rtyper/test/test_extfunc.py @@ -1,7 +1,6 @@ import py -from rpython.rtyper.extfunc import ExtFuncEntry, register_external,\ - is_external +from rpython.rtyper.extfunc import register_external from rpython.annotator.model import SomeInteger, SomeString, AnnotatorError from rpython.annotator.annrpython import RPythonAnnotator from rpython.annotator.policy import AnnotatorPolicy @@ -19,11 +18,7 @@ "NOT_RPYTHON" return eval("x+40") -class BTestFuncEntry(ExtFuncEntry): -_about_ = b -name = 'b' -signature_args = [SomeInteger()] -signature_result = SomeInteger() +register_external(b, [int], result=int) def f(): return b(2) @@ -43,15 +38,11 @@ def c(y, x): yyy -class CTestFuncEntry(ExtFuncEntry): -_about_ = c -name = 'ccc' -signature_args = [SomeInteger()] * 2 -signature_result = SomeInteger() +def llimpl(y, x): +return y + x -def lltypeimpl(y, x): -return y + x -lltypeimpl = staticmethod(lltypeimpl) +register_external(c, [int, int], result=int, llimpl=llimpl, + export_name='ccc') def f(): return c(3, 4) @@ -59,22 +50,6 @@ res = interpret(f, []) assert res == 7 -def test_register_external_signature(self): -""" -Test the standard interface for external functions. -""" -def dd(): -pass -register_external(dd, [int], int) - -def f(): -return dd(3) - -policy = AnnotatorPolicy() -a = RPythonAnnotator(policy=policy) -s = a.build_types(f, []) -assert isinstance(s, SomeInteger) - def test_register_external_tuple_args(self): """ Verify the annotation of a registered external function which takes a ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy llimpl: Compute signature eagerly in register_external()
Author: Ronan Lamy Branch: llimpl Changeset: r82119:c1b013088ffd Date: 2016-02-09 02:13 + http://bitbucket.org/pypy/pypy/changeset/c1b013088ffd/ Log:Compute signature eagerly in register_external() diff --git a/rpython/rtyper/extfunc.py b/rpython/rtyper/extfunc.py --- a/rpython/rtyper/extfunc.py +++ b/rpython/rtyper/extfunc.py @@ -6,31 +6,29 @@ class ExtFuncEntry(ExtRegistryEntry): safe_not_sandboxed = False -# common case: args is a list of annotation or types -def normalize_args(self, *args_s): -args = self.signature_args -signature_args = [annotation(arg, None) for arg in args] -assert len(args_s) == len(signature_args),\ +def check_args(self, *args_s): +params_s = self.signature_args +assert len(args_s) == len(params_s),\ "Argument number mismatch" -for i, expected in enumerate(signature_args): -arg = unionof(args_s[i], expected) -if not expected.contains(arg): +for i, s_param in enumerate(params_s): +arg = unionof(args_s[i], s_param) +if not s_param.contains(arg): raise SignatureError("In call to external function %r:\n" "arg %d must be %s,\n" " got %s" % ( -self.name, i+1, expected, args_s[i])) -return signature_args +self.name, i+1, s_param, args_s[i])) +return params_s def compute_result_annotation(self, *args_s): -self.normalize_args(*args_s) # check arguments +self.check_args(*args_s) return self.signature_result def specialize_call(self, hop): from rpython.rtyper.rtyper import llinterp_backend rtyper = hop.rtyper -signature_args = self.normalize_args(*hop.args_s) -args_r = [rtyper.getrepr(s_arg) for s_arg in signature_args] +signature_args = self.signature_args +args_r = [rtyper.getrepr(s_arg) for s_arg in self.signature_args] args_ll = [r_arg.lowleveltype for r_arg in args_r] s_result = hop.s_result r_result = rtyper.getrepr(s_result) @@ -83,23 +81,20 @@ if export_name is None: export_name = function.__name__ +params_s = [annotation(arg) for arg in args] +s_result = annotation(result) class FunEntry(ExtFuncEntry): _about_ = function safe_not_sandboxed = sandboxsafe -signature_args = args -signature_result = annotation(result, None) +signature_args = params_s +signature_result = s_result name = export_name if llimpl: lltypeimpl = staticmethod(llimpl) if llfakeimpl: lltypefakeimpl = staticmethod(llfakeimpl) -if export_name: -FunEntry.__name__ = export_name -else: -FunEntry.__name__ = function.func_name - def is_external(func): if hasattr(func, 'value'): func = func.value ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy llimpl: Sandbox externals during annotation
Author: Ronan Lamy Branch: llimpl Changeset: r82125:e2ae384cca29 Date: 2016-02-09 05:08 + http://bitbucket.org/pypy/pypy/changeset/e2ae384cca29/ Log:Sandbox externals during annotation diff --git a/rpython/rtyper/extfunc.py b/rpython/rtyper/extfunc.py --- a/rpython/rtyper/extfunc.py +++ b/rpython/rtyper/extfunc.py @@ -24,6 +24,16 @@ self.check_args(*args_s) return self.signature_result +def compute_annotation(self): +if (self.bookkeeper.annotator.translator.config.translation.sandbox +and not self.safe_not_sandboxed): +from rpython.translator.sandbox.rsandbox import make_sandbox_trampoline +impl = make_sandbox_trampoline(self.name, self.signature_args, +self.signature_result) +return self.bookkeeper.immutablevalue(impl) +return super(ExtFuncEntry, self).compute_annotation() + + def specialize_call(self, hop): from rpython.rtyper.rtyper import llinterp_backend rtyper = hop.rtyper @@ -36,8 +46,6 @@ impl = getattr(self, 'lltypeimpl', None) fakeimpl = getattr(self, 'lltypefakeimpl', self.instance) if impl: -impl = make_impl(rtyper, impl, self.safe_not_sandboxed, self.name, - signature_args, s_result) if hasattr(self, 'lltypefakeimpl') and rtyper.backend is llinterp_backend: FT = FuncType(args_ll, ll_result) obj = functionptr(FT, self.name, _external_name=self.name, @@ -60,12 +68,6 @@ hop.exception_is_here() return hop.genop('direct_call', vlist, r_result) -def make_impl(rtyper, impl, sandboxsafe, name, args_s, s_result): -if (rtyper.annotator.translator.config.translation.sandbox -and not sandboxsafe): -from rpython.translator.sandbox.rsandbox import make_sandbox_trampoline -impl = make_sandbox_trampoline(name, args_s, s_result) -return impl def register_external(function, args, result=None, export_name=None, llimpl=None, llfakeimpl=None, sandboxsafe=False): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy llimpl: Simplify ExtFuncEntry.specialize_call() by extracting .get_funcptr()
Author: Ronan Lamy Branch: llimpl Changeset: r82126:8ac8fbad47de Date: 2016-02-09 16:16 + http://bitbucket.org/pypy/pypy/changeset/8ac8fbad47de/ Log:Simplify ExtFuncEntry.specialize_call() by extracting .get_funcptr() diff --git a/rpython/rtyper/extfunc.py b/rpython/rtyper/extfunc.py --- a/rpython/rtyper/extfunc.py +++ b/rpython/rtyper/extfunc.py @@ -33,40 +33,41 @@ return self.bookkeeper.immutablevalue(impl) return super(ExtFuncEntry, self).compute_annotation() +def specialize_call(self, hop): +rtyper = hop.rtyper +args_r = [rtyper.getrepr(s_arg) for s_arg in self.signature_args] +r_result = rtyper.getrepr(self.signature_result) +obj = self.get_funcptr(rtyper, args_r, r_result) +vlist = [hop.inputconst(typeOf(obj), obj)] + hop.inputargs(*args_r) +hop.exception_is_here() +return hop.genop('direct_call', vlist, r_result) -def specialize_call(self, hop): +def get_funcptr(self, rtyper, args_r, r_result): from rpython.rtyper.rtyper import llinterp_backend -rtyper = hop.rtyper -signature_args = self.signature_args -args_r = [rtyper.getrepr(s_arg) for s_arg in self.signature_args] args_ll = [r_arg.lowleveltype for r_arg in args_r] -s_result = hop.s_result -r_result = rtyper.getrepr(s_result) ll_result = r_result.lowleveltype impl = getattr(self, 'lltypeimpl', None) fakeimpl = getattr(self, 'lltypefakeimpl', self.instance) if impl: if hasattr(self, 'lltypefakeimpl') and rtyper.backend is llinterp_backend: FT = FuncType(args_ll, ll_result) -obj = functionptr(FT, self.name, _external_name=self.name, -_callable=fakeimpl) +return functionptr( +FT, self.name, _external_name=self.name, +_callable=fakeimpl) elif isinstance(impl, _ptr): -obj = impl +return impl else: # store some attributes to the 'impl' function, where # the eventual call to rtyper.getcallable() will find them # and transfer them to the final lltype.functionptr(). impl._llfnobjattrs_ = {'_name': self.name} -obj = rtyper.getannmixlevel().delayedfunction( -impl, signature_args, hop.s_result) +return rtyper.getannmixlevel().delayedfunction( +impl, self.signature_args, self.signature_result) else: FT = FuncType(args_ll, ll_result) -obj = functionptr(FT, self.name, _external_name=self.name, - _callable=fakeimpl, - _safe_not_sandboxed=self.safe_not_sandboxed) -vlist = [hop.inputconst(typeOf(obj), obj)] + hop.inputargs(*args_r) -hop.exception_is_here() -return hop.genop('direct_call', vlist, r_result) +return functionptr( +FT, self.name, _external_name=self.name, _callable=fakeimpl, +_safe_not_sandboxed=self.safe_not_sandboxed) def register_external(function, args, result=None, export_name=None, ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy llimpl: Fix --sandbox translation
Author: Ronan Lamy Branch: llimpl Changeset: r82247:44df4ef6c185 Date: 2016-02-14 16:39 + http://bitbucket.org/pypy/pypy/changeset/44df4ef6c185/ Log:Fix --sandbox translation diff --git a/rpython/annotator/policy.py b/rpython/annotator/policy.py --- a/rpython/annotator/policy.py +++ b/rpython/annotator/policy.py @@ -3,6 +3,9 @@ from rpython.annotator.specialize import ( specialize_argvalue, specialize_argtype, specialize_arglistitemtype, specialize_arg_or_var, memo, specialize_call_location) +from rpython.flowspace.operation import op +from rpython.flowspace.model import Constant +from rpython.annotator.model import SomeTuple class AnnotatorPolicy(object): @@ -64,7 +67,35 @@ return LowLevelAnnotatorPolicy.specialize__ll_and_arg(*args) def no_more_blocks_to_annotate(pol, annotator): +bk = annotator.bookkeeper # hint to all pending specializers that we are done -for callback in annotator.bookkeeper.pending_specializations: +for callback in bk.pending_specializations: callback() -del annotator.bookkeeper.pending_specializations[:] +del bk.pending_specializations[:] +if annotator.added_blocks is not None: +all_blocks = annotator.added_blocks +else: +all_blocks = annotator.annotated +for block in list(all_blocks): +for i, instr in enumerate(block.operations): +if not isinstance(instr, (op.simple_call, op.call_args)): +continue +v_func = instr.args[0] +s_func = annotator.annotation(v_func) +if not hasattr(s_func, 'needs_sandboxing'): +continue +key = ('sandboxing', s_func.const) +if key not in bk.emulated_pbc_calls: +entry = s_func.entry +params_s = entry.signature_args +s_result = entry.signature_result +from rpython.translator.sandbox.rsandbox import make_sandbox_trampoline +sandbox_trampoline = make_sandbox_trampoline( +entry.name, params_s, s_result) +sandbox_trampoline._signature_ = [SomeTuple(items=params_s)], s_result +bk.emulate_pbc_call(key, bk.immutablevalue(sandbox_trampoline), params_s) +else: +s_trampoline = bk.emulated_pbc_calls[key][0] +sandbox_trampoline = s_trampoline.const +new = instr.replace({instr.args[0]: Constant(sandbox_trampoline)}) +block.operations[i] = new diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py --- a/rpython/annotator/unaryop.py +++ b/rpython/annotator/unaryop.py @@ -113,8 +113,9 @@ @op.simple_call.register(SomeObject) def simple_call_SomeObject(annotator, func, *args): -return annotator.annotation(func).call( -simple_args([annotator.annotation(arg) for arg in args])) +s_func = annotator.annotation(func) +argspec = simple_args([annotator.annotation(arg) for arg in args]) +return s_func.call(argspec) @op.call_args.register_transform(SomeObject) def transform_varargs(annotator, v_func, v_shape, *data_v): diff --git a/rpython/rtyper/extfunc.py b/rpython/rtyper/extfunc.py --- a/rpython/rtyper/extfunc.py +++ b/rpython/rtyper/extfunc.py @@ -25,13 +25,12 @@ return self.signature_result def compute_annotation(self): +s_result = super(ExtFuncEntry, self).compute_annotation() if (self.bookkeeper.annotator.translator.config.translation.sandbox and not self.safe_not_sandboxed): -from rpython.translator.sandbox.rsandbox import make_sandbox_trampoline -impl = make_sandbox_trampoline(self.name, self.signature_args, -self.signature_result) -return self.bookkeeper.immutablevalue(impl) -return super(ExtFuncEntry, self).compute_annotation() +s_result.needs_sandboxing = True +s_result.entry = self +return s_result def specialize_call(self, hop): rtyper = hop.rtyper diff --git a/rpython/translator/sandbox/test/test_sandbox.py b/rpython/translator/sandbox/test/test_sandbox.py --- a/rpython/translator/sandbox/test/test_sandbox.py +++ b/rpython/translator/sandbox/test/test_sandbox.py @@ -292,6 +292,21 @@ rescode = pipe.wait() assert rescode == 0 +def test_environ_items(): +def entry_point(argv): +print os.environ.items() +return 0 + +exe = compile(entry_point) +g, f = run_in_subprocess(exe) +expect(f, g, "ll_os.ll_os_envitems", (), []) +expect(f, g, "ll_os.ll_os_write", (1, "[]\n"), 3) +g.close() +tail = f.read() +f.close() +assert tail == "" + + class TestPrintedResults: def run(self, entry_point, args, expected): ___ pypy-co
[pypy-commit] pypy default: Remove dead code: Bookkeeper._find_current_op()
Author: Ronan Lamy Branch: Changeset: r82271:4bec5c63bc9e Date: 2016-02-15 17:42 + http://bitbucket.org/pypy/pypy/changeset/4bec5c63bc9e/ Log:Remove dead code: Bookkeeper._find_current_op() diff --git a/rpython/annotator/bookkeeper.py b/rpython/annotator/bookkeeper.py --- a/rpython/annotator/bookkeeper.py +++ b/rpython/annotator/bookkeeper.py @@ -551,20 +551,6 @@ emulated = callback return self.pbc_call(pbc, args, emulated=emulated) -def _find_current_op(self, opname=None, arity=None, pos=None, s_type=None): -""" Find operation that is currently being annotated. Do some -sanity checks to see whether the correct op was found.""" -# XXX XXX HACK HACK HACK -fn, block, i = self.position_key -op = block.operations[i] -if opname is not None: -assert op.opname == opname -if arity is not None: -assert len(op.args) == arity -if pos is not None: -assert self.annotator.binding(op.args[pos]) == s_type -return op - def whereami(self): return self.annotator.whereami(self.position_key) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy llimpl: Create SomeExternalFunction, clean up signature checking and sandboxing of externals
Author: Ronan Lamy Branch: llimpl Changeset: r82275:7b8f4a3f1bd2 Date: 2016-02-16 04:17 + http://bitbucket.org/pypy/pypy/changeset/7b8f4a3f1bd2/ Log:Create SomeExternalFunction, clean up signature checking and sandboxing of externals diff --git a/rpython/annotator/policy.py b/rpython/annotator/policy.py --- a/rpython/annotator/policy.py +++ b/rpython/annotator/policy.py @@ -86,12 +86,11 @@ continue key = ('sandboxing', s_func.const) if key not in bk.emulated_pbc_calls: -entry = s_func.entry -params_s = entry.signature_args -s_result = entry.signature_result +params_s = s_func.args_s +s_result = s_func.s_result from rpython.translator.sandbox.rsandbox import make_sandbox_trampoline sandbox_trampoline = make_sandbox_trampoline( -entry.name, params_s, s_result) +s_func.name, params_s, s_result) sandbox_trampoline._signature_ = [SomeTuple(items=params_s)], s_result bk.emulate_pbc_call(key, bk.immutablevalue(sandbox_trampoline), params_s) else: diff --git a/rpython/rtyper/extfunc.py b/rpython/rtyper/extfunc.py --- a/rpython/rtyper/extfunc.py +++ b/rpython/rtyper/extfunc.py @@ -1,16 +1,22 @@ from rpython.rtyper.extregistry import ExtRegistryEntry from rpython.rtyper.lltypesystem.lltype import typeOf, FuncType, functionptr, _ptr -from rpython.annotator.model import unionof +from rpython.annotator.model import unionof, SomeBuiltin from rpython.annotator.signature import annotation, SignatureError -class ExtFuncEntry(ExtRegistryEntry): -safe_not_sandboxed = False +class SomeExternalFunction(SomeBuiltin): +def __init__(self, name, args_s, s_result): +self.name = name +self.args_s = args_s +self.s_result = s_result -def check_args(self, *args_s): -params_s = self.signature_args -assert len(args_s) == len(params_s),\ - "Argument number mismatch" - +def check_args(self, callspec): +params_s = self.args_s +args_s, kwargs = callspec.unpack() +if kwargs: +raise SignatureError( +"External functions cannot be called with keyword arguments") +if len(args_s) != len(params_s): +raise SignatureError("Argument number mismatch") for i, s_param in enumerate(params_s): arg = unionof(args_s[i], s_param) if not s_param.contains(arg): @@ -18,18 +24,20 @@ "arg %d must be %s,\n" " got %s" % ( self.name, i+1, s_param, args_s[i])) -return params_s -def compute_result_annotation(self, *args_s): -self.check_args(*args_s) -return self.signature_result +def call(self, callspec): +self.check_args(callspec) +return self.s_result + +class ExtFuncEntry(ExtRegistryEntry): +safe_not_sandboxed = False def compute_annotation(self): -s_result = super(ExtFuncEntry, self).compute_annotation() +s_result = SomeExternalFunction( +self.name, self.signature_args, self.signature_result) if (self.bookkeeper.annotator.translator.config.translation.sandbox and not self.safe_not_sandboxed): s_result.needs_sandboxing = True -s_result.entry = self return s_result def specialize_call(self, hop): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy llimpl: hg merge default
Author: Ronan Lamy Branch: llimpl Changeset: r82274:e6a89c683651 Date: 2016-02-15 17:45 + http://bitbucket.org/pypy/pypy/changeset/e6a89c683651/ Log:hg merge default diff too long, truncating to 2000 out of 3299 lines diff --git a/lib-python/2.7/distutils/command/build_ext.py b/lib-python/2.7/distutils/command/build_ext.py --- a/lib-python/2.7/distutils/command/build_ext.py +++ b/lib-python/2.7/distutils/command/build_ext.py @@ -188,7 +188,7 @@ # the 'libs' directory is for binary installs - we assume that # must be the *native* platform. But we don't really support # cross-compiling via a binary install anyway, so we let it go. -self.library_dirs.append(os.path.join(sys.exec_prefix, 'include')) +self.library_dirs.append(os.path.join(sys.exec_prefix, 'libs')) if self.debug: self.build_temp = os.path.join(self.build_temp, "Debug") else: diff --git a/lib_pypy/cffi.egg-info/PKG-INFO b/lib_pypy/cffi.egg-info/PKG-INFO --- a/lib_pypy/cffi.egg-info/PKG-INFO +++ b/lib_pypy/cffi.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: cffi -Version: 1.5.0 +Version: 1.5.2 Summary: Foreign Function Interface for Python calling C code. Home-page: http://cffi.readthedocs.org Author: Armin Rigo, Maciej Fijalkowski diff --git a/lib_pypy/cffi/__init__.py b/lib_pypy/cffi/__init__.py --- a/lib_pypy/cffi/__init__.py +++ b/lib_pypy/cffi/__init__.py @@ -4,8 +4,8 @@ from .api import FFI, CDefError, FFIError from .ffiplatform import VerificationError, VerificationMissing -__version__ = "1.5.0" -__version_info__ = (1, 5, 0) +__version__ = "1.5.2" +__version_info__ = (1, 5, 2) # The verifier module file names are based on the CRC32 of a string that # contains the following version number. It may be older than __version__ diff --git a/lib_pypy/cffi/_cffi_include.h b/lib_pypy/cffi/_cffi_include.h --- a/lib_pypy/cffi/_cffi_include.h +++ b/lib_pypy/cffi/_cffi_include.h @@ -231,6 +231,12 @@ ((got_nonpos) == (expected <= 0) && \ (got) == (unsigned long long)expected) +#ifdef MS_WIN32 +# define _cffi_stdcall __stdcall +#else +# define _cffi_stdcall /* nothing */ +#endif + #ifdef __cplusplus } #endif diff --git a/lib_pypy/cffi/_embedding.h b/lib_pypy/cffi/_embedding.h new file mode 100644 --- /dev/null +++ b/lib_pypy/cffi/_embedding.h @@ -0,0 +1,517 @@ + +/* Support code for embedding */ + +#if defined(_MSC_VER) +# define CFFI_DLLEXPORT __declspec(dllexport) +#elif defined(__GNUC__) +# define CFFI_DLLEXPORT __attribute__((visibility("default"))) +#else +# define CFFI_DLLEXPORT /* nothing */ +#endif + + +/* There are two global variables of type _cffi_call_python_fnptr: + + * _cffi_call_python, which we declare just below, is the one called + by ``extern "Python"`` implementations. + + * _cffi_call_python_org, which on CPython is actually part of the + _cffi_exports[] array, is the function pointer copied from + _cffi_backend. + + After initialization is complete, both are equal. However, the + first one remains equal to &_cffi_start_and_call_python until the + very end of initialization, when we are (or should be) sure that + concurrent threads also see a completely initialized world, and + only then is it changed. +*/ +#undef _cffi_call_python +typedef void (*_cffi_call_python_fnptr)(struct _cffi_externpy_s *, char *); +static void _cffi_start_and_call_python(struct _cffi_externpy_s *, char *); +static _cffi_call_python_fnptr _cffi_call_python = &_cffi_start_and_call_python; + + +#ifndef _MSC_VER + /* --- Assuming a GCC not infinitely old --- */ +# define cffi_compare_and_swap(l,o,n) __sync_bool_compare_and_swap(l,o,n) +# define cffi_write_barrier() __sync_synchronize() +# if !defined(__amd64__) && !defined(__x86_64__) && \ + !defined(__i386__) && !defined(__i386) +# define cffi_read_barrier() __sync_synchronize() +# else +# define cffi_read_barrier() (void)0 +# endif +#else + /* --- Windows threads version --- */ +# include +# define cffi_compare_and_swap(l,o,n) \ + (InterlockedCompareExchangePointer(l,n,o) == (o)) +# define cffi_write_barrier() InterlockedCompareExchange(&_cffi_dummy,0,0) +# define cffi_read_barrier() (void)0 +static volatile LONG _cffi_dummy; +#endif + +#ifdef WITH_THREAD +# ifndef _MSC_VER +# include + static pthread_mutex_t _cffi_embed_startup_lock; +# else + static CRITICAL_SECTION _cffi_embed_startup_lock; +# endif + static char _cffi_embed_startup_lock_ready = 0; +#endif + +static void _cffi_acquire_reentrant_mutex(void) +{ +static void *volatile lock = NULL; + +while (!cffi_compare_and_swap(&lock, NULL, (void *)1)) { +/* should ideally do a spin loop instruction here, but + hard to do it portably and doesn't really matter I + think: pthread_mutex_init() should be very fas
[pypy-commit] pypy llimpl: SomeExternalFunction does not subclass SomeBuiltin any more
Author: Ronan Lamy Branch: llimpl Changeset: r82298:25d639caec04 Date: 2016-02-16 05:02 + http://bitbucket.org/pypy/pypy/changeset/25d639caec04/ Log:SomeExternalFunction does not subclass SomeBuiltin any more diff --git a/rpython/rtyper/extfunc.py b/rpython/rtyper/extfunc.py --- a/rpython/rtyper/extfunc.py +++ b/rpython/rtyper/extfunc.py @@ -1,9 +1,12 @@ +from rpython.annotator.model import unionof, SomeObject +from rpython.annotator.signature import annotation, SignatureError from rpython.rtyper.extregistry import ExtRegistryEntry -from rpython.rtyper.lltypesystem.lltype import typeOf, FuncType, functionptr, _ptr -from rpython.annotator.model import unionof, SomeBuiltin -from rpython.annotator.signature import annotation, SignatureError +from rpython.rtyper.lltypesystem.lltype import ( +typeOf, FuncType, functionptr, _ptr) +from rpython.rtyper.error import TyperError +from rpython.rtyper.rbuiltin import BuiltinFunctionRepr -class SomeExternalFunction(SomeBuiltin): +class SomeExternalFunction(SomeObject): def __init__(self, name, args_s, s_result): self.name = name self.args_s = args_s @@ -20,21 +23,31 @@ for i, s_param in enumerate(params_s): arg = unionof(args_s[i], s_param) if not s_param.contains(arg): -raise SignatureError("In call to external function %r:\n" -"arg %d must be %s,\n" -" got %s" % ( -self.name, i+1, s_param, args_s[i])) +raise SignatureError( +"In call to external function %r:\n" +"arg %d must be %s,\n" +" got %s" % ( +self.name, i + 1, s_param, args_s[i])) def call(self, callspec): self.check_args(callspec) return self.s_result +def rtyper_makerepr(self, rtyper): +if not self.is_constant(): +raise TyperError("Non-constant external function!") +return BuiltinFunctionRepr(self.const) + +def rtyper_makekey(self): +return self.__class__, self.const + + class ExtFuncEntry(ExtRegistryEntry): safe_not_sandboxed = False def compute_annotation(self): s_result = SomeExternalFunction( -self.name, self.signature_args, self.signature_result) +self.name, self.signature_args, self.signature_result) if (self.bookkeeper.annotator.translator.config.translation.sandbox and not self.safe_not_sandboxed): s_result.needs_sandboxing = True ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy llimpl: Create ExternalFunctionRepr
Author: Ronan Lamy Branch: llimpl Changeset: r82299:24d569eefdf9 Date: 2016-02-16 18:13 + http://bitbucket.org/pypy/pypy/changeset/24d569eefdf9/ Log:Create ExternalFunctionRepr diff --git a/rpython/rtyper/extfunc.py b/rpython/rtyper/extfunc.py --- a/rpython/rtyper/extfunc.py +++ b/rpython/rtyper/extfunc.py @@ -1,10 +1,10 @@ from rpython.annotator.model import unionof, SomeObject from rpython.annotator.signature import annotation, SignatureError -from rpython.rtyper.extregistry import ExtRegistryEntry +from rpython.rtyper.extregistry import ExtRegistryEntry, lookup from rpython.rtyper.lltypesystem.lltype import ( -typeOf, FuncType, functionptr, _ptr) +typeOf, FuncType, functionptr, _ptr, Void) from rpython.rtyper.error import TyperError -from rpython.rtyper.rbuiltin import BuiltinFunctionRepr +from rpython.rtyper.rmodel import Repr class SomeExternalFunction(SomeObject): def __init__(self, name, args_s, s_result): @@ -36,10 +36,58 @@ def rtyper_makerepr(self, rtyper): if not self.is_constant(): raise TyperError("Non-constant external function!") -return BuiltinFunctionRepr(self.const) +entry = lookup(self.const) +impl = getattr(entry, 'lltypeimpl', None) +fakeimpl = getattr(entry, 'lltypefakeimpl', None) +return ExternalFunctionRepr(self, impl, fakeimpl) def rtyper_makekey(self): -return self.__class__, self.const +return self.__class__, self + +class ExternalFunctionRepr(Repr): +lowleveltype = Void + +def __init__(self, s_func, impl, fakeimpl): +self.s_func = s_func +self.impl = impl +self.fakeimpl = fakeimpl + +def rtype_simple_call(self, hop): +rtyper = hop.rtyper +args_r = [rtyper.getrepr(s_arg) for s_arg in self.s_func.args_s] +r_result = rtyper.getrepr(self.s_func.s_result) +obj = self.get_funcptr(rtyper, args_r, r_result) +hop2 = hop.copy() +hop2.r_s_popfirstarg() +vlist = [hop2.inputconst(typeOf(obj), obj)] + hop2.inputargs(*args_r) +hop2.exception_is_here() +return hop2.genop('direct_call', vlist, r_result) + +def get_funcptr(self, rtyper, args_r, r_result): +from rpython.rtyper.rtyper import llinterp_backend +args_ll = [r_arg.lowleveltype for r_arg in args_r] +ll_result = r_result.lowleveltype +name = self.s_func.name +fakeimpl = getattr(self, 'lltypefakeimpl', self.s_func.const) +if self.impl: +if self.fakeimpl and rtyper.backend is llinterp_backend: +FT = FuncType(args_ll, ll_result) +return functionptr( +FT, name, _external_name=name, _callable=fakeimpl) +elif isinstance(self.impl, _ptr): +return self.impl +else: +# store some attributes to the 'impl' function, where +# the eventual call to rtyper.getcallable() will find them +# and transfer them to the final lltype.functionptr(). +self.impl._llfnobjattrs_ = {'_name': name} +return rtyper.getannmixlevel().delayedfunction( +self.impl, self.s_func.args_s, self.s_func.s_result) +else: +fakeimpl = self.fakeimpl or self.s_func.const +FT = FuncType(args_ll, ll_result) +return functionptr( +FT, name, _external_name=name, _callable=fakeimpl) class ExtFuncEntry(ExtRegistryEntry): @@ -53,42 +101,6 @@ s_result.needs_sandboxing = True return s_result -def specialize_call(self, hop): -rtyper = hop.rtyper -args_r = [rtyper.getrepr(s_arg) for s_arg in self.signature_args] -r_result = rtyper.getrepr(self.signature_result) -obj = self.get_funcptr(rtyper, args_r, r_result) -vlist = [hop.inputconst(typeOf(obj), obj)] + hop.inputargs(*args_r) -hop.exception_is_here() -return hop.genop('direct_call', vlist, r_result) - -def get_funcptr(self, rtyper, args_r, r_result): -from rpython.rtyper.rtyper import llinterp_backend -args_ll = [r_arg.lowleveltype for r_arg in args_r] -ll_result = r_result.lowleveltype -impl = getattr(self, 'lltypeimpl', None) -fakeimpl = getattr(self, 'lltypefakeimpl', self.instance) -if impl: -if hasattr(self, 'lltypefakeimpl') and rtyper.backend is llinterp_backend: -FT = FuncType(args_ll, ll_result) -return functionptr( -FT, self.name, _external_name=self.name, -_callable=fakeimpl) -elif isinstance(impl, _ptr): -return impl -else: -# store some attributes to the 'impl' function, where -# the eventual call to rtyper.getcallable() will find them -# and transfer them to the final lltype.functionptr(). -
[pypy-commit] pypy default: update whatsnew
Author: Ronan Lamy Branch: Changeset: r82317:1b11375c5116 Date: 2016-02-17 23:00 + http://bitbucket.org/pypy/pypy/changeset/1b11375c5116/ Log:update whatsnew diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst --- a/pypy/doc/whatsnew-head.rst +++ b/pypy/doc/whatsnew-head.rst @@ -152,3 +152,9 @@ Seperate structmember.h from Python.h Also enhance creating api functions to specify which header file they appear in (previously only pypy_decl.h) + +.. branch: llimpl + +Refactor register_external(), remove running_on_llinterp mechanism and +apply sandbox transform on externals at the end of annotation. + ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy llimpl: Close branch before merging
Author: Ronan Lamy Branch: llimpl Changeset: r82315:691635e5fdfb Date: 2016-02-17 22:56 + http://bitbucket.org/pypy/pypy/changeset/691635e5fdfb/ Log:Close branch before merging ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Merge branch 'llimpl'
Author: Ronan Lamy Branch: Changeset: r82316:4c30448f0457 Date: 2016-02-17 22:59 + http://bitbucket.org/pypy/pypy/changeset/4c30448f0457/ Log:Merge branch 'llimpl' Refactor register_external(), remove running_on_llinterp mechanism and apply sandbox transform on externals at the end of annotation. diff --git a/rpython/annotator/policy.py b/rpython/annotator/policy.py --- a/rpython/annotator/policy.py +++ b/rpython/annotator/policy.py @@ -3,6 +3,9 @@ from rpython.annotator.specialize import ( specialize_argvalue, specialize_argtype, specialize_arglistitemtype, specialize_arg_or_var, memo, specialize_call_location) +from rpython.flowspace.operation import op +from rpython.flowspace.model import Constant +from rpython.annotator.model import SomeTuple class AnnotatorPolicy(object): @@ -64,7 +67,34 @@ return LowLevelAnnotatorPolicy.specialize__ll_and_arg(*args) def no_more_blocks_to_annotate(pol, annotator): +bk = annotator.bookkeeper # hint to all pending specializers that we are done -for callback in annotator.bookkeeper.pending_specializations: +for callback in bk.pending_specializations: callback() -del annotator.bookkeeper.pending_specializations[:] +del bk.pending_specializations[:] +if annotator.added_blocks is not None: +all_blocks = annotator.added_blocks +else: +all_blocks = annotator.annotated +for block in list(all_blocks): +for i, instr in enumerate(block.operations): +if not isinstance(instr, (op.simple_call, op.call_args)): +continue +v_func = instr.args[0] +s_func = annotator.annotation(v_func) +if not hasattr(s_func, 'needs_sandboxing'): +continue +key = ('sandboxing', s_func.const) +if key not in bk.emulated_pbc_calls: +params_s = s_func.args_s +s_result = s_func.s_result +from rpython.translator.sandbox.rsandbox import make_sandbox_trampoline +sandbox_trampoline = make_sandbox_trampoline( +s_func.name, params_s, s_result) +sandbox_trampoline._signature_ = [SomeTuple(items=params_s)], s_result +bk.emulate_pbc_call(key, bk.immutablevalue(sandbox_trampoline), params_s) +else: +s_trampoline = bk.emulated_pbc_calls[key][0] +sandbox_trampoline = s_trampoline.const +new = instr.replace({instr.args[0]: Constant(sandbox_trampoline)}) +block.operations[i] = new diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py --- a/rpython/annotator/unaryop.py +++ b/rpython/annotator/unaryop.py @@ -113,8 +113,9 @@ @op.simple_call.register(SomeObject) def simple_call_SomeObject(annotator, func, *args): -return annotator.annotation(func).call( -simple_args([annotator.annotation(arg) for arg in args])) +s_func = annotator.annotation(func) +argspec = simple_args([annotator.annotation(arg) for arg in args]) +return s_func.call(argspec) @op.call_args.register_transform(SomeObject) def transform_varargs(annotator, v_func, v_shape, *data_v): diff --git a/rpython/memory/gctransform/test/test_transform.py b/rpython/memory/gctransform/test/test_transform.py --- a/rpython/memory/gctransform/test/test_transform.py +++ b/rpython/memory/gctransform/test/test_transform.py @@ -5,6 +5,7 @@ from rpython.translator.exceptiontransform import ExceptionTransformer from rpython.rtyper.lltypesystem import lltype from rpython.conftest import option +from rpython.rtyper.rtyper import llinterp_backend class LLInterpedTranformerTests: @@ -131,8 +132,10 @@ def rtype(func, inputtypes, specialize=True): t = TranslationContext() t.buildannotator().build_types(func, inputtypes) +rtyper = t.buildrtyper() +rtyper.backend = llinterp_backend if specialize: -t.buildrtyper().specialize() +rtyper.specialize() if option.view: t.view() return t diff --git a/rpython/memory/test/test_transformed_gc.py b/rpython/memory/test/test_transformed_gc.py --- a/rpython/memory/test/test_transformed_gc.py +++ b/rpython/memory/test/test_transformed_gc.py @@ -14,6 +14,7 @@ from rpython.conftest import option from rpython.rlib.rstring import StringBuilder from rpython.rlib.rarithmetic import LONG_BIT +from rpython.rtyper.rtyper import llinterp_backend WORD = LONG_BIT // 8 @@ -29,9 +30,11 @@ t.config.set(**extraconfigopts) ann = t.buildannotator() ann.build_types(func, inputtypes) +rtyper = t.buildrtyper() +rtyper.backend = llinterp_backend if specialize: -t.buildrtyper().specialize() +rtyper.specialize() if backendopt: from rpython.translator.ba
[pypy-commit] pypy default: kill unused make_constgraphbuilder()
Author: Ronan Lamy Branch: Changeset: r82318:6f907027fbb2 Date: 2016-02-17 23:18 + http://bitbucket.org/pypy/pypy/changeset/6f907027fbb2/ Log:kill unused make_constgraphbuilder() diff --git a/rpython/annotator/specialize.py b/rpython/annotator/specialize.py --- a/rpython/annotator/specialize.py +++ b/rpython/annotator/specialize.py @@ -317,18 +317,6 @@ yield (value,) + tuple_tail -def make_constgraphbuilder(n, v=None, factory=None, srcmodule=None): -def constgraphbuilder(translator, ignore): -args = ','.join(["arg%d" % i for i in range(n)]) -if factory is not None: -computed_v = factory() -else: -computed_v = v -miniglobals = {'v': computed_v, '__name__': srcmodule} -exec py.code.Source("constf = lambda %s: v" % args).compile() in miniglobals -return translator.buildflowgraph(miniglobals['constf']) -return constgraphbuilder - def maybe_star_args(funcdesc, key, args_s): args_s, key1, builder = flatten_star_args(funcdesc, args_s) if key1 is not None: diff --git a/rpython/rtyper/test/test_rpbc.py b/rpython/rtyper/test/test_rpbc.py --- a/rpython/rtyper/test/test_rpbc.py +++ b/rpython/rtyper/test/test_rpbc.py @@ -1,7 +1,7 @@ import py from rpython.annotator import model as annmodel -from rpython.annotator import policy, specialize +from rpython.annotator import specialize from rpython.rtyper.lltypesystem.lltype import typeOf from rpython.rtyper.test.tool import BaseRtypingTest from rpython.rtyper.llannotation import SomePtr, lltype_to_annotation @@ -1690,59 +1690,6 @@ # -class TestRPBCExtra(BaseRtypingTest): - -def test_folding_specialize_support(self): - -class S(object): - -def w(s, x): -if isinstance(x, int): -return x -if isinstance(x, str): -return len(x) -return -1 -w._annspecialcase_ = "specialize:w" - -def _freeze_(self): -return True - -s = S() - -def f(i, n): -w = s.w -if i == 0: -return w(0) -elif i == 1: -return w("abc") -elif i == 2: -return w(3*n) -elif i == 3: -return w(str(n)) -return -1 - -class P(policy.AnnotatorPolicy): -def specialize__w(pol, funcdesc, args_s): -typ = args_s[1].knowntype -if args_s[0].is_constant() and args_s[1].is_constant(): -x = args_s[1].const -v = s.w(x) -builder = specialize.make_constgraphbuilder(2, v) -return funcdesc.cachedgraph(x, builder=builder) -return funcdesc.cachedgraph(typ) - -p = P() - -res = self.interpret(f, [0, 66], policy=p) -assert res == 0 -res = self.interpret(f, [1, 66], policy=p) -assert res == 3 -res = self.interpret(f, [2, 4], policy=p) -assert res == 12 -res = self.interpret(f, [3, ], policy=p) -assert res == 4 - - def test_hlinvoke_simple(): def f(a,b): return a + b ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy desc-specialize: Create annotator.using_policy() context manager
Author: Ronan Lamy Branch: desc-specialize Changeset: r82327:f979a9068595 Date: 2016-02-19 17:16 + http://bitbucket.org/pypy/pypy/changeset/f979a9068595/ Log:Create annotator.using_policy() context manager diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py --- a/rpython/annotator/annrpython.py +++ b/rpython/annotator/annrpython.py @@ -2,6 +2,7 @@ import types from collections import defaultdict +from contextlib import contextmanager from rpython.tool.ansi_print import ansi_log from rpython.tool.pairtype import pair @@ -89,14 +90,9 @@ def get_call_parameters(self, function, args_s, policy): desc = self.bookkeeper.getdesc(function) -prevpolicy = self.policy -self.policy = policy -self.bookkeeper.enter(None) -try: -return desc.get_call_parameters(args_s) -finally: -self.bookkeeper.leave() -self.policy = prevpolicy +with self.using_policy(policy): +with self.bookkeeper.at_position(None): +return desc.get_call_parameters(args_s) def annotate_helper(self, function, args_s, policy=None): if policy is None: @@ -111,15 +107,23 @@ return graph def complete_helpers(self, policy): -saved = self.policy, self.added_blocks +saved = self.added_blocks +self.added_blocks = {} +with self.using_policy(policy): +try: +self.complete() +# invoke annotation simplifications for the new blocks +self.simplify(block_subset=self.added_blocks) +finally: +self.added_blocks = saved + +@contextmanager +def using_policy(self, policy): +"""A context manager that temporarily replaces the annotator policy""" +old_policy = self.policy self.policy = policy -try: -self.added_blocks = {} -self.complete() -# invoke annotation simplifications for the new blocks -self.simplify(block_subset=self.added_blocks) -finally: -self.policy, self.added_blocks = saved +yield +self.policy = old_policy def build_graph_types(self, flowgraph, inputcells, complete_now=True): checkgraph(flowgraph) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy desc-specialize: Extract method init_specializer()
Author: Ronan Lamy Branch: desc-specialize Changeset: r82326:0b89e9760cd8 Date: 2016-02-18 05:23 + http://bitbucket.org/pypy/pypy/changeset/0b89e9760cd8/ Log:Extract method init_specializer() diff --git a/rpython/annotator/description.py b/rpython/annotator/description.py --- a/rpython/annotator/description.py +++ b/rpython/annotator/description.py @@ -283,17 +283,20 @@ (self.name, e.getmsg())) return inputcells -def specialize(self, inputcells, op=None): -if (op is None and -getattr(self.bookkeeper, "position_key", None) is not None): -_, block, i = self.bookkeeper.position_key -op = block.operations[i] +def init_specializer(self): if self.specializer is None: # get the specializer based on the tag of the 'pyobj' # (if any), according to the current policy tag = getattr(self.pyobj, '_annspecialcase_', None) policy = self.bookkeeper.annotator.policy self.specializer = policy.get_specializer(tag) + +def specialize(self, inputcells, op=None): +if (op is None and +getattr(self.bookkeeper, "position_key", None) is not None): +_, block, i = self.bookkeeper.position_key +op = block.operations[i] +self.init_specializer() enforceargs = getattr(self.pyobj, '_annenforceargs_', None) signature = getattr(self.pyobj, '_signature_', None) if enforceargs and signature: ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy desc-specialize: Initialize funcdesc.specializer in FunctionDesc.__init__ and ensure the right annotator policy is active at the time
Author: Ronan Lamy Branch: desc-specialize Changeset: r82339:cf1b6e045f41 Date: 2016-02-20 10:19 + http://bitbucket.org/pypy/pypy/changeset/cf1b6e045f41/ Log:Initialize funcdesc.specializer in FunctionDesc.__init__ and ensure the right annotator policy is active at the time diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py --- a/rpython/annotator/annrpython.py +++ b/rpython/annotator/annrpython.py @@ -82,17 +82,17 @@ annmodel.TLS.check_str_without_nul = ( self.translator.config.translation.check_str_without_nul) -flowgraph, inputs_s = self.get_call_parameters(function, args_s, policy) +with self.using_policy(policy): +flowgraph, inputs_s = self.get_call_parameters(function, args_s) if main_entry_point: self.translator.entry_point_graph = flowgraph return self.build_graph_types(flowgraph, inputs_s, complete_now=complete_now) -def get_call_parameters(self, function, args_s, policy): -desc = self.bookkeeper.getdesc(function) -with self.using_policy(policy): -with self.bookkeeper.at_position(None): -return desc.get_call_parameters(args_s) +def get_call_parameters(self, function, args_s): +with self.bookkeeper.at_position(None): +desc = self.bookkeeper.getdesc(function) +return desc.get_call_parameters(args_s) def annotate_helper(self, function, args_s, policy=None): if policy is None: @@ -101,21 +101,21 @@ # XXX hack annmodel.TLS.check_str_without_nul = ( self.translator.config.translation.check_str_without_nul) -graph, inputcells = self.get_call_parameters(function, args_s, policy) -self.build_graph_types(graph, inputcells, complete_now=False) -self.complete_helpers(policy) +with self.using_policy(policy): +graph, inputcells = self.get_call_parameters(function, args_s) +self.build_graph_types(graph, inputcells, complete_now=False) +self.complete_helpers() return graph -def complete_helpers(self, policy): +def complete_helpers(self): saved = self.added_blocks self.added_blocks = {} -with self.using_policy(policy): -try: -self.complete() -# invoke annotation simplifications for the new blocks -self.simplify(block_subset=self.added_blocks) -finally: -self.added_blocks = saved +try: +self.complete() +# invoke annotation simplifications for the new blocks +self.simplify(block_subset=self.added_blocks) +finally: +self.added_blocks = saved @contextmanager def using_policy(self, policy): diff --git a/rpython/annotator/description.py b/rpython/annotator/description.py --- a/rpython/annotator/description.py +++ b/rpython/annotator/description.py @@ -214,6 +214,7 @@ # specializer(funcdesc, args_s) => graph # or => s_result (overridden/memo cases) self.specializer = specializer +self.init_specializer() self._cache = {} # convenience for the specializer def buildgraph(self, alt_name=None, builder=None): @@ -296,7 +297,6 @@ getattr(self.bookkeeper, "position_key", None) is not None): _, block, i = self.bookkeeper.position_key op = block.operations[i] -self.init_specializer() enforceargs = getattr(self.pyobj, '_annenforceargs_', None) signature = getattr(self.pyobj, '_signature_', None) if enforceargs and signature: diff --git a/rpython/rtyper/annlowlevel.py b/rpython/rtyper/annlowlevel.py --- a/rpython/rtyper/annlowlevel.py +++ b/rpython/rtyper/annlowlevel.py @@ -138,11 +138,12 @@ # get the graph of the mix-level helper ll_function and prepare it for # being annotated. Annotation and RTyping should be done in a single shot # at the end with finish(). -graph, args_s = self.rtyper.annotator.get_call_parameters( -ll_function, args_s, policy = self.policy) +ann = self.rtyper.annotator +with ann.using_policy(self.policy): +graph, args_s = ann.get_call_parameters(ll_function, args_s) for v_arg, s_arg in zip(graph.getargs(), args_s): -self.rtyper.annotator.setbinding(v_arg, s_arg) -self.rtyper.annotator.setbinding(graph.getreturnvar(), s_result) +ann.setbinding(v_arg, s_arg) +ann.setbinding(graph.getreturnvar(), s_result) #self.rtyper.annotator.annotated[graph.returnblock] = graph self.pending.append((ll_function, graph, args_s, s_result)) return graph @@ -224,16 +225,17 @@ bk = ann.bookkeeper translator = ann.translator original_graph_cou
[pypy-commit] pypy desc-specialize: Simplify FunctionDesc.__init__ and use factory method bk.newfuncdesc() instead
Author: Ronan Lamy Branch: desc-specialize Changeset: r82352:fe52b15deb73 Date: 2016-02-20 13:51 + http://bitbucket.org/pypy/pypy/changeset/fe52b15deb73/ Log:Simplify FunctionDesc.__init__ and use factory method bk.newfuncdesc() instead diff --git a/rpython/annotator/bookkeeper.py b/rpython/annotator/bookkeeper.py --- a/rpython/annotator/bookkeeper.py +++ b/rpython/annotator/bookkeeper.py @@ -9,6 +9,7 @@ from collections import OrderedDict from rpython.flowspace.model import Constant +from rpython.flowspace.bytecode import cpython_code_signature from rpython.annotator.model import ( SomeOrderedDict, SomeString, SomeChar, SomeFloat, unionof, SomeInstance, SomeDict, SomeBuiltin, SomePBC, SomeInteger, TLS, SomeUnicodeCodePoint, @@ -358,7 +359,7 @@ return self.descs[obj_key] except KeyError: if isinstance(pyobj, types.FunctionType): -result = description.FunctionDesc(self, pyobj) +result = self.newfuncdesc(pyobj) elif isinstance(pyobj, (type, types.ClassType)): if pyobj is object: raise Exception("ClassDesc for object not supported") @@ -403,6 +404,21 @@ self.descs[obj_key] = result return result +def newfuncdesc(self, pyfunc): +name = pyfunc.__name__ +if hasattr(pyfunc, '_generator_next_method_of_'): +from rpython.flowspace.argument import Signature +signature = Signature(['entry']) # haack +defaults = () +else: +signature = cpython_code_signature(pyfunc.func_code) +defaults = pyfunc.func_defaults +# get the specializer based on the tag of the 'pyobj' +# (if any), according to the current policy +tag = getattr(pyfunc, '_annspecialcase_', None) +specializer = self.annotator.policy.get_specializer(tag) +return description.FunctionDesc(self, pyfunc, name, signature, defaults, specializer) + def getfrozen(self, pyobj): return description.FrozenDesc(self, pyobj) diff --git a/rpython/annotator/classdesc.py b/rpython/annotator/classdesc.py --- a/rpython/annotator/classdesc.py +++ b/rpython/annotator/classdesc.py @@ -600,7 +600,7 @@ if mixin: # make a new copy of the FunctionDesc for this class, # but don't specialize further for all subclasses -funcdesc = FunctionDesc(self.bookkeeper, value) +funcdesc = self.bookkeeper.newfuncdesc(value) self.classdict[name] = funcdesc return # NB. if value is, say, AssertionError.__init__, then we diff --git a/rpython/annotator/description.py b/rpython/annotator/description.py --- a/rpython/annotator/description.py +++ b/rpython/annotator/description.py @@ -3,7 +3,6 @@ from rpython.annotator.signature import ( enforce_signature_args, enforce_signature_return, finish_type) from rpython.flowspace.model import FunctionGraph -from rpython.flowspace.bytecode import cpython_code_signature from rpython.annotator.argument import rawshape, ArgErr, simple_args from rpython.tool.sourcetools import valid_identifier from rpython.tool.pairtype import extendabletype @@ -192,29 +191,16 @@ class FunctionDesc(Desc): knowntype = types.FunctionType -def __init__(self, bookkeeper, pyobj=None, - name=None, signature=None, defaults=None, +def __init__(self, bookkeeper, pyobj, name, signature, defaults, specializer=None): super(FunctionDesc, self).__init__(bookkeeper, pyobj) -if name is None: -name = pyobj.func_name -if signature is None: -if hasattr(pyobj, '_generator_next_method_of_'): -from rpython.flowspace.argument import Signature -signature = Signature(['entry']) # haack -defaults = () -else: -signature = cpython_code_signature(pyobj.func_code) -if defaults is None: -defaults = pyobj.func_defaults self.name = name self.signature = signature -self.defaults = defaults or () +self.defaults = defaults # 'specializer' is a function with the following signature: # specializer(funcdesc, args_s) => graph # or => s_result (overridden/memo cases) self.specializer = specializer -self.init_specializer() self._cache = {} # convenience for the specializer def buildgraph(self, alt_name=None, builder=None): @@ -284,14 +270,6 @@ (self.name, e.getmsg())) return inputcells -def init_specializer(self): -if self.specializer is None: -# get the specializer based on the tag of the 'pyobj' -# (if any), according to the current policy -tag = ge
[pypy-commit] pypy desc-specialize: normalise funcdesc.defaults
Author: Ronan Lamy Branch: desc-specialize Changeset: r82354:8eba3a267336 Date: 2016-02-20 17:03 +0100 http://bitbucket.org/pypy/pypy/changeset/8eba3a267336/ Log:normalise funcdesc.defaults diff --git a/rpython/annotator/description.py b/rpython/annotator/description.py --- a/rpython/annotator/description.py +++ b/rpython/annotator/description.py @@ -196,7 +196,7 @@ super(FunctionDesc, self).__init__(bookkeeper, pyobj) self.name = name self.signature = signature -self.defaults = defaults +self.defaults = defaults if defaults is not None else () # 'specializer' is a function with the following signature: # specializer(funcdesc, args_s) => graph # or => s_result (overridden/memo cases) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy desc-specialize: Extract new function all_values() from memo()
Author: Ronan Lamy Branch: desc-specialize Changeset: r82353:0e58f82655b2 Date: 2016-02-20 16:48 +0100 http://bitbucket.org/pypy/pypy/changeset/0e58f82655b2/ Log:Extract new function all_values() from memo() diff --git a/rpython/annotator/specialize.py b/rpython/annotator/specialize.py --- a/rpython/annotator/specialize.py +++ b/rpython/annotator/specialize.py @@ -3,11 +3,13 @@ from rpython.tool.sourcetools import func_with_new_name from rpython.tool.algo.unionfind import UnionFind -from rpython.flowspace.model import Block, Link, Variable, SpaceOperation +from rpython.flowspace.model import Block, Link, Variable from rpython.flowspace.model import checkgraph from rpython.flowspace.operation import op from rpython.annotator import model as annmodel from rpython.flowspace.argument import Signature +from rpython.annotator.model import SomePBC, SomeImpossibleValue, SomeBool +from rpython.annotator.model import unionof def flatten_star_args(funcdesc, args_s): argnames, vararg, kwarg = funcdesc.signature @@ -127,7 +129,6 @@ def finish(self): if self.do_not_process: return -from rpython.annotator.model import unionof assert self.graph is None, "MemoTable already finished" # list of which argument positions can take more than one value example_args, example_value = self.table.iteritems().next() @@ -246,34 +247,36 @@ args_s.append(unionof(*values_s)) annotator.addpendinggraph(self.graph, args_s) +def all_values(s): +"""Return the exhaustive list of possible values matching annotation `s`. -def memo(funcdesc, arglist_s): -from rpython.annotator.model import SomePBC, SomeImpossibleValue, SomeBool -from rpython.annotator.model import unionof +Raises `AnnotatorError` if no such (reasonably small) finite list exists. +""" +if s.is_constant(): +return [s.const] +elif isinstance(s, SomePBC): +values = [] +assert not s.can_be_None, "memo call: cannot mix None and PBCs" +for desc in s.descriptions: +if desc.pyobj is None: +raise annmodel.AnnotatorError( +"memo call with a class or PBC that has no " +"corresponding Python object (%r)" % (desc,)) +values.append(desc.pyobj) +return values +elif isinstance(s, SomeImpossibleValue): +return [] +elif isinstance(s, SomeBool): +return [False, True] +else: +raise annmodel.AnnotatorError("memo call: argument must be a class " +"or a frozen PBC, got %r" % (s,)) + +def memo(funcdesc, args_s): # call the function now, and collect possible results -argvalues = [] -for s in arglist_s: -if s.is_constant(): -values = [s.const] -elif isinstance(s, SomePBC): -values = [] -assert not s.can_be_None, "memo call: cannot mix None and PBCs" -for desc in s.descriptions: -if desc.pyobj is None: -raise annmodel.AnnotatorError( -"memo call with a class or PBC that has no " -"corresponding Python object (%r)" % (desc,)) -values.append(desc.pyobj) -elif isinstance(s, SomeImpossibleValue): -return s# we will probably get more possible args later -elif isinstance(s, SomeBool): -values = [False, True] -else: -raise annmodel.AnnotatorError("memo call: argument must be a class " - "or a frozen PBC, got %r" % (s,)) -argvalues.append(values) + # the list of all possible tuples of arguments to give to the memo function -possiblevalues = cartesian_product(argvalues) +possiblevalues = cartesian_product([all_values(s_arg) for s_arg in args_s]) # a MemoTable factory -- one MemoTable per family of arguments that can # be called together, merged via a UnionFind. ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy cpyext-gc-support-2: Fix merge
Author: Ronan Lamy Branch: cpyext-gc-support-2 Changeset: r82400:8a2af16e80dc Date: 2016-02-22 17:45 +0100 http://bitbucket.org/pypy/pypy/changeset/8a2af16e80dc/ Log:Fix merge diff --git a/pypy/module/cpyext/tupleobject.py b/pypy/module/cpyext/tupleobject.py --- a/pypy/module/cpyext/tupleobject.py +++ b/pypy/module/cpyext/tupleobject.py @@ -101,7 +101,7 @@ track_reference(space, py_obj, w_obj) return w_obj -@cpython_api([PyObject], lltype.Void, external=False) +@cpython_api([PyObject], lltype.Void, header=None) def tuple_dealloc(space, py_obj): """Frees allocated PyTupleObject resources. """ ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy cpyext-gc-support-2: fix references to .instancetypedef
Author: Ronan Lamy Branch: cpyext-gc-support-2 Changeset: r82401:f7a259fbc9f7 Date: 2016-02-22 18:07 +0100 http://bitbucket.org/pypy/pypy/changeset/f7a259fbc9f7/ Log:fix references to .instancetypedef diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py --- a/pypy/module/cpyext/api.py +++ b/pypy/module/cpyext/api.py @@ -944,7 +944,7 @@ py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_type = space.type(w_obj) -typedescr = get_typedescr(w_type.instancetypedef) +typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, make_ref(space, w_type)) typedescr.attach(space, py_obj, w_obj) @@ -1142,7 +1142,7 @@ if not use_micronumpy: return use_micronumpy # import to register api functions by side-effect -import pypy.module.cpyext.ndarrayobject +import pypy.module.cpyext.ndarrayobject global GLOBALS, SYMBOLS_C, separate_module_files GLOBALS["PyArray_Type#"]= ('PyTypeObject*', "space.gettypeobject(W_NDimArray.typedef)") SYMBOLS_C += ['PyArray_Type', '_PyArray_FILLWBYTE', '_PyArray_ZEROS'] diff --git a/pypy/module/cpyext/bufferobject.py b/pypy/module/cpyext/bufferobject.py --- a/pypy/module/cpyext/bufferobject.py +++ b/pypy/module/cpyext/bufferobject.py @@ -25,7 +25,7 @@ @bootstrap_function def init_bufferobject(space): "Type description of PyBufferObject" -make_typedescr(space.w_buffer.instancetypedef, +make_typedescr(space.w_buffer.layout.typedef, basestruct=PyBufferObject.TO, attach=buffer_attach, dealloc=buffer_dealloc, diff --git a/pypy/module/cpyext/intobject.py b/pypy/module/cpyext/intobject.py --- a/pypy/module/cpyext/intobject.py +++ b/pypy/module/cpyext/intobject.py @@ -19,7 +19,7 @@ @bootstrap_function def init_intobject(space): "Type description of PyIntObject" -make_typedescr(space.w_int.instancetypedef, +make_typedescr(space.w_int.layout.typedef, basestruct=PyIntObject.TO, attach=int_attach, realize=int_realize) @@ -51,7 +51,7 @@ @cpython_api([lltype.Signed], PyObject) def PyInt_FromLong(space, ival): """Create a new integer object with a value of ival. - + """ return space.wrap(ival) diff --git a/pypy/module/cpyext/object.py b/pypy/module/cpyext/object.py --- a/pypy/module/cpyext/object.py +++ b/pypy/module/cpyext/object.py @@ -31,7 +31,7 @@ def _PyObject_NewVar(space, type, itemcount): w_type = from_ref(space, rffi.cast(PyObject, type)) assert isinstance(w_type, W_TypeObject) -typedescr = get_typedescr(w_type.instancetypedef) +typedescr = get_typedescr(w_type.layout.typedef) py_obj = typedescr.allocate(space, w_type, itemcount=itemcount) #py_obj.c_ob_refcnt = 0 --- will be set to 1 again by PyObject_Init{Var} if type.c_tp_itemsize == 0: diff --git a/pypy/module/cpyext/pyobject.py b/pypy/module/cpyext/pyobject.py --- a/pypy/module/cpyext/pyobject.py +++ b/pypy/module/cpyext/pyobject.py @@ -115,7 +115,7 @@ def init_pyobject(space): from pypy.module.cpyext.object import PyObject_dealloc # typedescr for the 'object' type -make_typedescr(space.w_object.instancetypedef, +make_typedescr(space.w_object.layout.typedef, dealloc=PyObject_dealloc) # almost all types, which should better inherit from object. make_typedescr(None) @@ -207,7 +207,7 @@ raise InvalidPointerException(str(ref)) w_type = from_ref(space, ref_type) assert isinstance(w_type, W_TypeObject) -return get_typedescr(w_type.instancetypedef).realize(space, ref) +return get_typedescr(w_type.layout.typedef).realize(space, ref) def debug_collect(): @@ -327,7 +327,7 @@ obj.c_ob_refcnt = 1 w_type = from_ref(space, rffi.cast(PyObject, obj.c_ob_type)) assert isinstance(w_type, W_TypeObject) -get_typedescr(w_type.instancetypedef).realize(space, obj) +get_typedescr(w_type.layout.typedef).realize(space, obj) @cpython_api([PyObject], lltype.Void) def _Py_Dealloc(space, obj): diff --git a/pypy/module/cpyext/stringobject.py b/pypy/module/cpyext/stringobject.py --- a/pypy/module/cpyext/stringobject.py +++ b/pypy/module/cpyext/stringobject.py @@ -59,7 +59,7 @@ @bootstrap_function def init_stringobject(space): "Type description of PyStringObject" -make_typedescr(space.w_str.instancetypedef, +make_typedescr(space.w_str.layout.typedef, basestruct=PyStringObject.TO, attach=string_attach, dealloc=string_dealloc, @@ -73,7 +73,7 @@ interpreter object. The buffer may be mutated, until string_realize() is called. Refcount of the result is 1. """ -typedescr = get_typedescr(space.w_str.instancetypedef) +typedescr = get_typedescr(space.
[pypy-commit] pypy cpyext-ext: hg merge default
Author: Ronan Lamy Branch: cpyext-ext Changeset: r82438:7fad651c7daf Date: 2016-02-23 14:39 +0100 http://bitbucket.org/pypy/pypy/changeset/7fad651c7daf/ Log:hg merge default diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst --- a/pypy/doc/whatsnew-head.rst +++ b/pypy/doc/whatsnew-head.rst @@ -128,6 +128,7 @@ Fix SSL tests by importing cpython's patch + .. branch: remove-getfield-pure Remove pure variants of ``getfield_gc_*`` operations from the JIT. Relevant @@ -163,3 +164,10 @@ .. branch: windows-vmprof-support vmprof should work on Windows. + + +.. branch: reorder-map-attributes + +When creating instances and adding attributes in several different orders +depending on some condition, the JIT would create too much code. This is now +fixed. \ No newline at end of file diff --git a/pypy/module/imp/test/test_import.py b/pypy/module/imp/test/test_import.py --- a/pypy/module/imp/test/test_import.py +++ b/pypy/module/imp/test/test_import.py @@ -1061,12 +1061,12 @@ py.test.skip("unresolved issues with win32 shell quoting rules") from pypy.interpreter.test.test_zpy import pypypath extrapath = udir.ensure("pythonpath", dir=1) -extrapath.join("urllib.py").write("print 42\n") +extrapath.join("sched.py").write("print 42\n") old = os.environ.get('PYTHONPATH', None) oldlang = os.environ.pop('LANG', None) try: os.environ['PYTHONPATH'] = str(extrapath) -output = py.process.cmdexec('''"%s" "%s" -c "import urllib"''' % +output = py.process.cmdexec('''"%s" "%s" -c "import sched"''' % (sys.executable, pypypath)) assert output.strip() == '42' finally: 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 @@ -28,7 +28,6 @@ guard_true(i14, descr=...) guard_not_invalidated(descr=...) i16 = int_eq(i6, %d) -guard_false(i16, descr=...) i15 = int_mod(i6, i10) i17 = int_rshift(i15, %d) i18 = int_and(i10, i17) @@ -68,7 +67,6 @@ guard_true(i11, descr=...) guard_not_invalidated(descr=...) i13 = int_eq(i6, %d) # value provided below -guard_false(i13, descr=...) i15 = int_mod(i6, 10) i17 = int_rshift(i15, %d)# value provided below i18 = int_and(10, i17) @@ -144,43 +142,6 @@ jump(..., descr=...) """) -def test_getattr_promote(self): -def main(n): -class A(object): -def meth_a(self): -return 1 -def meth_b(self): -return 2 -a = A() - -l = ['a', 'b'] -s = 0 -for i in range(n): -name = 'meth_' + l[i & 1] -meth = getattr(a, name) # ID: getattr -s += meth() -return s - -log = self.run(main, [1000]) -assert log.result == main(1000) -loops = log.loops_by_filename(self.filepath) -assert len(loops) == 1 -for loop in loops: -assert loop.match_by_id('getattr',''' -guard_not_invalidated? -i32 = strlen(p31) -i34 = int_add(5, i32) -p35 = newstr(i34) -strsetitem(p35, 0, 109) -strsetitem(p35, 1, 101) -strsetitem(p35, 2, 116) -strsetitem(p35, 3, 104) -strsetitem(p35, 4, 95) -copystrcontent(p31, p35, 0, 5, i32) -i49 = call_i(ConstClass(_ll_2_str_eq_nonnull__rpy_stringPtr_rpy_stringPtr), p35, ConstPtr(ptr48), descr=) -guard_value(i49, 1, descr=...) -''') - def test_remove_duplicate_method_calls(self): def main(n): lst = [] 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 @@ -1,4 +1,4 @@ -import weakref +import weakref, sys from rpython.rlib import jit, objectmodel, debug, rerased from rpython.rlib.rarithmetic import intmask, r_uint @@ -12,6 +12,11 @@ from pypy.objspace.std.typeobject import MutableCell +erase_item, unerase_item = rerased.new_erasing_pair("mapdict storage item") +erase_map, unerase_map = rerased.new_erasing_pair("map") +erase_list, unerase_list = rerased.new_erasing_pair("mapdict storage list") + + # # attribute shapes @@ -20,6 +25,7 @@ # note: we use "x * NUM_DIGITS_POW2" instead of "x << NUM_DIGITS" because # we want to propagate knowledge that the result cannot be negative + class AbstractAttribute(object): _immutable_fields_ = ['terminator'] cache_attrs = None @@ -151,29 +157,124 @@ cache[
[pypy-commit] pypy cpyext-ext: fix test: types which have the same size as PyObject should not cause instance layout conflicts
Author: Ronan Lamy Branch: cpyext-ext Changeset: r82442:7ee3179525f3 Date: 2016-02-23 15:33 +0100 http://bitbucket.org/pypy/pypy/changeset/7ee3179525f3/ Log:fix test: types which have the same size as PyObject should not cause instance layout conflicts diff --git a/pypy/module/cpyext/test/test_typeobject.py b/pypy/module/cpyext/test/test_typeobject.py --- a/pypy/module/cpyext/test/test_typeobject.py +++ b/pypy/module/cpyext/test/test_typeobject.py @@ -396,7 +396,7 @@ which should have a different tp_getattro/tp_setattro than its tp_base, which is 'object'. */ - + if (!args->ob_type->tp_setattro) { PyErr_SetString(PyExc_ValueError, "missing tp_setattro"); @@ -719,7 +719,7 @@ long ival; } IntLikeObject; -static PyObject * +static PyObject * intlike_nb_add(PyObject *self, PyObject *other) { long val2, val1 = ((IntLikeObject *)(self))->ival; @@ -782,7 +782,7 @@ def test_app_cant_subclass_two_types(self): module = self.import_module(name='foo') try: -class bar(module.fooType, module.Property): +class bar(module.fooType, module.UnicodeSubtype): pass except TypeError as e: assert str(e) == 'instance layout conflicts in multiple inheritance' ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy cpyext-ext: Fix for running -A cpyext tests
Author: Ronan Lamy Branch: cpyext-ext Changeset: r82443:cf846c1b0068 Date: 2016-02-23 16:07 +0100 http://bitbucket.org/pypy/pypy/changeset/cf846c1b0068/ Log:Fix for running -A cpyext tests diff --git a/pypy/module/cpyext/test/test_cpyext.py b/pypy/module/cpyext/test/test_cpyext.py --- a/pypy/module/cpyext/test/test_cpyext.py +++ b/pypy/module/cpyext/test/test_cpyext.py @@ -285,7 +285,7 @@ return space.wrap(pydname) @gateway.unwrap_spec(name=str, init='str_or_None', body=str, - load_it=bool, filename='str_or_None', + load_it=bool, filename='str_or_None', PY_SSIZE_T_CLEAN=bool) def import_module(space, name, init=None, body='', load_it=True, filename=None, w_include_dirs=None, @@ -307,7 +307,7 @@ code = """ %(PY_SSIZE_T_CLEAN)s #include -/* fix for cpython 2.7 Python.h if running tests with -A +/* fix for cpython 2.7 Python.h if running tests with -A since pypy compiles with -fvisibility-hidden */ #undef PyMODINIT_FUNC #define PyMODINIT_FUNC RPY_EXPORTED void @@ -433,9 +433,8 @@ self.w_reimport_module = wrap(interp2app(reimport_module)) self.w_import_extension = wrap(interp2app(import_extension)) self.w_record_imported_module = wrap(interp2app(record_imported_module)) -self.w_here = self.space.wrap( -str(py.path.local(pypydir)) + '/module/cpyext/test/') -self.w_debug_collect = self.space.wrap(interp2app(debug_collect)) +self.w_here = wrap(str(py.path.local(pypydir)) + '/module/cpyext/test/') +self.w_debug_collect = wrap(interp2app(debug_collect)) # create the file lock before we count allocations self.space.call_method(self.space.sys.get("stdout"), "flush") ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy cpyext-ext: Manually expand obscure macro
Author: Ronan Lamy Branch: cpyext-ext Changeset: r82454:58459ae8908d Date: 2016-02-23 18:17 +0100 http://bitbucket.org/pypy/pypy/changeset/58459ae8908d/ Log:Manually expand obscure macro diff --git a/pypy/module/cpyext/test/foo.c b/pypy/module/cpyext/test/foo.c --- a/pypy/module/cpyext/test/foo.c +++ b/pypy/module/cpyext/test/foo.c @@ -182,7 +182,7 @@ {"float_member", T_FLOAT, offsetof(fooobject, foo_float), 0, NULL}, {"double_member", T_DOUBLE, offsetof(fooobject, foo_double), 0, NULL}, {"longlong_member", T_LONGLONG, offsetof(fooobject, foo_longlong), 0, NULL}, -{"ulonglong_member", T_ULONGLONG, offsetof(fooobject, foo_ulonglong), 0, NULL}, +{"ulonglong_member", T_ULONGLONG, offsetof(fooobject, foo_ulonglong), 0, NULL}, {"ssizet_member", T_PYSSIZET, offsetof(fooobject, foo_ssizet), 0, NULL}, {NULL} /* Sentinel */ }; @@ -450,7 +450,7 @@ if ((foop = newfooobject()) == NULL) { return NULL; } - + return (PyObject *)foop; } @@ -666,7 +666,7 @@ PyMethodDescr_TypePtr == PyGetSetDescr_TypePtr || PyMemberDescr_TypePtr == PyGetSetDescr_TypePtr) { -PyErr_Format(PyExc_RuntimeError, +PyErr_Format(PyExc_RuntimeError, "at least two of the 'Py{Method,Member,GetSet}Descr_Type's are the same\n" "(in cmp_docstring %s %d)", __FILE__, __LINE__); return NULL; @@ -695,7 +695,20 @@ _CMPDOC(CFunction, new->m_ml->ml_doc, new->m_ml->ml_name); } else if (_TESTDOC1(Type)) { -_CMPDOC(Type, new->tp_doc, new->tp_name); +PyTypeObject *new = (PyTypeObject *)obj; +if (!(new->tp_doc)) { +PyErr_Format(PyExc_RuntimeError, "Type '%s' %s", new->tp_name, msg); +return NULL; +} +else { +if (strcmp(new->tp_doc, docstr) != 0) +{ +PyErr_Format(PyExc_RuntimeError, + "%s's docstring '%s' is not '%s'", + new->tp_name, new->tp_doc, docstr); +return NULL; +} +} } else if (_TESTDOC2(MemberDescr)) { _CMPDOC(MemberDescr, new->d_member->doc, new->d_member->name); @@ -718,13 +731,13 @@ attr_as_str = PyString_AS_STRING(doc_attr); if (strcmp(attr_as_str, docstr) != 0) -{ -PyErr_Format(PyExc_RuntimeError, - "objects's docstring '%s' is not '%s'", - attr_as_str, docstr); +{ +PyErr_Format(PyExc_RuntimeError, + "objects's docstring '%s' is not '%s'", + attr_as_str, docstr); Py_XDECREF(doc_attr); -return NULL; -} +return NULL; +} Py_XDECREF(doc_attr); Py_RETURN_NONE; } @@ -782,7 +795,7 @@ return; if (PyType_Ready(&SimplePropertyType) < 0) return; - + SimplePropertyType.tp_new = PyType_GenericNew; InitErrType.tp_new = PyType_GenericNew; ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy desc-specialize: Extract normalize_args() method out of funcdesc.specialize
Author: Ronan Lamy Branch: desc-specialize Changeset: r82483:5089fd09c1d1 Date: 2016-02-24 15:47 +0100 http://bitbucket.org/pypy/pypy/changeset/5089fd09c1d1/ Log:Extract normalize_args() method out of funcdesc.specialize diff --git a/rpython/annotator/description.py b/rpython/annotator/description.py --- a/rpython/annotator/description.py +++ b/rpython/annotator/description.py @@ -275,19 +275,7 @@ getattr(self.bookkeeper, "position_key", None) is not None): _, block, i = self.bookkeeper.position_key op = block.operations[i] -enforceargs = getattr(self.pyobj, '_annenforceargs_', None) -signature = getattr(self.pyobj, '_signature_', None) -if enforceargs and signature: -raise Exception("%r: signature and enforceargs cannot both be " -"used" % (self,)) -if enforceargs: -if not callable(enforceargs): -from rpython.annotator.signature import Sig -enforceargs = Sig(*enforceargs) -self.pyobj._annenforceargs_ = enforceargs -enforceargs(self, inputcells) # can modify inputcells in-place -if signature: -enforce_signature_args(self, signature[0], inputcells) # mutates inputcells +self.normalize_args(inputcells) if getattr(self.pyobj, '_annspecialcase_', '').endswith("call_location"): return self.specializer(self, inputcells, op) else: @@ -319,6 +307,27 @@ result = unionof(result, s_previous_result) return result +def normalize_args(self, inputs_s): +""" +Canonicalize argument annotations into the exact parameter +annotations of a specific specialized graph. + +Note: this method has no return value but mutates its argument instead. +""" +enforceargs = getattr(self.pyobj, '_annenforceargs_', None) +signature = getattr(self.pyobj, '_signature_', None) +if enforceargs and signature: +raise Exception("%r: signature and enforceargs cannot both be " +"used" % (self,)) +if enforceargs: +if not callable(enforceargs): +from rpython.annotator.signature import Sig +enforceargs = Sig(*enforceargs) +self.pyobj._annenforceargs_ = enforceargs +enforceargs(self, inputs_s) # can modify inputs_s in-place +if signature: +enforce_signature_args(self, signature[0], inputs_s) # mutates inputs_s + def get_graph(self, args, op): inputs_s = self.parse_arguments(args) return self.specialize(inputs_s, op) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy desc-specialize: Use @specialize decorators instead of direct assignments to ._annspecialcase_
Author: Ronan Lamy Branch: desc-specialize Changeset: r82482:fd243b77d69b Date: 2016-02-21 15:00 +0100 http://bitbucket.org/pypy/pypy/changeset/fd243b77d69b/ Log:Use @specialize decorators instead of direct assignments to ._annspecialcase_ diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py --- a/pypy/interpreter/baseobjspace.py +++ b/pypy/interpreter/baseobjspace.py @@ -356,12 +356,12 @@ class BufferInterfaceNotFound(Exception): pass +@specialize.memo() def wrappable_class_name(Class): try: return Class.typedef.name except AttributeError: return 'internal subclass of %s' % (Class.__name__,) -wrappable_class_name._annspecialcase_ = 'specialize:memo' class CannotHaveLock(Exception): """Raised by space.allocate_lock() if we're translating.""" @@ -391,7 +391,7 @@ self.check_signal_action = None # changed by the signal module self.user_del_action = UserDelAction(self) self._code_of_sys_exc_info = None - + # can be overridden to a subclass self.initialize() @@ -808,12 +808,13 @@ assert type(s) is str return self.interned_strings.get(s) is not None +@specialize.arg(1) def descr_self_interp_w(self, RequiredClass, w_obj): if not isinstance(w_obj, RequiredClass): raise DescrMismatch() return w_obj -descr_self_interp_w._annspecialcase_ = 'specialize:arg(1)' +@specialize.arg(1) def interp_w(self, RequiredClass, w_obj, can_be_None=False): """ Unwrap w_obj, checking that it is an instance of the required internal @@ -828,7 +829,6 @@ wrappable_class_name(RequiredClass), w_obj.getclass(self)) return w_obj -interp_w._annspecialcase_ = 'specialize:arg(1)' def unpackiterable(self, w_iterable, expected_length=-1): """Unpack an iterable into a real (interpreter-level) list. @@ -1245,6 +1245,7 @@ self.setitem(w_globals, w_key, self.wrap(self.builtin)) return statement.exec_code(self, w_globals, w_locals) +@specialize.arg(2) def appexec(self, posargs_w, source): """ return value from executing given source at applevel. EXPERIMENTAL. The source must look like @@ -1256,7 +1257,6 @@ w_func = self.fromcache(AppExecCache).getorbuild(source) args = Arguments(self, list(posargs_w)) return self.call_args(w_func, args) -appexec._annspecialcase_ = 'specialize:arg(2)' def _next_or_none(self, w_it): try: @@ -1266,6 +1266,7 @@ raise return None +@specialize.arg(3) def compare_by_iteration(self, w_iterable1, w_iterable2, op): w_it1 = self.iter(w_iterable1) w_it2 = self.iter(w_iterable2) @@ -1288,7 +1289,6 @@ if op == 'gt': return self.gt(w_x1, w_x2) if op == 'ge': return self.ge(w_x1, w_x2) assert False, "bad value for op" -compare_by_iteration._annspecialcase_ = 'specialize:arg(3)' def decode_index(self, w_index_or_slice, seqlength): """Helper for custom sequence implementations diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py --- a/pypy/interpreter/error.py +++ b/pypy/interpreter/error.py @@ -446,6 +446,7 @@ space.wrap(msg)) return OperationError(exc, w_error) +@specialize.arg(3) def wrap_oserror2(space, e, w_filename=None, exception_name='w_OSError', w_exception_class=None): assert isinstance(e, OSError) @@ -473,8 +474,8 @@ w_error = space.call_function(exc, space.wrap(errno), space.wrap(msg)) return OperationError(exc, w_error) -wrap_oserror2._annspecialcase_ = 'specialize:arg(3)' +@specialize.arg(3) def wrap_oserror(space, e, filename=None, exception_name='w_OSError', w_exception_class=None): if filename is not None: @@ -485,7 +486,6 @@ return wrap_oserror2(space, e, None, exception_name=exception_name, w_exception_class=w_exception_class) -wrap_oserror._annspecialcase_ = 'specialize:arg(3)' def exception_from_saved_errno(space, w_type): from rpython.rlib.rposix import get_saved_errno diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py --- a/pypy/interpreter/typedef.py +++ b/pypy/interpreter/typedef.py @@ -138,6 +138,7 @@ # / \ #5 6 +@specialize.memo() def get_unique_interplevel_subclass(config, cls, hasdict, wants_slots, needsdel=False, weakrefable=False): "NOT_RPYTHON: initialization-time only" @@ -153,7 +154,6 @@ assert key not in _subclass_cache _subclass_cache[key] = subcls return subcls -get_unique_interplevel_
[pypy-commit] pypy desc-specialize: Create special FunctionDesc subclass for @specialize.memo() functions
Author: Ronan Lamy Branch: desc-specialize Changeset: r82490:67633b1da4fa Date: 2016-02-24 19:00 +0100 http://bitbucket.org/pypy/pypy/changeset/67633b1da4fa/ Log:Create special FunctionDesc subclass for @specialize.memo() functions diff --git a/rpython/annotator/bookkeeper.py b/rpython/annotator/bookkeeper.py --- a/rpython/annotator/bookkeeper.py +++ b/rpython/annotator/bookkeeper.py @@ -22,6 +22,7 @@ from rpython.annotator import description from rpython.annotator.signature import annotationoftype from rpython.annotator.argument import simple_args +from rpython.annotator.specialize import memo from rpython.rlib.objectmodel import r_dict, r_ordereddict, Symbolic from rpython.tool.algo.unionfind import UnionFind from rpython.rtyper import extregistry @@ -417,6 +418,8 @@ # (if any), according to the current policy tag = getattr(pyfunc, '_annspecialcase_', None) specializer = self.annotator.policy.get_specializer(tag) +if specializer is memo: +return description.MemoDesc(self, pyfunc, name, signature, defaults, specializer) return description.FunctionDesc(self, pyfunc, name, signature, defaults, specializer) def getfrozen(self, pyobj): diff --git a/rpython/annotator/description.py b/rpython/annotator/description.py --- a/rpython/annotator/description.py +++ b/rpython/annotator/description.py @@ -395,6 +395,15 @@ return s_sigs +class MemoDesc(FunctionDesc): +def pycall(self, whence, args, s_previous_result, op=None): +inputcells = self.parse_arguments(args) +s_result = self.specialize(inputcells, op) +assert not isinstance(s_result, FunctionGraph) +assert s_result.contains(s_previous_result) +return s_result + + class MethodDesc(Desc): knowntype = types.MethodType ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy desc-specialize: fixes
Author: Ronan Lamy Branch: desc-specialize Changeset: r82491:aef099eea410 Date: 2016-02-25 10:06 +0100 http://bitbucket.org/pypy/pypy/changeset/aef099eea410/ Log:fixes diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py --- a/pypy/module/cpyext/api.py +++ b/pypy/module/cpyext/api.py @@ -1295,7 +1295,7 @@ miniglobals = {'__name__':__name__, # for module name propagation } exec source.compile() in miniglobals -call_external_function = specialize.ll(miniglobals['cpy_call_external']) +call_external_function = specialize.ll()(miniglobals['cpy_call_external']) call_external_function._dont_inline_ = True call_external_function._gctransformer_hint_close_stack_ = True # don't inline, as a hack to guarantee that no GC pointer is alive diff --git a/rpython/annotator/description.py b/rpython/annotator/description.py --- a/rpython/annotator/description.py +++ b/rpython/annotator/description.py @@ -6,7 +6,7 @@ from rpython.annotator.argument import rawshape, ArgErr, simple_args from rpython.tool.sourcetools import valid_identifier from rpython.tool.pairtype import extendabletype -from rpython.annotator.model import AnnotatorError, s_ImpossibleValue +from rpython.annotator.model import AnnotatorError, s_ImpossibleValue, unionof class CallFamily(object): """A family of Desc objects that could be called from common call sites. @@ -116,7 +116,6 @@ self.s_value = s_ImpossibleValue# union of possible values def update(self, other): -from rpython.annotator.model import unionof self.descs.update(other.descs) self.read_locations.update(other.read_locations) self.s_value = unionof(self.s_value, other.s_value) @@ -303,7 +302,6 @@ # Some specializations may break the invariant of returning # annotations that are always more general than the previous time. # We restore it here: -from rpython.annotator.model import unionof result = unionof(result, s_previous_result) return result @@ -399,8 +397,9 @@ def pycall(self, whence, args, s_previous_result, op=None): inputcells = self.parse_arguments(args) s_result = self.specialize(inputcells, op) -assert not isinstance(s_result, FunctionGraph) -assert s_result.contains(s_previous_result) +if isinstance(s_result, FunctionGraph): +s_result = s_result.getreturnvar().annotation +s_result = unionof(s_result, s_previous_result) return s_result diff --git a/rpython/rtyper/lltypesystem/llmemory.py b/rpython/rtyper/lltypesystem/llmemory.py --- a/rpython/rtyper/lltypesystem/llmemory.py +++ b/rpython/rtyper/lltypesystem/llmemory.py @@ -377,7 +377,6 @@ def _sizeof_none(TYPE): assert not TYPE._is_varsize() return ItemOffset(TYPE) -_sizeof_none._annspecialcase_ = 'specialize:memo' @specialize.memo() def _internal_array_field(TYPE): diff --git a/rpython/rtyper/rpbc.py b/rpython/rtyper/rpbc.py --- a/rpython/rtyper/rpbc.py +++ b/rpython/rtyper/rpbc.py @@ -362,9 +362,9 @@ def get_concrete_llfn(self, s_pbc, args_s, op): bk = self.rtyper.annotator.bookkeeper funcdesc, = s_pbc.descriptions -args = simple_args(args_s) with bk.at_position(None): -graph = funcdesc.get_graph(args, op) +argspec = simple_args(args_s) +graph = funcdesc.get_graph(argspec, op) llfn = self.rtyper.getcallable(graph) return inputconst(typeOf(llfn), llfn) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy cpyext-ext: Fix refcount bug in test
Author: Ronan Lamy Branch: cpyext-ext Changeset: r82513:4f809c093ddd Date: 2016-02-25 17:00 +0100 http://bitbucket.org/pypy/pypy/changeset/4f809c093ddd/ Log:Fix refcount bug in test diff --git a/pypy/module/cpyext/test/test_dictobject.py b/pypy/module/cpyext/test/test_dictobject.py --- a/pypy/module/cpyext/test/test_dictobject.py +++ b/pypy/module/cpyext/test/test_dictobject.py @@ -169,9 +169,8 @@ w_proxy, space.wrap('sys')) raises(OperationError, space.call_method, w_proxy, 'clear') assert api.PyDictProxy_Check(w_proxy) - + class AppTestDictObject(AppTestCpythonExtensionBase): -#@py.test.mark.xfail(reason='make_frozendict memoize only works translated') def test_dictproxytype(self): module = self.import_extension('foo', [ ("dict_proxy", "METH_VARARGS", @@ -182,12 +181,11 @@ if (!PyArg_ParseTuple(args, "O", &dict)) return NULL; proxydict = PyDictProxy_New(dict); - Py_DECREF(dict); if (!PyDictProxy_Check(proxydict)) { Py_DECREF(proxydict); PyErr_SetNone(PyExc_ValueError); return NULL; - } + } if (!PyDictProxy_CheckExact(proxydict)) { Py_DECREF(proxydict); PyErr_SetNone(PyExc_ValueError); @@ -195,7 +193,7 @@ } i = PyObject_Size(proxydict); Py_DECREF(proxydict); - return PyLong_FromLong(i); + return PyLong_FromLong(i); """), ]) assert module.dict_proxy({'a': 1, 'b': 2}) == 2 ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Use skipif in tests instead of manually emulating it
Author: Ronan Lamy Branch: Changeset: r82563:4a5b9f2b35f5 Date: 2016-02-26 14:13 +0100 http://bitbucket.org/pypy/pypy/changeset/4a5b9f2b35f5/ Log:Use skipif in tests instead of manually emulating it diff --git a/rpython/rlib/test/test_posix.py b/rpython/rlib/test/test_posix.py --- a/rpython/rlib/test/test_posix.py +++ b/rpython/rlib/test/test_posix.py @@ -1,4 +1,4 @@ -import py +import py.test from rpython.rtyper.test.tool import BaseRtypingTest from rpython.rtyper.annlowlevel import hlstr from rpython.tool.udir import udir @@ -58,7 +58,7 @@ assert res def test_times(self): -import py; py.test.skip("llinterp does not like tuple returns") +py.test.skip("llinterp does not like tuple returns") from rpython.rtyper.test.test_llinterp import interpret times = interpret(lambda: posix.times(), ()) assert isinstance(times, tuple) @@ -119,21 +119,21 @@ res = self.interpret(f,[fi,20]) assert self.ll_to_string(res) == text -if hasattr(os, 'chown'): -def test_chown(self): -f = open(path, "w") -f.write("xyz") -f.close() -def f(): -try: -posix.chown(path, os.getuid(), os.getgid()) -return 1 -except OSError: -return 2 +@py.test.mark.skipif("not hasattr(os, 'chown')") +def test_chown(self): +f = open(path, "w") +f.write("xyz") +f.close() +def f(): +try: +posix.chown(path, os.getuid(), os.getgid()) +return 1 +except OSError: +return 2 -assert self.interpret(f, []) == 1 -os.unlink(path) -assert self.interpret(f, []) == 2 +assert self.interpret(f, []) == 1 +os.unlink(path) +assert self.interpret(f, []) == 2 def test_close(self): def f(fi): @@ -144,70 +144,70 @@ res = self.interpret(f,[fi]) py.test.raises( OSError, os.fstat, fi) -if hasattr(os, 'ftruncate'): -def test_ftruncate(self): -def f(fi,len): -os.ftruncate(fi,len) -fi = os.open(path,os.O_RDWR,0777) -func = self.interpret(f,[fi,6]) -assert os.fstat(fi).st_size == 6 +@py.test.mark.skipif("not hasattr(os, 'ftruncate')") +def test_ftruncate(self): +def f(fi,len): +os.ftruncate(fi,len) +fi = os.open(path,os.O_RDWR,0777) +func = self.interpret(f,[fi,6]) +assert os.fstat(fi).st_size == 6 -if hasattr(os, 'getuid'): -def test_getuid(self): -def f(): -return os.getuid() -assert self.interpret(f, []) == f() +@py.test.mark.skipif("not hasattr(os, 'getuid')") +def test_getuid(self): +def f(): +return os.getuid() +assert self.interpret(f, []) == f() -if hasattr(os, 'getgid'): -def test_getgid(self): -def f(): -return os.getgid() -assert self.interpret(f, []) == f() +@py.test.mark.skipif("not hasattr(os, 'getgid')") +def test_getgid(self): +def f(): +return os.getgid() +assert self.interpret(f, []) == f() -if hasattr(os, 'setuid'): -def test_os_setuid(self): -def f(): -os.setuid(os.getuid()) -return os.getuid() -assert self.interpret(f, []) == f() +@py.test.mark.skipif("not hasattr(os, 'setuid')") +def test_os_setuid(self): +def f(): +os.setuid(os.getuid()) +return os.getuid() +assert self.interpret(f, []) == f() -if hasattr(os, 'sysconf'): -def test_os_sysconf(self): -def f(i): -return os.sysconf(i) -assert self.interpret(f, [13]) == f(13) +@py.test.mark.skipif("not hasattr(os, 'sysconf')") +def test_os_sysconf(self): +def f(i): +return os.sysconf(i) +assert self.interpret(f, [13]) == f(13) -if hasattr(os, 'confstr'): -def test_os_confstr(self): -def f(i): -try: -return os.confstr(i) -except OSError: -return "ps!!" -some_value = os.confstr_names.values()[-1] -res = self.interpret(f, [some_value]) -assert hlstr(res) == f(some_value) -res = self.interpret(f, [94781413]) -assert hlstr(res) == "ps!!" +@py.test.mark.skipif("not hasattr(os, 'confstr')") +def test_os_confstr(self): +def f(i): +try: +return os.confstr(i) +except OSError: +return "ps!!" +some_value = os.confstr_names.values()[-1] +res = self.interpret(f, [some_value]) +assert hlstr(res) == f(some_value) +re
[pypy-commit] pypy py3.3: Fix test so that the truncate() call actually fails
Author: Ronan Lamy Branch: py3.3 Changeset: r82565:2d2859fe2901 Date: 2016-02-26 14:44 +0100 http://bitbucket.org/pypy/pypy/changeset/2d2859fe2901/ Log:Fix test so that the truncate() call actually fails diff --git a/pypy/module/posix/test/test_posix2.py b/pypy/module/posix/test/test_posix2.py --- a/pypy/module/posix/test/test_posix2.py +++ b/pypy/module/posix/test/test_posix2.py @@ -996,7 +996,8 @@ # Check invalid inputs mkfile(dest) raises(OSError, posix.truncate, dest, -1) -raises(OSError, posix.truncate, 1, 1) +with open(dest, 'rb') as f: # f is read-only so cannot be truncated +raises(OSError, posix.truncate, f.fileno(), 1) raises(TypeError, posix.truncate, dest, None) raises(TypeError, posix.truncate, None, None) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Avoid using deprecated pytest features (i.e. yielding test cases and using test methods instead of test functions)
Author: Ronan Lamy Branch: Changeset: r82589:96f67d31a0af Date: 2016-02-27 16:18 +0100 http://bitbucket.org/pypy/pypy/changeset/96f67d31a0af/ Log:Avoid using deprecated pytest features (i.e. yielding test cases and using test methods instead of test functions) diff --git a/rpython/rtyper/test/test_rdict.py b/rpython/rtyper/test/test_rdict.py --- a/rpython/rtyper/test/test_rdict.py +++ b/rpython/rtyper/test/test_rdict.py @@ -1182,118 +1182,113 @@ count_frees += 1 assert count_frees >= 3 -class TestStress: -def test_stress(self): -from rpython.annotator.dictdef import DictKey, DictValue -from rpython.annotator import model as annmodel -dictrepr = rdict.DictRepr(None, rint.signed_repr, rint.signed_repr, - DictKey(None, annmodel.SomeInteger()), - DictValue(None, annmodel.SomeInteger())) -dictrepr.setup() -l_dict = rdict.ll_newdict(dictrepr.DICT) -referencetable = [None] * 400 -referencelength = 0 -value = 0 +def test_stress(): +from rpython.annotator.dictdef import DictKey, DictValue +from rpython.annotator import model as annmodel +dictrepr = rdict.DictRepr(None, rint.signed_repr, rint.signed_repr, +DictKey(None, annmodel.SomeInteger()), +DictValue(None, annmodel.SomeInteger())) +dictrepr.setup() +l_dict = rdict.ll_newdict(dictrepr.DICT) +referencetable = [None] * 400 +referencelength = 0 +value = 0 -def complete_check(): -for n, refvalue in zip(range(len(referencetable)), referencetable): -try: -gotvalue = rdict.ll_dict_getitem(l_dict, n) -except KeyError: -assert refvalue is None -else: -assert gotvalue == refvalue +def complete_check(): +for n, refvalue in zip(range(len(referencetable)), referencetable): +try: +gotvalue = rdict.ll_dict_getitem(l_dict, n) +except KeyError: +assert refvalue is None +else: +assert gotvalue == refvalue -for x in not_really_random(): -n = int(x*100.0)# 0 <= x < 400 -op = repr(x)[-1] -if op <= '2' and referencetable[n] is not None: -rdict.ll_dict_delitem(l_dict, n) -referencetable[n] = None -referencelength -= 1 -elif op <= '6': -rdict.ll_dict_setitem(l_dict, n, value) -if referencetable[n] is None: -referencelength += 1 -referencetable[n] = value -value += 1 +for x in not_really_random(): +n = int(x*100.0)# 0 <= x < 400 +op = repr(x)[-1] +if op <= '2' and referencetable[n] is not None: +rdict.ll_dict_delitem(l_dict, n) +referencetable[n] = None +referencelength -= 1 +elif op <= '6': +rdict.ll_dict_setitem(l_dict, n, value) +if referencetable[n] is None: +referencelength += 1 +referencetable[n] = value +value += 1 +else: +try: +gotvalue = rdict.ll_dict_getitem(l_dict, n) +except KeyError: +assert referencetable[n] is None else: -try: -gotvalue = rdict.ll_dict_getitem(l_dict, n) -except KeyError: -assert referencetable[n] is None -else: -assert gotvalue == referencetable[n] -if 1.38 <= x <= 1.39: -complete_check() -print 'current dict length:', referencelength -assert l_dict.num_items == referencelength -complete_check() +assert gotvalue == referencetable[n] +if 1.38 <= x <= 1.39: +complete_check() +print 'current dict length:', referencelength +assert l_dict.num_items == referencelength +complete_check() -def test_stress_2(self): -yield self.stress_combination, True, False -yield self.stress_combination, False, True -yield self.stress_combination, False, False -yield self.stress_combination, True, True +@py.test.mark.parametrize('key_can_be_none', [True, False]) +@py.test.mark.parametrize('value_can_be_none', [True, False]) +def test_stress_2(key_can_be_none, value_can_be_none): +from rpython.rtyper.lltypesystem.rstr import string_repr +from rpython.annotator.dictdef import DictKey, DictValue +from rpython.annotator import model as annmodel -def stress_combination(self, key_can_be_none, value_can_be_none): -from rpython.rtyper.lltypesystem.rstr import string_repr -from rpython.annot
[pypy-commit] pypy default: Simplify tests by using a dict as the reference.
Author: Ronan Lamy Branch: Changeset: r82592:56afe29ed2bf Date: 2016-02-27 16:35 +0100 http://bitbucket.org/pypy/pypy/changeset/56afe29ed2bf/ Log:Simplify tests by using a dict as the reference. diff --git a/rpython/rtyper/test/test_rdict.py b/rpython/rtyper/test/test_rdict.py --- a/rpython/rtyper/test/test_rdict.py +++ b/rpython/rtyper/test/test_rdict.py @@ -1,5 +1,8 @@ from rpython.translator.translator import TranslationContext +from rpython.annotator import model as annmodel +from rpython.annotator.dictdef import DictKey, DictValue from rpython.rtyper.lltypesystem import lltype, rffi +from rpython.rtyper.lltypesystem.rstr import string_repr from rpython.rtyper import rint from rpython.rtyper.lltypesystem import rdict, rstr from rpython.rtyper.test.tool import BaseRtypingTest @@ -1182,113 +1185,88 @@ count_frees += 1 assert count_frees >= 3 +N_KEYS = 400 def test_stress(): -from rpython.annotator.dictdef import DictKey, DictValue -from rpython.annotator import model as annmodel dictrepr = rdict.DictRepr(None, rint.signed_repr, rint.signed_repr, DictKey(None, annmodel.SomeInteger()), DictValue(None, annmodel.SomeInteger())) dictrepr.setup() l_dict = rdict.ll_newdict(dictrepr.DICT) -referencetable = [None] * 400 -referencelength = 0 +reference = {} value = 0 +def check_value(n): +try: +gotvalue = rdict.ll_dict_getitem(l_dict, n) +except KeyError: +n not in reference +else: +assert gotvalue == reference[n] + def complete_check(): -for n, refvalue in zip(range(len(referencetable)), referencetable): -try: -gotvalue = rdict.ll_dict_getitem(l_dict, n) -except KeyError: -assert refvalue is None -else: -assert gotvalue == refvalue +for n in range(N_KEYS): +check_value(n) for x in not_really_random(): n = int(x*100.0)# 0 <= x < 400 op = repr(x)[-1] -if op <= '2' and referencetable[n] is not None: +if op <= '2' and n in reference: rdict.ll_dict_delitem(l_dict, n) -referencetable[n] = None -referencelength -= 1 +del reference[n] elif op <= '6': rdict.ll_dict_setitem(l_dict, n, value) -if referencetable[n] is None: -referencelength += 1 -referencetable[n] = value +reference[n] = value value += 1 else: -try: -gotvalue = rdict.ll_dict_getitem(l_dict, n) -except KeyError: -assert referencetable[n] is None -else: -assert gotvalue == referencetable[n] +check_value(n) if 1.38 <= x <= 1.39: complete_check() -print 'current dict length:', referencelength -assert l_dict.num_items == referencelength +print 'current dict length:', len(reference) +assert l_dict.num_items == len(reference) complete_check() + @py.test.mark.parametrize('key_can_be_none', [True, False]) @py.test.mark.parametrize('value_can_be_none', [True, False]) def test_stress_2(key_can_be_none, value_can_be_none): -from rpython.rtyper.lltypesystem.rstr import string_repr -from rpython.annotator.dictdef import DictKey, DictValue -from rpython.annotator import model as annmodel - -print -print "Testing combination with can_be_None: keys %s, values %s" % ( -key_can_be_none, value_can_be_none) - class PseudoRTyper: cache_dummy_values = {} dictrepr = rdict.DictRepr(PseudoRTyper(), string_repr, string_repr, DictKey(None, annmodel.SomeString(key_can_be_none)), DictValue(None, annmodel.SomeString(value_can_be_none))) dictrepr.setup() -print dictrepr.lowleveltype -for key, value in dictrepr.DICTENTRY._adtmeths.items(): -print '%s = %s' % (key, value) l_dict = rdict.ll_newdict(dictrepr.DICT) -referencetable = [None] * 400 -referencelength = 0 +reference = {} values = not_really_random() -keytable = [string_repr.convert_const("foo%d" % n) -for n in range(len(referencetable))] +keytable = [string_repr.convert_const("foo%d" % n) for n in range(N_KEYS)] + +def check_value(n): +try: +gotvalue = rdict.ll_dict_getitem(l_dict, keytable[n]) +except KeyError: +assert n not in reference +else: +assert gotvalue == reference[n] def complete_check(): -for n, refvalue in zip(range(len(referencetable)), referencetable): -try: -gotvalue = rdict.ll_dict_getitem(l_dict, keytable[n]) -except KeyError: -assert refvalue is N
[pypy-commit] pypy default: merge heads
Author: Ronan Lamy Branch: Changeset: r82601:fd41d042c08e Date: 2016-02-28 17:42 + http://bitbucket.org/pypy/pypy/changeset/fd41d042c08e/ Log:merge heads diff --git a/rpython/memory/gctransform/boehm.py b/rpython/memory/gctransform/boehm.py --- a/rpython/memory/gctransform/boehm.py +++ b/rpython/memory/gctransform/boehm.py @@ -156,9 +156,9 @@ resulttype = lltype.Signed) hop.genop('int_invert', [v_int], resultvar=hop.spaceop.result) -def gcheader_initdata(self, defnode): +def gcheader_initdata(self, obj): hdr = lltype.malloc(self.HDR, immortal=True) -hdr.hash = lltype.identityhash_nocache(defnode.obj._as_ptr()) +hdr.hash = lltype.identityhash_nocache(obj._as_ptr()) return hdr._obj diff --git a/rpython/memory/gctransform/framework.py b/rpython/memory/gctransform/framework.py --- a/rpython/memory/gctransform/framework.py +++ b/rpython/memory/gctransform/framework.py @@ -1479,8 +1479,8 @@ resulttype=llmemory.Address) llops.genop('raw_memclear', [v_adr, v_totalsize]) -def gcheader_initdata(self, defnode): -o = lltype.top_container(defnode.obj) +def gcheader_initdata(self, obj): +o = lltype.top_container(obj) needs_hash = self.get_prebuilt_hash(o) is not None hdr = self.gc_header_for(o, needs_hash) return hdr._obj diff --git a/rpython/memory/gctransform/refcounting.py b/rpython/memory/gctransform/refcounting.py --- a/rpython/memory/gctransform/refcounting.py +++ b/rpython/memory/gctransform/refcounting.py @@ -286,6 +286,6 @@ hop.genop("direct_call", [self.identityhash_ptr, v_adr], resultvar=hop.spaceop.result) -def gcheader_initdata(self, defnode): -top = lltype.top_container(defnode.obj) +def gcheader_initdata(self, obj): +top = lltype.top_container(obj) return self.gcheaderbuilder.header_of_object(top)._obj diff --git a/rpython/translator/c/node.py b/rpython/translator/c/node.py --- a/rpython/translator/c/node.py +++ b/rpython/translator/c/node.py @@ -546,7 +546,7 @@ if needs_gcheader(T): gct = self.db.gctransformer if gct is not None: -self.gc_init = gct.gcheader_initdata(self) +self.gc_init = gct.gcheader_initdata(self.obj) db.getcontainernode(self.gc_init) else: self.gc_init = None @@ -677,7 +677,7 @@ if needs_gcheader(T): gct = self.db.gctransformer if gct is not None: -self.gc_init = gct.gcheader_initdata(self) +self.gc_init = gct.gcheader_initdata(self.obj) db.getcontainernode(self.gc_init) else: self.gc_init = None ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Create stateful hypothesis test for rdict.
Author: Ronan Lamy Branch: Changeset: r82600:9053529ba3ba Date: 2016-02-28 17:24 + http://bitbucket.org/pypy/pypy/changeset/9053529ba3ba/ Log:Create stateful hypothesis test for rdict. This will eventually replace test_stress() and test_stress_2() diff --git a/rpython/rtyper/test/test_rdict.py b/rpython/rtyper/test/test_rdict.py --- a/rpython/rtyper/test/test_rdict.py +++ b/rpython/rtyper/test/test_rdict.py @@ -1270,3 +1270,72 @@ print 'current dict length:', len(reference) assert l_dict.num_items == len(reference) complete_check() + +from hypothesis.strategies import builds, sampled_from, binary, just + +class Action(object): +pass + +class SetItem(Action): +def __init__(self, key, value): +self.key = key +self.value = value + +def __repr__(self): +return 'SetItem(%r, %r)' % (self.key, self.value) + +class DelItem(Action): +def __init__(self, key): +self.key = key + +def __repr__(self): +return 'DelItem(%r)' % (self.key) + +class CompleteCheck(Action): +pass + +st_keys = binary() +st_values = binary() +st_setitem = builds(SetItem, st_keys, st_values) + +def st_delitem(keys): +return builds(DelItem, sampled_from(keys)) + +from hypothesis.stateful import GenericStateMachine + +_ll = string_repr.convert_const + +class StressTest(GenericStateMachine): +def __init__(self): +class PseudoRTyper: +cache_dummy_values = {} +dictrepr = rdict.DictRepr(PseudoRTyper(), string_repr, string_repr, +DictKey(None, annmodel.SomeString(False)), +DictValue(None, annmodel.SomeString(False))) +dictrepr.setup() +self.l_dict = rdict.ll_newdict(dictrepr.DICT) +self.reference = {} + +def steps(self): +return (st_setitem | st_delitem(self.reference) | just(CompleteCheck())) if self.reference else (st_setitem | just(CompleteCheck())) + +def execute_step(self, action): +if isinstance(action, SetItem): +ll_key = string_repr.convert_const(action.key) +ll_value = string_repr.convert_const(action.value) +rdict.ll_dict_setitem(self.l_dict, ll_key, ll_value) +self.reference[action.key] = action.value +assert rdict.ll_contains(self.l_dict, ll_key) +elif isinstance(action, DelItem): +ll_key = string_repr.convert_const(action.key) +rdict.ll_dict_delitem(self.l_dict, ll_key) +del self.reference[action.key] +assert not rdict.ll_contains(self.l_dict, ll_key) +elif isinstance(action, CompleteCheck): +assert self.l_dict.num_items == len(self.reference) +for key, value in self.reference.iteritems(): +assert rdict.ll_dict_getitem(self.l_dict, _ll(key)) == _ll(value) + + +TestHyp = StressTest.TestCase + ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Move execute_step() implementation to the Action subclasses
Author: Ronan Lamy Branch: Changeset: r82613:a1d15704499c Date: 2016-02-29 15:24 + http://bitbucket.org/pypy/pypy/changeset/a1d15704499c/ Log:Move execute_step() implementation to the Action subclasses diff --git a/rpython/rtyper/test/test_rdict.py b/rpython/rtyper/test/test_rdict.py --- a/rpython/rtyper/test/test_rdict.py +++ b/rpython/rtyper/test/test_rdict.py @@ -1284,6 +1284,13 @@ def __repr__(self): return 'SetItem(%r, %r)' % (self.key, self.value) +def execute(self, state): +ll_key = string_repr.convert_const(self.key) +ll_value = string_repr.convert_const(self.value) +rdict.ll_dict_setitem(state.l_dict, ll_key, ll_value) +state.reference[self.key] = self.value +assert rdict.ll_contains(state.l_dict, ll_key) + class DelItem(Action): def __init__(self, key): self.key = key @@ -1291,8 +1298,17 @@ def __repr__(self): return 'DelItem(%r)' % (self.key) +def execute(self, state): +ll_key = string_repr.convert_const(self.key) +rdict.ll_dict_delitem(state.l_dict, ll_key) +del state.reference[self.key] +assert not rdict.ll_contains(state.l_dict, ll_key) + class CompleteCheck(Action): -pass +def execute(self, state): +assert state.l_dict.num_items == len(state.reference) +for key, value in state.reference.iteritems(): +assert rdict.ll_dict_getitem(state.l_dict, _ll(key)) == _ll(value) st_keys = binary() st_values = binary() @@ -1320,22 +1336,6 @@ return (st_setitem | st_delitem(self.reference) | just(CompleteCheck())) if self.reference else (st_setitem | just(CompleteCheck())) def execute_step(self, action): -if isinstance(action, SetItem): -ll_key = string_repr.convert_const(action.key) -ll_value = string_repr.convert_const(action.value) -rdict.ll_dict_setitem(self.l_dict, ll_key, ll_value) -self.reference[action.key] = action.value -assert rdict.ll_contains(self.l_dict, ll_key) -elif isinstance(action, DelItem): -ll_key = string_repr.convert_const(action.key) -rdict.ll_dict_delitem(self.l_dict, ll_key) -del self.reference[action.key] -assert not rdict.ll_contains(self.l_dict, ll_key) -elif isinstance(action, CompleteCheck): -assert self.l_dict.num_items == len(self.reference) -for key, value in self.reference.iteritems(): -assert rdict.ll_dict_getitem(self.l_dict, _ll(key)) == _ll(value) - +action.execute(self) TestHyp = StressTest.TestCase - ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Add clear() and copy() actions
Author: Ronan Lamy Branch: Changeset: r82614:b212924f1c8d Date: 2016-02-29 16:06 + http://bitbucket.org/pypy/pypy/changeset/b212924f1c8d/ Log:Add clear() and copy() actions diff --git a/rpython/rtyper/test/test_rdict.py b/rpython/rtyper/test/test_rdict.py --- a/rpython/rtyper/test/test_rdict.py +++ b/rpython/rtyper/test/test_rdict.py @@ -1304,6 +1304,15 @@ del state.reference[self.key] assert not rdict.ll_contains(state.l_dict, ll_key) +class CopyDict(Action): +def execute(self, state): +state.l_dict = rdict.ll_copy(state.l_dict) + +class ClearDict(Action): +def execute(self, state): +rdict.ll_clear(state.l_dict) +state.reference.clear() + class CompleteCheck(Action): def execute(self, state): assert state.l_dict.num_items == len(state.reference) @@ -1333,7 +1342,13 @@ self.reference = {} def steps(self): -return (st_setitem | st_delitem(self.reference) | just(CompleteCheck())) if self.reference else (st_setitem | just(CompleteCheck())) +global_actions = [CopyDict(), ClearDict(), CompleteCheck()] +if self.reference: +return ( +st_setitem | st_delitem(self.reference) | +sampled_from(global_actions)) +else: +return (st_setitem | sampled_from(global_actions)) def execute_step(self, action): action.execute(self) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Improve hypothesis test: catch infinite loops (posix only) and do the complete check once and only once, at the end of the run.
Author: Ronan Lamy Branch: Changeset: r82615:721ef287647d Date: 2016-02-29 18:36 + http://bitbucket.org/pypy/pypy/changeset/721ef287647d/ Log:Improve hypothesis test: catch infinite loops (posix only) and do the complete check once and only once, at the end of the run. diff --git a/rpython/rtyper/test/test_rdict.py b/rpython/rtyper/test/test_rdict.py --- a/rpython/rtyper/test/test_rdict.py +++ b/rpython/rtyper/test/test_rdict.py @@ -1,3 +1,6 @@ +from contextlib import contextmanager +import signal + from rpython.translator.translator import TranslationContext from rpython.annotator import model as annmodel from rpython.annotator.dictdef import DictKey, DictValue @@ -12,6 +15,27 @@ import py py.log.setconsumer("rtyper", py.log.STDOUT) +if hasattr(signal, 'alarm'): +@contextmanager +def signal_timeout(n): +"""A flaky context manager that throws an exception if the body of the +`with` block runs for longer than `n` seconds. +""" +def handler(signum, frame): +raise RuntimeError('timeout') +signal.signal(signal.SIGALRM, handler) +signal.alarm(n) +try: +yield +finally: +signal.alarm(0) +else: +@contextmanager +def signal_timeout(n): +yield + + + def not_really_random(): """A random-ish generator, which also generates nice patterns from time to time. Could be useful to detect problems associated with specific usage patterns.""" @@ -1313,12 +1337,6 @@ rdict.ll_clear(state.l_dict) state.reference.clear() -class CompleteCheck(Action): -def execute(self, state): -assert state.l_dict.num_items == len(state.reference) -for key, value in state.reference.iteritems(): -assert rdict.ll_dict_getitem(state.l_dict, _ll(key)) == _ll(value) - st_keys = binary() st_values = binary() st_setitem = builds(SetItem, st_keys, st_values) @@ -1342,7 +1360,7 @@ self.reference = {} def steps(self): -global_actions = [CopyDict(), ClearDict(), CompleteCheck()] +global_actions = [CopyDict(), ClearDict()] if self.reference: return ( st_setitem | st_delitem(self.reference) | @@ -1351,6 +1369,13 @@ return (st_setitem | sampled_from(global_actions)) def execute_step(self, action): -action.execute(self) +with signal_timeout(1): # catches infinite loops +action.execute(self) + +def teardown(self): +assert rdict.ll_dict_len(self.l_dict) == len(self.reference) +for key, value in self.reference.iteritems(): +assert rdict.ll_dict_getitem(self.l_dict, _ll(key)) == _ll(value) + TestHyp = StressTest.TestCase ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Make hypothesis test parametric in the key and value types
Author: Ronan Lamy Branch: Changeset: r82617:959fe6807849 Date: 2016-02-29 21:57 + http://bitbucket.org/pypy/pypy/changeset/959fe6807849/ Log:Make hypothesis test parametric in the key and value types diff --git a/rpython/rtyper/test/test_rdict.py b/rpython/rtyper/test/test_rdict.py --- a/rpython/rtyper/test/test_rdict.py +++ b/rpython/rtyper/test/test_rdict.py @@ -1,8 +1,9 @@ +import sys from contextlib import contextmanager import signal from rpython.translator.translator import TranslationContext -from rpython.annotator import model as annmodel +from rpython.annotator.model import SomeInteger, SomeString from rpython.annotator.dictdef import DictKey, DictValue from rpython.rtyper.lltypesystem import lltype, rffi from rpython.rtyper.lltypesystem.rstr import string_repr @@ -1213,8 +1214,8 @@ def test_stress(): dictrepr = rdict.DictRepr(None, rint.signed_repr, rint.signed_repr, -DictKey(None, annmodel.SomeInteger()), -DictValue(None, annmodel.SomeInteger())) +DictKey(None, SomeInteger()), +DictValue(None, SomeInteger())) dictrepr.setup() l_dict = rdict.ll_newdict(dictrepr.DICT) reference = {} @@ -1257,8 +1258,8 @@ class PseudoRTyper: cache_dummy_values = {} dictrepr = rdict.DictRepr(PseudoRTyper(), string_repr, string_repr, -DictKey(None, annmodel.SomeString(key_can_be_none)), -DictValue(None, annmodel.SomeString(value_can_be_none))) +DictKey(None, SomeString(key_can_be_none)), +DictValue(None, SomeString(value_can_be_none))) dictrepr.setup() l_dict = rdict.ll_newdict(dictrepr.DICT) reference = {} @@ -1295,87 +1296,114 @@ assert l_dict.num_items == len(reference) complete_check() -from hypothesis.strategies import builds, sampled_from, binary, just +from hypothesis.strategies import builds, sampled_from, binary, just, integers +from hypothesis.stateful import GenericStateMachine, run_state_machine_as_test + +def ann2strategy(s_value): +if isinstance(s_value, SomeString): +if s_value.can_be_None: +return binary() | just(None) +else: +return binary() +elif isinstance(s_value, SomeInteger): +return integers(min_value=~sys.maxint, max_value=sys.maxint) +else: +raise TypeError("Cannot convert annotation %s to a strategy" % s_value) + class Action(object): -pass +def __repr__(self): +return "%s()" % self.__class__.__name__ -class SetItem(Action): -def __init__(self, key, value): -self.key = key -self.value = value +class PseudoRTyper: +cache_dummy_values = {} -def __repr__(self): -return 'SetItem(%r, %r)' % (self.key, self.value) +# XXX: None keys crash the test, but translation sort-of allows it +@py.test.mark.parametrize('s_key', +[SomeString(), SomeInteger()]) +@py.test.mark.parametrize('s_value', +[SomeString(can_be_None=True), SomeString(), SomeInteger()]) +def test_hypothesis(s_key, s_value): +rtyper = PseudoRTyper() +r_key = s_key.rtyper_makerepr(rtyper) +r_value = s_value.rtyper_makerepr(rtyper) +dictrepr = rdict.DictRepr(rtyper, r_key, r_value, +DictKey(None, s_key), +DictValue(None, s_value)) +dictrepr.setup() -def execute(self, state): -ll_key = string_repr.convert_const(self.key) -ll_value = string_repr.convert_const(self.value) -rdict.ll_dict_setitem(state.l_dict, ll_key, ll_value) -state.reference[self.key] = self.value -assert rdict.ll_contains(state.l_dict, ll_key) +_ll_key = r_key.convert_const +_ll_value = r_value.convert_const -class DelItem(Action): -def __init__(self, key): -self.key = key +class SetItem(Action): +def __init__(self, key, value): +self.key = key +self.value = value -def __repr__(self): -return 'DelItem(%r)' % (self.key) +def __repr__(self): +return 'SetItem(%r, %r)' % (self.key, self.value) -def execute(self, state): -ll_key = string_repr.convert_const(self.key) -rdict.ll_dict_delitem(state.l_dict, ll_key) -del state.reference[self.key] -assert not rdict.ll_contains(state.l_dict, ll_key) +def execute(self, state): +ll_key = _ll_key(self.key) +ll_value = _ll_value(self.value) +rdict.ll_dict_setitem(state.l_dict, ll_key, ll_value) +state.reference[self.key] = self.value +assert rdict.ll_contains(state.l_dict, ll_key) -class CopyDict(Action): -def execute(self, state): -state.l_dict = rdict.ll_copy(state.l_dict) +class DelItem(Action): +def __init__(self, key): +self.key = key -class ClearDict(Action): -def e
[pypy-commit] pypy default: kill dead and/or superseded tests
Author: Ronan Lamy Branch: Changeset: r82618:51611a2b96f6 Date: 2016-02-29 22:08 + http://bitbucket.org/pypy/pypy/changeset/51611a2b96f6/ Log:kill dead and/or superseded tests diff --git a/rpython/rtyper/test/test_rdict.py b/rpython/rtyper/test/test_rdict.py --- a/rpython/rtyper/test/test_rdict.py +++ b/rpython/rtyper/test/test_rdict.py @@ -14,7 +14,20 @@ from rpython.rlib.rarithmetic import r_int, r_uint, r_longlong, r_ulonglong import py -py.log.setconsumer("rtyper", py.log.STDOUT) +from hypothesis.strategies import builds, sampled_from, binary, just, integers +from hypothesis.stateful import GenericStateMachine, run_state_machine_as_test + +def ann2strategy(s_value): +if isinstance(s_value, SomeString): +if s_value.can_be_None: +return binary() | just(None) +else: +return binary() +elif isinstance(s_value, SomeInteger): +return integers(min_value=~sys.maxint, max_value=sys.maxint) +else: +raise TypeError("Cannot convert annotation %s to a strategy" % s_value) + if hasattr(signal, 'alarm'): @contextmanager @@ -36,7 +49,6 @@ yield - def not_really_random(): """A random-ish generator, which also generates nice patterns from time to time. Could be useful to detect problems associated with specific usage patterns.""" @@ -1032,28 +1044,6 @@ assert r_AB_dic.lowleveltype == r_BA_dic.lowleveltype -def test_dict_resize(self): -py.test.skip("test written for non-ordered dicts, update or kill") -# XXX we no longer automatically resize on 'del'. We need to -# hack a bit in this test to trigger a resize by continuing to -# fill the dict's table while keeping the actual size very low -# in order to force a resize to shrink the table back -def func(want_empty): -d = self.newdict() -for i in range(rdict.DICT_INITSIZE << 1): -d[chr(ord('a') + i)] = i -if want_empty: -for i in range(rdict.DICT_INITSIZE << 1): -del d[chr(ord('a') + i)] -for i in range(rdict.DICT_INITSIZE << 3): -d[chr(ord('A') - i)] = i -del d[chr(ord('A') - i)] -return d -res = self.interpret(func, [0]) -assert len(res.entries) > rdict.DICT_INITSIZE -res = self.interpret(func, [1]) -assert len(res.entries) == rdict.DICT_INITSIZE - def test_opt_dummykeymarker(self): def f(): d = {"hello": None} @@ -1145,170 +1135,6 @@ DICT = lltype.typeOf(llres.item1) assert sorted(DICT.TO.entries.TO.OF._flds) == ['f_hash', 'key', 'value'] -def test_deleted_entry_reusage_with_colliding_hashes(self): -py.test.skip("test written for non-ordered dicts, update or kill") -def lowlevelhash(value): -p = rstr.mallocstr(len(value)) -for i in range(len(value)): -p.chars[i] = value[i] -return rstr.LLHelpers.ll_strhash(p) - -def func(c1, c2): -c1 = chr(c1) -c2 = chr(c2) -d = self.newdict() -d[c1] = 1 -d[c2] = 2 -del d[c1] -return d[c2] - -char_by_hash = {} -base = rdict.DICT_INITSIZE -for y in range(0, 256): -y = chr(y) -y_hash = lowlevelhash(y) % base -char_by_hash.setdefault(y_hash, []).append(y) - -x, y = char_by_hash[0][:2] # find a collision - -res = self.interpret(func, [ord(x), ord(y)]) -assert res == 2 - -def func2(c1, c2): -c1 = chr(c1) -c2 = chr(c2) -d = self.newdict() -d[c1] = 1 -d[c2] = 2 -del d[c1] -d[c1] = 3 -return d - -res = self.interpret(func2, [ord(x), ord(y)]) -for i in range(len(res.entries)): -assert not (res.entries.everused(i) and not res.entries.valid(i)) - -def func3(c0, c1, c2, c3, c4, c5, c6, c7): -d = self.newdict() -c0 = chr(c0) ; d[c0] = 1; del d[c0] -c1 = chr(c1) ; d[c1] = 1; del d[c1] -c2 = chr(c2) ; d[c2] = 1; del d[c2] -c3 = chr(c3) ; d[c3] = 1; del d[c3] -c4 = chr(c4) ; d[c4] = 1; del d[c4] -c5 = chr(c5) ; d[c5] = 1; del d[c5] -c6 = chr(c6) ; d[c6] = 1; del d[c6] -c7 = chr(c7) ; d[c7] = 1; del d[c7] -return d - -if rdict.DICT_INITSIZE != 8: -py.test.skip("make dict tests more indepdent from initsize") -res = self.interpret(func3, [ord(char_by_hash[i][0]) - for i in range(rdict.DICT_INITSIZE)]) -count_frees = 0 -for i in range(len(res.entries)): -if not res.entries.everused(i): -count_frees += 1 -assert count_frees >= 3 - -N_
[pypy-commit] pypy default: Test rdict also with char, unicode, unichar
Author: Ronan Lamy Branch: Changeset: r82639:b8922598b1c9 Date: 2016-03-01 16:52 + http://bitbucket.org/pypy/pypy/changeset/b8922598b1c9/ Log:Test rdict also with char, unicode, unichar diff --git a/rpython/rtyper/test/test_rdict.py b/rpython/rtyper/test/test_rdict.py --- a/rpython/rtyper/test/test_rdict.py +++ b/rpython/rtyper/test/test_rdict.py @@ -3,26 +3,35 @@ import signal from rpython.translator.translator import TranslationContext -from rpython.annotator.model import SomeInteger, SomeString +from rpython.annotator.model import ( +SomeInteger, SomeString, SomeChar, SomeUnicodeString, SomeUnicodeCodePoint) from rpython.annotator.dictdef import DictKey, DictValue from rpython.rtyper.lltypesystem import lltype, rffi -from rpython.rtyper.lltypesystem.rstr import string_repr -from rpython.rtyper import rint -from rpython.rtyper.lltypesystem import rdict, rstr +from rpython.rtyper.lltypesystem import rdict from rpython.rtyper.test.tool import BaseRtypingTest from rpython.rlib.objectmodel import r_dict from rpython.rlib.rarithmetic import r_int, r_uint, r_longlong, r_ulonglong import py -from hypothesis.strategies import builds, sampled_from, binary, just, integers +from hypothesis.strategies import ( +builds, sampled_from, binary, just, integers, text, characters) from hypothesis.stateful import GenericStateMachine, run_state_machine_as_test def ann2strategy(s_value): -if isinstance(s_value, SomeString): +if isinstance(s_value, SomeChar): +return builds(chr, integers(min_value=0, max_value=255)) +elif isinstance(s_value, SomeString): if s_value.can_be_None: return binary() | just(None) else: return binary() +elif isinstance(s_value, SomeUnicodeCodePoint): +return characters() +elif isinstance(s_value, SomeUnicodeString): +if s_value.can_be_None: +return text() | just(None) +else: +return text() elif isinstance(s_value, SomeInteger): return integers(min_value=~sys.maxint, max_value=sys.maxint) else: @@ -239,9 +248,8 @@ def test_dict_copy(self): def func(): -# XXX this does not work if we use chars, only! dic = self.newdict() -dic['ab'] = 1 +dic['a'] = 1 dic['b'] = 2 d2 = dic.copy() ok = 1 @@ -1146,9 +1154,9 @@ # XXX: None keys crash the test, but translation sort-of allows it @py.test.mark.parametrize('s_key', -[SomeString(), SomeInteger()]) +[SomeString(), SomeInteger(), SomeChar(), SomeUnicodeString(), SomeUnicodeCodePoint()]) @py.test.mark.parametrize('s_value', -[SomeString(can_be_None=True), SomeString(), SomeInteger()]) +[SomeString(can_be_None=True), SomeString(), SomeChar(), SomeInteger(), SomeUnicodeString(), SomeUnicodeCodePoint()]) def test_hypothesis(s_key, s_value): rtyper = PseudoRTyper() r_key = s_key.rtyper_makerepr(rtyper) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Refactor parametric test into a single stateful test with increased run-time
Author: Ronan Lamy Branch: Changeset: r82658:eeb057746657 Date: 2016-03-02 15:02 + http://bitbucket.org/pypy/pypy/changeset/eeb057746657/ Log:Refactor parametric test into a single stateful test with increased run-time diff --git a/rpython/rtyper/test/test_rdict.py b/rpython/rtyper/test/test_rdict.py --- a/rpython/rtyper/test/test_rdict.py +++ b/rpython/rtyper/test/test_rdict.py @@ -13,8 +13,9 @@ from rpython.rlib.rarithmetic import r_int, r_uint, r_longlong, r_ulonglong import py +from hypothesis import given, settings from hypothesis.strategies import ( -builds, sampled_from, binary, just, integers, text, characters) +builds, sampled_from, binary, just, integers, text, characters, tuples) from hypothesis.stateful import GenericStateMachine, run_state_machine_as_test def ann2strategy(s_value): @@ -1152,92 +1153,123 @@ class PseudoRTyper: cache_dummy_values = {} + # XXX: None keys crash the test, but translation sort-of allows it -@py.test.mark.parametrize('s_key', -[SomeString(), SomeInteger(), SomeChar(), SomeUnicodeString(), SomeUnicodeCodePoint()]) -@py.test.mark.parametrize('s_value', -[SomeString(can_be_None=True), SomeString(), SomeChar(), SomeInteger(), SomeUnicodeString(), SomeUnicodeCodePoint()]) -def test_hypothesis(s_key, s_value): -rtyper = PseudoRTyper() -r_key = s_key.rtyper_makerepr(rtyper) -r_value = s_value.rtyper_makerepr(rtyper) -dictrepr = rdict.DictRepr(rtyper, r_key, r_value, -DictKey(None, s_key), -DictValue(None, s_value)) -dictrepr.setup() +keytypes_s = [ +SomeString(), SomeInteger(), SomeChar(), +SomeUnicodeString(), SomeUnicodeCodePoint()] +st_keys = sampled_from(keytypes_s) +st_values = sampled_from(keytypes_s + [SomeString(can_be_None=True)]) -_ll_key = r_key.convert_const -_ll_value = r_value.convert_const +class Space(object): +def __init__(self, s_key, s_value): +self.s_key = s_key +self.s_value = s_value +rtyper = PseudoRTyper() +r_key = s_key.rtyper_makerepr(rtyper) +r_value = s_value.rtyper_makerepr(rtyper) +dictrepr = rdict.DictRepr(rtyper, r_key, r_value, +DictKey(None, s_key), +DictValue(None, s_value)) +dictrepr.setup() +self.l_dict = rdict.ll_newdict(dictrepr.DICT) +self.reference = {} +self.ll_key = r_key.convert_const +self.ll_value = r_value.convert_const -class SetItem(Action): -def __init__(self, key, value): -self.key = key -self.value = value +def setitem(self, key, value): +ll_key = self.ll_key(key) +ll_value = self.ll_value(value) +rdict.ll_dict_setitem(self.l_dict, ll_key, ll_value) +self.reference[key] = value +assert rdict.ll_contains(self.l_dict, ll_key) -def __repr__(self): -return 'SetItem(%r, %r)' % (self.key, self.value) +def delitem(self, key): +ll_key = self.ll_key(key) +rdict.ll_dict_delitem(self.l_dict, ll_key) +del self.reference[key] +assert not rdict.ll_contains(self.l_dict, ll_key) -def execute(self, state): -ll_key = _ll_key(self.key) -ll_value = _ll_value(self.value) -rdict.ll_dict_setitem(state.l_dict, ll_key, ll_value) -state.reference[self.key] = self.value -assert rdict.ll_contains(state.l_dict, ll_key) +def copydict(self): +self.l_dict = rdict.ll_copy(self.l_dict) -class DelItem(Action): -def __init__(self, key): -self.key = key +def cleardict(self): +rdict.ll_clear(self.l_dict) +self.reference.clear() +assert rdict.ll_dict_len(self.l_dict) == 0 -def __repr__(self): -return 'DelItem(%r)' % (self.key) +def fullcheck(self): +assert rdict.ll_dict_len(self.l_dict) == len(self.reference) +for key, value in self.reference.iteritems(): +assert (rdict.ll_dict_getitem(self.l_dict, self.ll_key(key)) == +self.ll_value(value)) -def execute(self, state): -ll_key = _ll_key(self.key) -rdict.ll_dict_delitem(state.l_dict, ll_key) -del state.reference[self.key] -assert not rdict.ll_contains(state.l_dict, ll_key) +class SetItem(Action): +def __init__(self, key, value): +self.key = key +self.value = value -class CopyDict(Action): -def execute(self, state): -state.l_dict = rdict.ll_copy(state.l_dict) +def __repr__(self): +return 'SetItem(%r, %r)' % (self.key, self.value) -class ClearDict(Action): -def execute(self, state): -rdict.ll_clear(state.l_dict) -state.reference.clear() +def execute(self, space): +space.setitem(self.key, self.value) -st_keys = ann2strategy(s_key) -st
[pypy-commit] pypy default: cleanup
Author: Ronan Lamy Branch: Changeset: r82663:db9d97b06d3a Date: 2016-03-02 20:16 + http://bitbucket.org/pypy/pypy/changeset/db9d97b06d3a/ Log:cleanup diff --git a/rpython/rtyper/test/test_rdict.py b/rpython/rtyper/test/test_rdict.py --- a/rpython/rtyper/test/test_rdict.py +++ b/rpython/rtyper/test/test_rdict.py @@ -13,7 +13,7 @@ from rpython.rlib.rarithmetic import r_int, r_uint, r_longlong, r_ulonglong import py -from hypothesis import given, settings +from hypothesis import settings from hypothesis.strategies import ( builds, sampled_from, binary, just, integers, text, characters, tuples) from hypothesis.stateful import GenericStateMachine, run_state_machine_as_test @@ -1145,15 +1145,20 @@ assert sorted(DICT.TO.entries.TO.OF._flds) == ['f_hash', 'key', 'value'] +class Action(object): +def __init__(self, method, args): +self.method = method +self.args = args -class Action(object): +def execute(self, space): +getattr(space, self.method)(*self.args) + def __repr__(self): -return "%s()" % self.__class__.__name__ +return "space.%s(%s)" % (self.method, ', '.join(map(repr, self.args))) class PseudoRTyper: cache_dummy_values = {} - # XXX: None keys crash the test, but translation sort-of allows it keytypes_s = [ SomeString(), SomeInteger(), SomeChar(), @@ -1204,53 +1209,27 @@ assert (rdict.ll_dict_getitem(self.l_dict, self.ll_key(key)) == self.ll_value(value)) -class SetItem(Action): -def __init__(self, key, value): -self.key = key -self.value = value - -def __repr__(self): -return 'SetItem(%r, %r)' % (self.key, self.value) - -def execute(self, space): -space.setitem(self.key, self.value) - -class DelItem(Action): -def __init__(self, key): -self.key = key - -def __repr__(self): -return 'DelItem(%r)' % (self.key) - -def execute(self, space): -space.delitem(self.key) - -class CopyDict(Action): -def execute(self, space): -space.copydict() - -class ClearDict(Action): -def execute(self, space): -space.cleardict() - class StressTest(GenericStateMachine): def __init__(self): self.space = None def st_setitem(self): -return builds(SetItem, self.st_keys, self.st_values) +return builds(Action, +just('setitem'), tuples(self.st_keys, self.st_values)) def st_updateitem(self): -return builds(SetItem, sampled_from(self.space.reference), -self.st_values) +return builds(Action, +just('setitem'), +tuples(sampled_from(self.space.reference), self.st_values)) def st_delitem(self): -return builds(DelItem, sampled_from(self.space.reference)) +return builds(Action, +just('delitem'), tuples(sampled_from(self.space.reference))) def steps(self): if not self.space: -return builds(Space, st_keys, st_values) -global_actions = [CopyDict(), ClearDict()] +return builds(Action, just('setup'), tuples(st_keys, st_values)) +global_actions = [Action('copydict', ()), Action('cleardict', ())] if self.space.reference: return ( self.st_setitem() | sampled_from(global_actions) | @@ -1259,8 +1238,8 @@ return (self.st_setitem() | sampled_from(global_actions)) def execute_step(self, action): -if isinstance(action, Space): -self.space = action +if action.method == 'setup': +self.space = Space(*action.args) self.st_keys = ann2strategy(self.space.s_key) self.st_values = ann2strategy(self.space.s_value) return ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Fix typo that made a test useless
Author: Ronan Lamy Branch: Changeset: r82673:4d2c1de4fbff Date: 2016-03-03 14:12 + http://bitbucket.org/pypy/pypy/changeset/4d2c1de4fbff/ Log:Fix typo that made a test useless diff --git a/rpython/rtyper/test/test_rdict.py b/rpython/rtyper/test/test_rdict.py --- a/rpython/rtyper/test/test_rdict.py +++ b/rpython/rtyper/test/test_rdict.py @@ -1048,7 +1048,7 @@ s_BA_dic = s.items[1] r_AB_dic = rtyper.getrepr(s_AB_dic) -r_BA_dic = rtyper.getrepr(s_AB_dic) +r_BA_dic = rtyper.getrepr(s_BA_dic) assert r_AB_dic.lowleveltype == r_BA_dic.lowleveltype ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Reuse rdict hypothesis test in test_rordereddict.py
Author: Ronan Lamy Branch: Changeset: r82678:67aa41de326b Date: 2016-03-03 15:52 + http://bitbucket.org/pypy/pypy/changeset/67aa41de326b/ Log:Reuse rdict hypothesis test in test_rordereddict.py diff --git a/rpython/rtyper/test/test_rdict.py b/rpython/rtyper/test/test_rdict.py --- a/rpython/rtyper/test/test_rdict.py +++ b/rpython/rtyper/test/test_rdict.py @@ -1166,50 +1166,51 @@ st_keys = sampled_from(keytypes_s) st_values = sampled_from(keytypes_s + [SomeString(can_be_None=True)]) -class Space(object): +class MappingSpace(object): def __init__(self, s_key, s_value): self.s_key = s_key self.s_value = s_value rtyper = PseudoRTyper() r_key = s_key.rtyper_makerepr(rtyper) r_value = s_value.rtyper_makerepr(rtyper) -dictrepr = rdict.DictRepr(rtyper, r_key, r_value, +dictrepr = self.MappingRepr(rtyper, r_key, r_value, DictKey(None, s_key), DictValue(None, s_value)) dictrepr.setup() -self.l_dict = rdict.ll_newdict(dictrepr.DICT) -self.reference = {} +self.l_dict = self.newdict(dictrepr) +self.reference = self.new_reference() self.ll_key = r_key.convert_const self.ll_value = r_value.convert_const def setitem(self, key, value): ll_key = self.ll_key(key) ll_value = self.ll_value(value) -rdict.ll_dict_setitem(self.l_dict, ll_key, ll_value) +self.ll_setitem(self.l_dict, ll_key, ll_value) self.reference[key] = value -assert rdict.ll_contains(self.l_dict, ll_key) +assert self.ll_contains(self.l_dict, ll_key) def delitem(self, key): ll_key = self.ll_key(key) -rdict.ll_dict_delitem(self.l_dict, ll_key) +self.ll_delitem(self.l_dict, ll_key) del self.reference[key] -assert not rdict.ll_contains(self.l_dict, ll_key) +assert not self.ll_contains(self.l_dict, ll_key) def copydict(self): -self.l_dict = rdict.ll_copy(self.l_dict) +self.l_dict = self.ll_copy(self.l_dict) +assert self.ll_len(self.l_dict) == len(self.reference) def cleardict(self): -rdict.ll_clear(self.l_dict) +self.ll_clear(self.l_dict) self.reference.clear() -assert rdict.ll_dict_len(self.l_dict) == 0 +assert self.ll_len(self.l_dict) == 0 def fullcheck(self): -assert rdict.ll_dict_len(self.l_dict) == len(self.reference) +assert self.ll_len(self.l_dict) == len(self.reference) for key, value in self.reference.iteritems(): -assert (rdict.ll_dict_getitem(self.l_dict, self.ll_key(key)) == +assert (self.ll_getitem(self.l_dict, self.ll_key(key)) == self.ll_value(value)) -class StressTest(GenericStateMachine): +class MappingSM(GenericStateMachine): def __init__(self): self.space = None @@ -1239,7 +1240,7 @@ def execute_step(self, action): if action.method == 'setup': -self.space = Space(*action.args) +self.space = self.Space(*action.args) self.st_keys = ann2strategy(self.space.s_key) self.st_values = ann2strategy(self.space.s_value) return @@ -1250,5 +1251,24 @@ if self.space: self.space.fullcheck() + +class DictSpace(MappingSpace): +MappingRepr = rdict.DictRepr +new_reference = dict +ll_getitem = staticmethod(rdict.ll_dict_getitem) +ll_setitem = staticmethod(rdict.ll_dict_setitem) +ll_delitem = staticmethod(rdict.ll_dict_delitem) +ll_len = staticmethod(rdict.ll_dict_len) +ll_contains = staticmethod(rdict.ll_contains) +ll_copy = staticmethod(rdict.ll_copy) +ll_clear = staticmethod(rdict.ll_clear) + +def newdict(self, repr): +return rdict.ll_newdict(repr.DICT) + +class DictSM(MappingSM): +Space = DictSpace + def test_hypothesis(): -run_state_machine_as_test(StressTest, settings(max_examples=500, stateful_step_count=100)) +run_state_machine_as_test( +DictSM, settings(max_examples=500, stateful_step_count=100)) diff --git a/rpython/rtyper/test/test_rordereddict.py b/rpython/rtyper/test/test_rordereddict.py --- a/rpython/rtyper/test/test_rordereddict.py +++ b/rpython/rtyper/test/test_rordereddict.py @@ -1,14 +1,18 @@ - import py from collections import OrderedDict +from hypothesis import settings +from hypothesis.stateful import run_state_machine_as_test + from rpython.rtyper.lltypesystem import lltype, rffi from rpython.rtyper.lltypesystem import rordereddict, rstr from rpython.rlib.rarithmetic import intmask from rpython.rtyper.annlowlevel import llstr, hlstr -from rpython.rtyper.test.test_rdict import BaseTestRDict +from rpython.rtyper.test.test_rdict import ( +BaseTestRDict, MappingSpace, MappingSM) from rpython.rlib import objectmodel +rodct = rordereddict def get_indexes(ll_d): return ll_d.indexes._ob
[pypy-commit] pypy default: kill obsolete tests
Author: Ronan Lamy Branch: Changeset: r82679:9db8617310dc Date: 2016-03-03 16:25 + http://bitbucket.org/pypy/pypy/changeset/9db8617310dc/ Log:kill obsolete tests diff --git a/rpython/rtyper/test/test_rdict.py b/rpython/rtyper/test/test_rdict.py --- a/rpython/rtyper/test/test_rdict.py +++ b/rpython/rtyper/test/test_rdict.py @@ -59,19 +59,6 @@ yield -def not_really_random(): -"""A random-ish generator, which also generates nice patterns from time to time. -Could be useful to detect problems associated with specific usage patterns.""" -import random -x = random.random() -print 'random seed: %r' % (x,) -for i in range(12000): -r = 3.4 + i/2.0 -x = r*x - x*x -assert 0 <= x < 4 -yield x - - class BaseTestRDict(BaseRtypingTest): def test_dict_creation(self): def createdict(i): diff --git a/rpython/rtyper/test/test_rordereddict.py b/rpython/rtyper/test/test_rordereddict.py --- a/rpython/rtyper/test/test_rordereddict.py +++ b/rpython/rtyper/test/test_rordereddict.py @@ -334,129 +334,6 @@ assert res == 6 -class TestStress: - -def test_stress(self): -from rpython.annotator.dictdef import DictKey, DictValue -from rpython.annotator import model as annmodel -from rpython.rtyper import rint -from rpython.rtyper.test.test_rdict import not_really_random -rodct = rordereddict -dictrepr = rodct.OrderedDictRepr( - None, rint.signed_repr, rint.signed_repr, - DictKey(None, annmodel.SomeInteger()), - DictValue(None, annmodel.SomeInteger())) -dictrepr.setup() -l_dict = rodct.ll_newdict(dictrepr.DICT) -referencetable = [None] * 400 -referencelength = 0 -value = 0 - -def complete_check(): -for n, refvalue in zip(range(len(referencetable)), referencetable): -try: -gotvalue = rodct.ll_dict_getitem(l_dict, n) -except KeyError: -assert refvalue is None -else: -assert gotvalue == refvalue - -for x in not_really_random(): -n = int(x*100.0)# 0 <= x < 400 -op = repr(x)[-1] -if op <= '2' and referencetable[n] is not None: -rodct.ll_dict_delitem(l_dict, n) -referencetable[n] = None -referencelength -= 1 -elif op <= '6': -rodct.ll_dict_setitem(l_dict, n, value) -if referencetable[n] is None: -referencelength += 1 -referencetable[n] = value -value += 1 -else: -try: -gotvalue = rodct.ll_dict_getitem(l_dict, n) -except KeyError: -assert referencetable[n] is None -else: -assert gotvalue == referencetable[n] -if 1.38 <= x <= 1.39: -complete_check() -print 'current dict length:', referencelength -assert l_dict.num_live_items == referencelength -complete_check() - -def test_stress_2(self): -yield self.stress_combination, True, False -yield self.stress_combination, False, True -yield self.stress_combination, False, False -yield self.stress_combination, True, True - -def stress_combination(self, key_can_be_none, value_can_be_none): -from rpython.rtyper.lltypesystem.rstr import string_repr -from rpython.annotator.dictdef import DictKey, DictValue -from rpython.annotator import model as annmodel -from rpython.rtyper.test.test_rdict import not_really_random -rodct = rordereddict - -print -print "Testing combination with can_be_None: keys %s, values %s" % ( -key_can_be_none, value_can_be_none) - -class PseudoRTyper: -cache_dummy_values = {} -dictrepr = rodct.OrderedDictRepr( - PseudoRTyper(), string_repr, string_repr, - DictKey(None, annmodel.SomeString(key_can_be_none)), - DictValue(None, annmodel.SomeString(value_can_be_none))) -dictrepr.setup() -print dictrepr.lowleveltype -#for key, value in dictrepr.DICTENTRY._adtmeths.items(): -#print '%s = %s' % (key, value) -l_dict = rodct.ll_newdict(dictrepr.DICT) -referencetable = [None] * 400 -referencelength = 0 -values = not_really_random() -keytable = [string_repr.convert_const("foo%d" % n) -for n in range(len(referencetable))] - -def complete_check(): -for n, refvalue in zip(range(len(referencetable)), referencetable): -try: -gotvalue = rodct.ll_dict_getitem
[pypy-commit] pypy rawrefcount-review: Rename some parameters for clarity
Author: Ronan Lamy Branch: rawrefcount-review Changeset: r82774:111c68c340a7 Date: 2016-03-04 16:48 + http://bitbucket.org/pypy/pypy/changeset/111c68c340a7/ Log:Rename some parameters for clarity diff --git a/rpython/rlib/rawrefcount.py b/rpython/rlib/rawrefcount.py --- a/rpython/rlib/rawrefcount.py +++ b/rpython/rlib/rawrefcount.py @@ -6,7 +6,6 @@ # import sys, weakref from rpython.rtyper.lltypesystem import lltype, llmemory -from rpython.rlib.objectmodel import we_are_translated, specialize from rpython.rtyper.extregistry import ExtRegistryEntry from rpython.rlib import rgc @@ -36,27 +35,23 @@ _d_list = [] _dealloc_trigger_callback = dealloc_trigger_callback -def create_link_pypy(p, ob): +def create_link_pypy(gcobj, ob): "NOT_RPYTHON: a link where the PyPy object contains some or all the data" -#print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) -assert p not in _pypy2ob -#assert not ob.c_ob_pypy_link -ob.c_ob_pypy_link = _build_pypy_link(p) -_pypy2ob[p] = ob +assert gcobj not in _pypy2ob +ob.c_ob_pypy_link = _build_pypy_link(gcobj) +_pypy2ob[gcobj] = ob _p_list.append(ob) -def create_link_pyobj(p, ob): +def create_link_pyobj(gcobj, ob): """NOT_RPYTHON: a link where the PyObject contains all the data. - from_obj() will not work on this 'p'.""" -#print 'create_link_pyobj\n\t%s\n\t%s' % (p, ob) -assert p not in _pypy2ob -#assert not ob.c_ob_pypy_link -ob.c_ob_pypy_link = _build_pypy_link(p) + from_obj() will not work on this 'gcobj'.""" +assert gcobj not in _pypy2ob +ob.c_ob_pypy_link = _build_pypy_link(gcobj) _o_list.append(ob) -def from_obj(OB_PTR_TYPE, p): +def from_obj(OB_PTR_TYPE, gcobj): "NOT_RPYTHON" -ob = _pypy2ob.get(p) +ob = _pypy2ob.get(gcobj) if ob is None: return lltype.nullptr(OB_PTR_TYPE.TO) assert lltype.typeOf(ob) == OB_PTR_TYPE @@ -67,9 +62,9 @@ link = ob.c_ob_pypy_link if link == 0: return None -p = _adr2pypy[link] -assert isinstance(p, Class) -return p +gcobj = _adr2pypy[link] +assert isinstance(gcobj, Class) +return gcobj def next_dead(OB_PTR_TYPE): if len(_d_list) == 0: @@ -163,24 +158,24 @@ # -def _unspec_p(hop, v_p): -assert isinstance(v_p.concretetype, lltype.Ptr) -assert v_p.concretetype.TO._gckind == 'gc' -return hop.genop('cast_opaque_ptr', [v_p], resulttype=llmemory.GCREF) +def _unspec_gc(hop, v_gcobj): +assert isinstance(v_gcobj.concretetype, lltype.Ptr) +assert v_gcobj.concretetype.TO._gckind == 'gc' +return hop.genop('cast_opaque_ptr', [v_gcobj], resulttype=llmemory.GCREF) def _unspec_ob(hop, v_ob): assert isinstance(v_ob.concretetype, lltype.Ptr) assert v_ob.concretetype.TO._gckind == 'raw' return hop.genop('cast_ptr_to_adr', [v_ob], resulttype=llmemory.Address) -def _spec_p(hop, v_p): -assert v_p.concretetype == llmemory.GCREF -return hop.genop('cast_opaque_ptr', [v_p], +def _spec_gc(hop, v_gcref): +assert v_gcref.concretetype == llmemory.GCREF +return hop.genop('cast_opaque_ptr', [v_gcref], resulttype=hop.r_result.lowleveltype) -def _spec_ob(hop, v_ob): -assert v_ob.concretetype == llmemory.Address -return hop.genop('cast_adr_to_ptr', [v_ob], +def _spec_ob(hop, v_adr): +assert v_adr.concretetype == llmemory.Address +return hop.genop('cast_adr_to_ptr', [v_adr], resulttype=hop.r_result.lowleveltype) @@ -200,7 +195,7 @@ class Entry(ExtRegistryEntry): _about_ = (create_link_pypy, create_link_pyobj) -def compute_result_annotation(self, s_p, s_ob): +def compute_result_annotation(self, s_gcobj, s_ob): pass def specialize_call(self, hop): @@ -208,28 +203,28 @@ name = 'gc_rawrefcount_create_link_pypy' elif self.instance is create_link_pyobj: name = 'gc_rawrefcount_create_link_pyobj' -v_p, v_ob = hop.inputargs(*hop.args_r) +v_gcobj, v_ob = hop.inputargs(*hop.args_r) hop.exception_cannot_occur() -hop.genop(name, [_unspec_p(hop, v_p), _unspec_ob(hop, v_ob)]) +hop.genop(name, [_unspec_gc(hop, v_gcobj), _unspec_ob(hop, v_ob)]) class Entry(ExtRegistryEntry): _about_ = from_obj -def compute_result_annotation(self, s_OB_PTR_TYPE, s_p): +def compute_result_annotation(self, s_OB_PTR_TYPE, s_gcobj): from rpython.annotator import model as annmodel from rpython.rtyper.llannotation import lltype_to_annotation -assert (isinstance(s_p, annmodel.SomeInstance) or -annmodel.s_None.contains(s_p)) +assert (isinstance(s_gcobj, annmodel.SomeInstance) or +annmodel.s_None.contains(s_gcobj)) assert s_OB_PTR_TYPE.is_constant() return lltype_to_annotation(s_OB_PTR_TYPE.const) def specialize_call(self
[pypy-commit] pypy rawrefcount-review: A branch to remove the conceptual dependency of rpython.rlib.rawrefcount on PyPy specifics
Author: Ronan Lamy Branch: rawrefcount-review Changeset: r82773:aeab1067f34a Date: 2016-03-04 15:18 + http://bitbucket.org/pypy/pypy/changeset/aeab1067f34a/ Log:A branch to remove the conceptual dependency of rpython.rlib.rawrefcount on PyPy specifics ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy rawrefcount-review: Move rpython implementations next to their functions
Author: Ronan Lamy Branch: rawrefcount-review Changeset: r82775:267edcb35bc5 Date: 2016-03-04 16:59 + http://bitbucket.org/pypy/pypy/changeset/267edcb35bc5/ Log:Move rpython implementations next to their functions diff --git a/rpython/rlib/rawrefcount.py b/rpython/rlib/rawrefcount.py --- a/rpython/rlib/rawrefcount.py +++ b/rpython/rlib/rawrefcount.py @@ -35,6 +35,19 @@ _d_list = [] _dealloc_trigger_callback = dealloc_trigger_callback +class Entry(ExtRegistryEntry): +_about_ = init + +def compute_result_annotation(self, s_dealloc_callback): +from rpython.rtyper.llannotation import SomePtr +assert isinstance(s_dealloc_callback, SomePtr) # ll-ptr-to-function + +def specialize_call(self, hop): +hop.exception_cannot_occur() +[v_dealloc_callback] = hop.inputargs(hop.args_r[0]) +hop.genop('gc_rawrefcount_init', [v_dealloc_callback]) + + def create_link_pypy(gcobj, ob): "NOT_RPYTHON: a link where the PyPy object contains some or all the data" assert gcobj not in _pypy2ob @@ -49,6 +62,22 @@ ob.c_ob_pypy_link = _build_pypy_link(gcobj) _o_list.append(ob) +class Entry(ExtRegistryEntry): +_about_ = (create_link_pypy, create_link_pyobj) + +def compute_result_annotation(self, s_gcobj, s_ob): +pass + +def specialize_call(self, hop): +if self.instance is create_link_pypy: +name = 'gc_rawrefcount_create_link_pypy' +elif self.instance is create_link_pyobj: +name = 'gc_rawrefcount_create_link_pyobj' +v_gcobj, v_ob = hop.inputargs(*hop.args_r) +hop.exception_cannot_occur() +hop.genop(name, [_unspec_gc(hop, v_gcobj), _unspec_ob(hop, v_ob)]) + + def from_obj(OB_PTR_TYPE, gcobj): "NOT_RPYTHON" ob = _pypy2ob.get(gcobj) @@ -57,6 +86,25 @@ assert lltype.typeOf(ob) == OB_PTR_TYPE return ob +class Entry(ExtRegistryEntry): +_about_ = from_obj + +def compute_result_annotation(self, s_OB_PTR_TYPE, s_gcobj): +from rpython.annotator import model as annmodel +from rpython.rtyper.llannotation import lltype_to_annotation +assert (isinstance(s_gcobj, annmodel.SomeInstance) or +annmodel.s_None.contains(s_gcobj)) +assert s_OB_PTR_TYPE.is_constant() +return lltype_to_annotation(s_OB_PTR_TYPE.const) + +def specialize_call(self, hop): +hop.exception_cannot_occur() +v_gcobj = hop.inputarg(hop.args_r[1], arg=1) +v_adr = hop.genop('gc_rawrefcount_from_obj', [_unspec_gc(hop, v_gcobj)], + resulttype=llmemory.Address) +return _spec_ob(hop, v_adr) + + def to_obj(Class, ob): "NOT_RPYTHON" link = ob.c_ob_pypy_link @@ -66,6 +114,25 @@ assert isinstance(gcobj, Class) return gcobj +class Entry(ExtRegistryEntry): +_about_ = to_obj + +def compute_result_annotation(self, s_Class, s_ob): +from rpython.annotator import model as annmodel +from rpython.rtyper.llannotation import SomePtr +assert isinstance(s_ob, SomePtr) +assert s_Class.is_constant() +classdef = self.bookkeeper.getuniqueclassdef(s_Class.const) +return annmodel.SomeInstance(classdef, can_be_None=True) + +def specialize_call(self, hop): +hop.exception_cannot_occur() +v_ob = hop.inputarg(hop.args_r[1], arg=1) +v_gcobj = hop.genop('gc_rawrefcount_to_obj', [_unspec_ob(hop, v_ob)], +resulttype=llmemory.GCREF) +return _spec_gc(hop, v_gcobj) + + def next_dead(OB_PTR_TYPE): if len(_d_list) == 0: return lltype.nullptr(OB_PTR_TYPE.TO) @@ -73,6 +140,21 @@ assert lltype.typeOf(ob) == OB_PTR_TYPE return ob +class Entry(ExtRegistryEntry): +_about_ = next_dead + +def compute_result_annotation(self, s_OB_PTR_TYPE): +from rpython.rtyper.llannotation import lltype_to_annotation +assert s_OB_PTR_TYPE.is_constant() +return lltype_to_annotation(s_OB_PTR_TYPE.const) + +def specialize_call(self, hop): +hop.exception_cannot_occur() +v_rawaddr = hop.genop('gc_rawrefcount_next_dead', [], + resulttype=llmemory.Address) +return _spec_ob(hop, v_rawaddr) + + def _collect(track_allocation=True): """NOT_RPYTHON: for tests only. Emulates a GC collection. Will invoke dealloc_trigger_callback() once if there are objects @@ -177,83 +259,3 @@ assert v_adr.concretetype == llmemory.Address return hop.genop('cast_adr_to_ptr', [v_adr], resulttype=hop.r_result.lowleveltype) - - -class Entry(ExtRegistryEntry): -_about_ = init - -def compute_result_annotation(self, s_dealloc_callback): -from rpython.rtyper.llannotation import SomePtr -assert isinstance(s_dealloc_callback, SomePtr) # ll-ptr-to-function - -def specialize_call(self, hop): -hop.exception_cannot_occur() -[v_dealloc_callb
[pypy-commit] pypy rawrefcount-review: Factor out some repeated code
Author: Ronan Lamy Branch: rawrefcount-review Changeset: r82780:0d0ac385be9c Date: 2016-03-04 19:14 + http://bitbucket.org/pypy/pypy/changeset/0d0ac385be9c/ Log:Factor out some repeated code diff --git a/rpython/memory/gc/incminimark.py b/rpython/memory/gc/incminimark.py --- a/rpython/memory/gc/incminimark.py +++ b/rpython/memory/gc/incminimark.py @@ -285,7 +285,7 @@ assert small_request_threshold % WORD == 0 self.read_from_env = read_from_env self.nursery_size = nursery_size - + self.small_request_threshold = small_request_threshold self.major_collection_threshold = major_collection_threshold self.growth_rate_max = growth_rate_max @@ -729,7 +729,7 @@ # nursery. "Next area" in this case is the space between the # pinned object in front of nusery_top and the pinned object # after that. Graphically explained: -# +# # |- allocating totalsize failed in this area # | |- nursery_top # | ||- pinned object in front of nursery_top, @@ -774,7 +774,7 @@ # true after that. In that case we do a second step. # The goal is to avoid too high memory peaks if the # program allocates a lot of surviving objects. -# +# if (self.gc_state != STATE_SCANNING or self.threshold_reached()): @@ -2767,6 +2767,14 @@ def _pyobj(self, pyobjaddr): return llmemory.cast_adr_to_ptr(pyobjaddr, self.PYOBJ_HDR_PTR) +def _rrc_set_gc_partner(self, adr_rawobj, adr_gcobj): +int_gcobj = llmemory.cast_adr_to_int(adr_gcobj, "symbolic") +self._pyobj(adr_rawobj).ob_pypy_link = int_gcobj + +def _rrc_get_gc_partner(self, adr_rawobj): +int_gcobj = self._pyobj(adr_rawobj).ob_pypy_link +return llmemory.cast_int_to_adr(int_gcobj) + def rawrefcount_init(self, dealloc_trigger_callback): # see pypy/doc/discussion/rawrefcount.rst if not self.rrc_enabled: @@ -2797,8 +2805,7 @@ def rawrefcount_create_link_pypy(self, gcobj, pyobject): ll_assert(self.rrc_enabled, "rawrefcount.init not called") obj = llmemory.cast_ptr_to_adr(gcobj) -objint = llmemory.cast_adr_to_int(obj, "symbolic") -self._pyobj(pyobject).ob_pypy_link = objint +self._rrc_set_gc_partner(pyobject, obj) # lst = self.rrc_p_list_young if self.is_in_nursery(obj): @@ -2813,12 +2820,11 @@ def rawrefcount_create_link_pyobj(self, gcobj, pyobject): ll_assert(self.rrc_enabled, "rawrefcount.init not called") obj = llmemory.cast_ptr_to_adr(gcobj) +self._rrc_set_gc_partner(pyobject, obj) if self.is_young_object(obj): self.rrc_o_list_young.append(pyobject) else: self.rrc_o_list_old.append(pyobject) -objint = llmemory.cast_adr_to_int(obj, "symbolic") -self._pyobj(pyobject).ob_pypy_link = objint # there is no rrc_o_dict def rawrefcount_from_obj(self, gcobj): @@ -2830,7 +2836,7 @@ return dct.get(obj) def rawrefcount_to_obj(self, pyobject): -obj = llmemory.cast_int_to_adr(self._pyobj(pyobject).ob_pypy_link) +obj = self._rrc_get_gc_partner(pyobject) return llmemory.cast_adr_to_ptr(obj, llmemory.GCREF) def rawrefcount_next_dead(self): @@ -2859,8 +2865,7 @@ pass # the corresponding object may die else: # force the corresponding object to be alive -intobj = self._pyobj(pyobject).ob_pypy_link -singleaddr.address[0] = llmemory.cast_int_to_adr(intobj) +singleaddr.address[0] = self._rrc_get_gc_partner(pyobject) self._trace_drag_out(singleaddr, llmemory.NULL) def rrc_minor_collection_free(self): @@ -2876,14 +2881,12 @@ no_o_dict) def _rrc_minor_free(self, pyobject, surviving_list, surviving_dict): -intobj = self._pyobj(pyobject).ob_pypy_link -obj = llmemory.cast_int_to_adr(intobj) +obj = self._rrc_get_gc_partner(pyobject) if self.is_in_nursery(obj): if self.is_forwarded(obj): # Common case: survives and moves obj = self.get_forwarding_address(obj) -intobj = llmemory.cast_adr_to_int(obj, "symbolic") -self._pyobj(pyobject).ob_pypy_link = intobj +self._rrc_set_gc_partner(pyobject, obj) surviving = True if surviving_dict: # Surviving nursery object: was originally in @@ -2947,8 +2950,7 @@ pass # the corresponding object may die else: # force the corresponding object to be alive -
[pypy-commit] pypy rawrefcount-review: Use @py.test.mark.parametrize
Author: Ronan Lamy Branch: rawrefcount-review Changeset: r82783:73435fbb4416 Date: 2016-03-04 20:57 + http://bitbucket.org/pypy/pypy/changeset/73435fbb4416/ Log:Use @py.test.mark.parametrize diff --git a/rpython/memory/gc/test/test_rawrefcount.py b/rpython/memory/gc/test/test_rawrefcount.py --- a/rpython/memory/gc/test/test_rawrefcount.py +++ b/rpython/memory/gc/test/test_rawrefcount.py @@ -74,7 +74,8 @@ return p1 return p1, p1ref, r1, r1addr, check_alive -def test_rawrefcount_objects_basic(self, old=False): +@py.test.mark.parametrize('old', [True, False]) +def test_rawrefcount_objects_basic(self, old): p1, p1ref, r1, r1addr, check_alive = ( self._rawrefcount_pair(42, is_light=True, create_old=old)) p2 = self.malloc(S) @@ -95,7 +96,8 @@ lltype.free(r1, flavor='raw') lltype.free(r2, flavor='raw') -def test_rawrefcount_objects_collection_survives_from_raw(self, old=False): +@py.test.mark.parametrize('old', [True, False]) +def test_rawrefcount_objects_collection_survives_from_raw(self, old): p1, p1ref, r1, r1addr, check_alive = ( self._rawrefcount_pair(42, is_light=True, create_old=old)) check_alive(0) @@ -114,7 +116,8 @@ assert self.trigger == [] assert self.gc.rawrefcount_next_dead() == llmemory.NULL -def test_rawrefcount_dies_quickly(self, old=False): +@py.test.mark.parametrize('old', [True, False]) +def test_rawrefcount_dies_quickly(self, old): p1, p1ref, r1, r1addr, check_alive = ( self._rawrefcount_pair(42, is_light=True, create_old=old)) check_alive(0) @@ -126,7 +129,8 @@ py.test.raises(RuntimeError, "p1.x")# dead self.gc.check_no_more_rawrefcount_state() -def test_rawrefcount_objects_collection_survives_from_obj(self, old=False): +@py.test.mark.parametrize('old', [True, False]) +def test_rawrefcount_objects_collection_survives_from_obj(self, old): p1, p1ref, r1, r1addr, check_alive = ( self._rawrefcount_pair(42, is_light=True, create_old=old)) check_alive(0) @@ -144,16 +148,8 @@ py.test.raises(RuntimeError, "p1.x")# dead self.gc.check_no_more_rawrefcount_state() -def test_rawrefcount_objects_basic_old(self): -self.test_rawrefcount_objects_basic(old=True) -def test_rawrefcount_objects_collection_survives_from_raw_old(self): -self.test_rawrefcount_objects_collection_survives_from_raw(old=True) -def test_rawrefcount_dies_quickly_old(self): -self.test_rawrefcount_dies_quickly(old=True) -def test_rawrefcount_objects_collection_survives_from_obj_old(self): -self.test_rawrefcount_objects_collection_survives_from_obj(old=True) - -def test_pypy_nonlight_survives_from_raw(self, old=False): +@py.test.mark.parametrize('old', [True, False]) +def test_pypy_nonlight_survives_from_raw(self, old): p1, p1ref, r1, r1addr, check_alive = ( self._rawrefcount_pair(42, is_light=False, create_old=old)) check_alive(0) @@ -175,7 +171,8 @@ self.gc.check_no_more_rawrefcount_state() lltype.free(r1, flavor='raw') -def test_pypy_nonlight_survives_from_obj(self, old=False): +@py.test.mark.parametrize('old', [True, False]) +def test_pypy_nonlight_survives_from_obj(self, old): p1, p1ref, r1, r1addr, check_alive = ( self._rawrefcount_pair(42, is_light=False, create_old=old)) check_alive(0) @@ -196,7 +193,8 @@ self.gc.check_no_more_rawrefcount_state() lltype.free(r1, flavor='raw') -def test_pypy_nonlight_dies_quickly(self, old=False): +@py.test.mark.parametrize('old', [True, False]) +def test_pypy_nonlight_dies_quickly(self, old): p1, p1ref, r1, r1addr, check_alive = ( self._rawrefcount_pair(42, is_light=False, create_old=old)) check_alive(0) @@ -213,13 +211,6 @@ self.gc.check_no_more_rawrefcount_state() lltype.free(r1, flavor='raw') -def test_pypy_nonlight_survives_from_raw_old(self): -self.test_pypy_nonlight_survives_from_raw(old=True) -def test_pypy_nonlight_survives_from_obj_old(self): -self.test_pypy_nonlight_survives_from_obj(old=True) -def test_pypy_nonlight_dies_quickly_old(self): -self.test_pypy_nonlight_dies_quickly(old=True) - def test_pyobject_pypy_link_dies_on_minor_collection(self): p1, p1ref, r1, r1addr, check_alive = ( self._rawrefcount_pair(42, is_pyobj=True)) @@ -231,7 +222,8 @@ self.gc.check_no_more_rawrefcount_state() lltype.free(r1, flavor='raw') -def test_pyobject_dies(self, old=False): +@py.test.mark.parametrize('old', [True, False]) +def test_pyobject_dies(self, old): p1, p1ref, r1, r1addr, check_alive = ( self._rawrefcount_pair(42, is_pyobj=True, create_old=ol
[pypy-commit] pypy rawrefcount-review: Try to simplify tests
Author: Ronan Lamy Branch: rawrefcount-review Changeset: r82822:805b6b103730 Date: 2016-03-06 16:09 + http://bitbucket.org/pypy/pypy/changeset/805b6b103730/ Log:Try to simplify tests diff --git a/rpython/memory/gc/test/test_rawrefcount.py b/rpython/memory/gc/test/test_rawrefcount.py --- a/rpython/memory/gc/test/test_rawrefcount.py +++ b/rpython/memory/gc/test/test_rawrefcount.py @@ -28,42 +28,58 @@ count2 = len(self.trigger) assert count2 - count1 == expected_trigger +def create_gcobj(self, intval, old=False, immortal=False): +if immortal: +p1 = lltype.malloc(S, immortal=True) +p1.x = intval +self.consider_constant(p1) +return p1 +p1 = self.malloc(S) +p1.x = intval +if old: +self.stackroots.append(p1) +self._collect(major=False) +p1 = self.stackroots.pop() +return p1 + +def create_rawobj(self, immortal=False): +r1 = lltype.malloc(PYOBJ_HDR, flavor='raw', immortal=immortal) +r1.ob_refcnt = 0 +r1.ob_pypy_link = 0 +return r1 + +def create_link(self, rawobj, gcobj, is_light=False, is_pyobj=False): +if is_light: +rawobj.ob_refcnt += REFCNT_FROM_PYPY_LIGHT +else: +rawobj.ob_refcnt += REFCNT_FROM_PYPY +rawaddr = llmemory.cast_ptr_to_adr(rawobj) +gcref = lltype.cast_opaque_ptr(llmemory.GCREF, gcobj) +if is_pyobj: +assert not is_light +self.gc.rawrefcount_create_link_pyobj(gcref, rawaddr) +else: +self.gc.rawrefcount_create_link_pypy(gcref, rawaddr) + def _rawrefcount_pair(self, intval, is_light=False, is_pyobj=False, create_old=False, create_immortal=False): +self.trigger = [] +self.gc.rawrefcount_init(lambda: self.trigger.append(1)) +# +p1 = self.create_gcobj(intval, old=create_old, immortal=create_immortal) +r1 = self.create_rawobj(immortal=create_immortal) +self.create_link(r1, p1, is_light=is_light, is_pyobj=is_pyobj) if is_light: rc = REFCNT_FROM_PYPY_LIGHT else: rc = REFCNT_FROM_PYPY -self.trigger = [] -self.gc.rawrefcount_init(lambda: self.trigger.append(1)) -# -if create_immortal: -p1 = lltype.malloc(S, immortal=True) -else: -p1 = self.malloc(S) -p1.x = intval -if create_immortal: -self.consider_constant(p1) -elif create_old: -self.stackroots.append(p1) -self._collect(major=False) -p1 = self.stackroots.pop() -p1ref = lltype.cast_opaque_ptr(llmemory.GCREF, p1) -r1 = lltype.malloc(PYOBJ_HDR, flavor='raw', immortal=create_immortal) -r1.ob_refcnt = rc -r1.ob_pypy_link = 0 -r1addr = llmemory.cast_ptr_to_adr(r1) -if is_pyobj: -assert not is_light -self.gc.rawrefcount_create_link_pyobj(p1ref, r1addr) -else: -self.gc.rawrefcount_create_link_pypy(p1ref, r1addr) assert r1.ob_refcnt == rc assert r1.ob_pypy_link != 0 def check_alive(extra_refcount): assert r1.ob_refcnt == rc + extra_refcount assert r1.ob_pypy_link != 0 +r1addr = llmemory.cast_ptr_to_adr(r1) p1ref = self.gc.rawrefcount_to_obj(r1addr) p1 = lltype.cast_opaque_ptr(lltype.Ptr(S), p1ref) assert p1.x == intval @@ -72,25 +88,25 @@ else: assert self.gc.rawrefcount_from_obj(p1ref) == llmemory.NULL return p1 -return p1, p1ref, r1, r1addr, check_alive +return p1, r1, check_alive @py.test.mark.parametrize('old', [True, False]) def test_rawrefcount_objects_basic(self, old): -p1, p1ref, r1, r1addr, check_alive = ( +p1, r1, check_alive = ( self._rawrefcount_pair(42, is_light=True, create_old=old)) -p2 = self.malloc(S) -p2.x = 84 +p1ref = lltype.cast_opaque_ptr(llmemory.GCREF, p1) +r1addr = llmemory.cast_ptr_to_adr(r1) +assert r1.ob_pypy_link != 0 +assert self.gc.rawrefcount_from_obj(p1ref) == r1addr +assert self.gc.rawrefcount_to_obj(r1addr) == p1ref +p2 = self.create_gcobj(84) +r2 = self.create_rawobj() +r2.ob_refcnt += 1 p2ref = lltype.cast_opaque_ptr(llmemory.GCREF, p2) -r2 = lltype.malloc(PYOBJ_HDR, flavor='raw') -r2.ob_refcnt = 1 -r2.ob_pypy_link = 0 r2addr = llmemory.cast_ptr_to_adr(r2) # p2 and r2 are not linked -assert r1.ob_pypy_link != 0 assert r2.ob_pypy_link == 0 -assert self.gc.rawrefcount_from_obj(p1ref) == r1addr assert self.gc.rawrefcount_from_obj(p2ref) == llmemory.NULL -assert self.gc.rawrefcount_to_obj(r1addr) == p1ref a
[pypy-commit] pypy rawrefcount-review: Move test class state into separate class GCSpace
Author: Ronan Lamy Branch: rawrefcount-review Changeset: r82823:d4a535a667c8 Date: 2016-03-06 17:58 + http://bitbucket.org/pypy/pypy/changeset/d4a535a667c8/ Log:Move test class state into separate class GCSpace diff --git a/rpython/memory/gc/test/test_direct.py b/rpython/memory/gc/test/test_direct.py --- a/rpython/memory/gc/test/test_direct.py +++ b/rpython/memory/gc/test/test_direct.py @@ -13,7 +13,7 @@ from rpython.memory.gc import minimark, incminimark from rpython.memory.gctypelayout import zero_gc_pointers_inside, zero_gc_pointers from rpython.rlib.debug import debug_print -import pdb + WORD = LONG_BIT // 8 ADDR_ARRAY = lltype.Array(llmemory.Address) @@ -29,15 +29,15 @@ class DirectRootWalker(object): -def __init__(self, tester): -self.tester = tester +def __init__(self, space): +self.space = space def walk_roots(self, collect_stack_root, collect_static_in_prebuilt_nongc, collect_static_in_prebuilt_gc, is_minor=False): -gc = self.tester.gc -layoutbuilder = self.tester.layoutbuilder +gc = self.space.gc +layoutbuilder = self.space.layoutbuilder if collect_static_in_prebuilt_gc: for addrofaddr in layoutbuilder.addresses_of_static_ptrs: if addrofaddr.address[0]: @@ -47,7 +47,7 @@ if addrofaddr.address[0]: collect_static_in_prebuilt_nongc(gc, addrofaddr) if collect_stack_root: -stackroots = self.tester.stackroots +stackroots = self.space.stackroots a = lltype.malloc(ADDR_ARRAY, len(stackroots), flavor='raw') for i in range(len(a)): a[i] = llmemory.cast_ptr_to_adr(stackroots[i]) @@ -67,22 +67,18 @@ pass -class BaseDirectGCTest(object): -GC_PARAMS = {} - -def setup_method(self, meth): +class GCSpace(object): +def __init__(self, GCClass, GC_PARAMS): from rpython.config.translationoption import get_combined_translation_config config = get_combined_translation_config(translating=True).translation self.stackroots = [] -GC_PARAMS = self.GC_PARAMS.copy() -if hasattr(meth, 'GC_PARAMS'): -GC_PARAMS.update(meth.GC_PARAMS) +GC_PARAMS = GC_PARAMS.copy() GC_PARAMS['translated_to_c'] = False -self.gc = self.GCClass(config, **GC_PARAMS) +self.gc = GCClass(config, **GC_PARAMS) self.gc.DEBUG = True self.rootwalker = DirectRootWalker(self) self.gc.set_root_walker(self.rootwalker) -self.layoutbuilder = TypeLayoutBuilder(self.GCClass) +self.layoutbuilder = TypeLayoutBuilder(GCClass) self.get_type_id = self.layoutbuilder.get_type_id self.layoutbuilder.initialize_gc_query_function(self.gc) self.gc.setup() @@ -115,9 +111,34 @@ zero_gc_pointers_inside(obj_ptr, TYPE) return obj_ptr +class BaseDirectGCTest(object): +GC_PARAMS = {} + +def setup_method(self, meth): +GC_PARAMS = self.GC_PARAMS.copy() +if hasattr(meth, 'GC_PARAMS'): +GC_PARAMS.update(meth.GC_PARAMS) +self.space = GCSpace(self.GCClass, GC_PARAMS) +self.stackroots = self.space.stackroots +self.gc = self.space.gc +self.get_type_id = self.space.get_type_id + +def consider_constant(self, p): +self.space.consider_constant(p) + +def write(self, p, fieldname, newvalue): +self.space.write(p, fieldname, newvalue) + +def writearray(self, p, index, newvalue): +self.space.writearray(p, index, newvalue) + +def malloc(self, TYPE, n=None): +return self.space.malloc(TYPE, n) + + class DirectGCTest(BaseDirectGCTest): - + def test_simple(self): p = self.malloc(S) p.x = 5 @@ -679,7 +700,7 @@ #ensure all the ptr fields are zeroed assert p.prev == lltype.nullptr(S) assert p.next == lltype.nullptr(S) - + def test_malloc_varsize_no_cleanup(self): x = lltype.Signed VAR1 = lltype.GcArray(x) @@ -744,4 +765,4 @@ assert elem.prev == lltype.nullptr(S) assert elem.next == lltype.nullptr(S) - + ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy rawrefcount-review: Factor out all interpreter-dependent behaviour into a few GC methods
Author: Ronan Lamy Branch: rawrefcount-review Changeset: r82864:7daebe814a60 Date: 2016-03-06 00:27 + http://bitbucket.org/pypy/pypy/changeset/7daebe814a60/ Log:Factor out all interpreter-dependent behaviour into a few GC methods diff --git a/rpython/memory/gc/incminimark.py b/rpython/memory/gc/incminimark.py --- a/rpython/memory/gc/incminimark.py +++ b/rpython/memory/gc/incminimark.py @@ -2775,6 +2775,26 @@ int_gcobj = self._pyobj(adr_rawobj).ob_pypy_link return llmemory.cast_int_to_adr(int_gcobj) +def _rrc_has_untracked_referents(self, raw_obj): +from rpython.rlib.rawrefcount import ( +REFCNT_FROM_PYPY, REFCNT_FROM_PYPY_LIGHT) +rc = self._pyobj(raw_obj).ob_refcnt +return rc != REFCNT_FROM_PYPY and rc != REFCNT_FROM_PYPY_LIGHT + +def _rrc_unlink(self, adr_rawobj): +from rpython.rlib.rawrefcount import REFCNT_FROM_PYPY +RC_MASK = REFCNT_FROM_PYPY - 1 +rawobj = self._pyobj(adr_rawobj) +rawobj.ob_refcnt &= RC_MASK +rawobj.ob_pypy_link = 0 + +def _rrc_is_light(self, adr_rawobj): +from rpython.rlib.rawrefcount import REFCNT_FROM_PYPY_LIGHT +return self._pyobj(adr_rawobj).ob_refcnt >= REFCNT_FROM_PYPY_LIGHT + +def _rrc_dealloc_light(self, adr_rawobj): +lltype.free(self._pyobj(adr_rawobj), flavor='raw') + def rawrefcount_init(self, dealloc_trigger_callback): # see pypy/doc/discussion/rawrefcount.rst if not self.rrc_enabled: @@ -2844,7 +2864,6 @@ return self.rrc_dealloc_pending.pop() return llmemory.NULL - def rrc_invoke_callback(self): if self.rrc_enabled and self.rrc_dealloc_pending.non_empty(): self.rrc_dealloc_trigger_callback() @@ -2857,13 +2876,7 @@ self.rrc_singleaddr) def _rrc_minor_trace(self, pyobject, singleaddr): -from rpython.rlib.rawrefcount import REFCNT_FROM_PYPY -from rpython.rlib.rawrefcount import REFCNT_FROM_PYPY_LIGHT -# -rc = self._pyobj(pyobject).ob_refcnt -if rc == REFCNT_FROM_PYPY or rc == REFCNT_FROM_PYPY_LIGHT: -pass # the corresponding object may die -else: +if self._rrc_has_untracked_referents(pyobject): # force the corresponding object to be alive singleaddr.address[0] = self._rrc_get_gc_partner(pyobject) self._trace_drag_out(singleaddr, llmemory.NULL) @@ -2915,40 +2928,20 @@ self._rrc_free(pyobject) def _rrc_free(self, pyobject): -from rpython.rlib.rawrefcount import REFCNT_FROM_PYPY -from rpython.rlib.rawrefcount import REFCNT_FROM_PYPY_LIGHT -# -rc = self._pyobj(pyobject).ob_refcnt -if rc >= REFCNT_FROM_PYPY_LIGHT: -rc -= REFCNT_FROM_PYPY_LIGHT -if rc == 0: -lltype.free(self._pyobj(pyobject), flavor='raw') -else: -# can only occur if LIGHT is used in create_link_pyobj() -self._pyobj(pyobject).ob_refcnt = rc -self._pyobj(pyobject).ob_pypy_link = 0 +if self._rrc_has_untracked_referents(pyobject): +self._rrc_unlink(pyobject) +elif self._rrc_is_light(pyobject): +self._rrc_dealloc_light(pyobject) else: -ll_assert(rc >= REFCNT_FROM_PYPY, "refcount underflow?") -ll_assert(rc < int(REFCNT_FROM_PYPY_LIGHT * 0.99), - "refcount underflow from REFCNT_FROM_PYPY_LIGHT?") -rc -= REFCNT_FROM_PYPY -self._pyobj(pyobject).ob_refcnt = rc -self._pyobj(pyobject).ob_pypy_link = 0 -if rc == 0: -self.rrc_dealloc_pending.append(pyobject) +self._rrc_unlink(pyobject) +self.rrc_dealloc_pending.append(pyobject) _rrc_free._always_inline_ = True def rrc_major_collection_trace(self): self.rrc_p_list_old.foreach(self._rrc_major_trace, None) def _rrc_major_trace(self, pyobject, ignore): -from rpython.rlib.rawrefcount import REFCNT_FROM_PYPY -from rpython.rlib.rawrefcount import REFCNT_FROM_PYPY_LIGHT -# -rc = self._pyobj(pyobject).ob_refcnt -if rc == REFCNT_FROM_PYPY or rc == REFCNT_FROM_PYPY_LIGHT: -pass # the corresponding object may die -else: +if self._rrc_has_untracked_referents(pyobject): # force the corresponding object to be alive obj = self._rrc_get_gc_partner(pyobject) self.objects_to_trace.append(obj) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy rawrefcount-review: Add stateful hypothesis testing for rawrefcount
Author: Ronan Lamy Branch: rawrefcount-review Changeset: r82865:7ddef219107f Date: 2016-03-07 18:40 + http://bitbucket.org/pypy/pypy/changeset/7ddef219107f/ Log:Add stateful hypothesis testing for rawrefcount diff --git a/rpython/memory/gc/test/test_rawrefcount.py b/rpython/memory/gc/test/test_rawrefcount.py --- a/rpython/memory/gc/test/test_rawrefcount.py +++ b/rpython/memory/gc/test/test_rawrefcount.py @@ -1,7 +1,7 @@ import py from rpython.rtyper.lltypesystem import lltype, llmemory from rpython.memory.gc.incminimark import IncrementalMiniMarkGC -from rpython.memory.gc.test.test_direct import BaseDirectGCTest +from rpython.memory.gc.test.test_direct import BaseDirectGCTest, GCSpace from rpython.rlib.rawrefcount import REFCNT_FROM_PYPY from rpython.rlib.rawrefcount import REFCNT_FROM_PYPY_LIGHT @@ -289,3 +289,178 @@ check_alive(0) self._collect(major=True) check_alive(0) + +class RefcountSpace(GCSpace): +def __init__(self): +GCSpace.__init__(self, IncrementalMiniMarkGC, {}) +self.trigger = [] +self.gc.rawrefcount_init(lambda: self.trigger.append(1)) + +def new_rawobj(self): +r1 = lltype.malloc(PYOBJ_HDR, flavor='raw') +r1.ob_refcnt = 0 +r1.ob_pypy_link = 0 +return r1 + +def new_gcobj(self, intval): +p1 = self.malloc(S) +p1.x = intval +return p1 + +def create_link(self, rawobj, gcobj, is_light=False, is_pyobj=False): +if is_light: +rawobj.ob_refcnt += REFCNT_FROM_PYPY_LIGHT +else: +rawobj.ob_refcnt += REFCNT_FROM_PYPY +rawaddr = llmemory.cast_ptr_to_adr(rawobj) +gcref = lltype.cast_opaque_ptr(llmemory.GCREF, gcobj) +if is_pyobj: +self.gc.rawrefcount_create_link_pyobj(gcref, rawaddr) +else: +self.gc.rawrefcount_create_link_pypy(gcref, rawaddr) + +def from_gc(self, gcobj): +gcref = lltype.cast_opaque_ptr(llmemory.GCREF, gcobj) +rawaddr = self.gc.rawrefcount_from_obj(gcref) +if rawaddr == llmemory.NULL: +return None +else: +return self.gc._pyobj(rawaddr) + +from rpython.rtyper.test.test_rdict import signal_timeout, Action +from hypothesis.strategies import ( +builds, sampled_from, binary, just, integers, text, characters, tuples, +booleans, one_of) +from hypothesis.stateful import GenericStateMachine, run_state_machine_as_test +from rpython.tool.leakfinder import start_tracking_allocations, stop_tracking_allocations + +RC_MASK = REFCNT_FROM_PYPY - 1 + +class StateMachine(GenericStateMachine): +def __init__(self): +self.space = RefcountSpace() +self.rawobjs = [] +self.rootlinks = [] +self.next_id = 0 +start_tracking_allocations() + +def free(self, rawobj): +lltype.free(rawobj, flavor='raw') + +def incref(self, rawobj): +rawobj.ob_refcnt += 1 + +def decref(self, rawobj): +assert rawobj.ob_refcnt > 0 +rawobj.ob_refcnt -= 1 +if rawobj.ob_refcnt == 0: +i = self.rawobjs.index(rawobj) +self.free(rawobj) +del self.rawobjs[i] +elif rawobj.ob_refcnt & RC_MASK == 0: +i = self.rawobjs.index(rawobj) +del self.rawobjs[i] + +def get_linkable_gcobjs(self): +res = [] +for p, has_link in zip(self.space.stackroots, self.rootlinks): +if not has_link: +res.append(p) +return res + +def get_linkable_rawobjs(self): +return [r for r in self.rawobjs +if r.ob_refcnt != 0 and r.ob_pypy_link == 0] + +def find_root_index(self, p): +return self.space.stackroots.index(p) + +def add_rawobj(self): +r = self.space.new_rawobj() +self.incref(r) +self.rawobjs.append(r) + +def add_gcobj(self): +p = self.space.new_gcobj(self.next_id) +self.space.stackroots.append(p) +self.rootlinks.append(False) +self.next_id += 1 +return p + +def create_gcpartner(self, raw, is_light=False, is_pyobj=False): +p = self.space.new_gcobj(self.next_id) +self.next_id += 1 +self.space.create_link(raw, p, is_light=is_light, is_pyobj=is_pyobj) + +def create_rawpartner(self, p, is_light=False, is_pyobj=False): +assert self.space.from_gc(p) is None +i = self.find_root_index(p) +raw = self.space.new_rawobj() +self.space.create_link(raw, p, is_light=is_light, is_pyobj=is_pyobj) +self.rootlinks[i] = True + +def minor_collection(self): +self.space.gc.minor_collection() + +def major_collection(self): +self.space.gc.collect() + +def forget_root(self, n): +del self.space.stackroots[n] +del self.rootlinks[n] + +def steps(self): +valid_st = [] +global_actions = [ +Action('add_rawobj', ()), +Action('mi
[pypy-commit] pypy default: small cleanup
Author: Ronan Lamy Branch: Changeset: r82916:6e82c4562984 Date: 2016-03-09 17:51 + http://bitbucket.org/pypy/pypy/changeset/6e82c4562984/ Log:small cleanup diff --git a/pypy/interpreter/mixedmodule.py b/pypy/interpreter/mixedmodule.py --- a/pypy/interpreter/mixedmodule.py +++ b/pypy/interpreter/mixedmodule.py @@ -3,7 +3,7 @@ from pypy.interpreter import gateway from pypy.interpreter.error import OperationError from pypy.interpreter.baseobjspace import W_Root -import os, sys +import sys class MixedModule(Module): applevel_name = None @@ -60,7 +60,7 @@ def save_module_content_for_future_reload(self): self.w_initialdict = self.space.call_method(self.w_dict, 'items') - +@classmethod def get_applevel_name(cls): """ NOT_RPYTHON """ if cls.applevel_name is not None: @@ -68,7 +68,6 @@ else: pkgroot = cls.__module__ return pkgroot.split('.')[-1] -get_applevel_name = classmethod(get_applevel_name) def get(self, name): space = self.space @@ -103,7 +102,7 @@ # be normal Functions to get the correct binding behaviour func = w_value if (isinstance(func, Function) and -type(func) is not BuiltinFunction): +type(func) is not BuiltinFunction): try: bltin = func._builtinversion_ except AttributeError: @@ -115,7 +114,6 @@ space.setitem(self.w_dict, w_name, w_value) return w_value - def getdict(self, space): if self.lazy: for name in self.loaders: @@ -131,6 +129,7 @@ self.startup_called = False self._frozen = True +@classmethod def buildloaders(cls): """ NOT_RPYTHON """ if not hasattr(cls, 'loaders'): @@ -149,8 +148,6 @@ if '__doc__' not in loaders: loaders['__doc__'] = cls.get__doc__ -buildloaders = classmethod(buildloaders) - def extra_interpdef(self, name, spec): cls = self.__class__ pkgroot = cls.__module__ @@ -159,21 +156,21 @@ w_obj = loader(space) space.setattr(space.wrap(self), space.wrap(name), w_obj) +@classmethod def get__doc__(cls, space): return space.wrap(cls.__doc__) -get__doc__ = classmethod(get__doc__) def getinterpevalloader(pkgroot, spec): """ NOT_RPYTHON """ def ifileloader(space): -d = {'space' : space} +d = {'space':space} # EVIL HACK (but it works, and this is not RPython :-) while 1: try: value = eval(spec, d) except NameError, ex: -name = ex.args[0].split("'")[1] # super-Evil +name = ex.args[0].split("'")[1] # super-Evil if name in d: raise # propagate the NameError try: ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy pypy3.3-bootstrap: Do not store the absolute path of the source into the translated executable (breaks stuff)
Author: Ronan Lamy Branch: pypy3.3-bootstrap Changeset: r82923:6a5e412892d7 Date: 2016-03-09 20:43 + http://bitbucket.org/pypy/pypy/changeset/6a5e412892d7/ Log:Do not store the absolute path of the source into the translated executable (breaks stuff) diff --git a/pypy/module/sys/state.py b/pypy/module/sys/state.py --- a/pypy/module/sys/state.py +++ b/pypy/module/sys/state.py @@ -14,16 +14,7 @@ self.w_modules = space.newdict(module=True) self.w_warnoptions = space.newlist([]) self.w_argv = space.newlist([]) - -self.setinitialpath(space) - -def setinitialpath(self, space): -from pypy.module.sys.initpath import compute_stdlib_path -# Initialize the default path -pypydir = os.path.dirname(os.path.abspath(pypy.__file__)) -srcdir = os.path.dirname(pypydir) -path = compute_stdlib_path(self, srcdir) -self.w_path = space.newlist([space.wrap(p) for p in path]) +self.w_path = space.newlist([]) def get(space): return space.fromcache(State) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.3-bootstrap-hack: Initialise the filesystem encoding only after imports have been bootstrapped.
Author: Ronan Lamy Branch: py3.3-bootstrap-hack Changeset: r82949:eb02742ce71d Date: 2016-03-10 19:01 + http://bitbucket.org/pypy/pypy/changeset/eb02742ce71d/ Log:Initialise the filesystem encoding only after imports have been bootstrapped. Creating it requires importing the 'encodings' module from the stdlib, so the stdlib path needs to have been computed first. diff --git a/pypy/interpreter/app_main.py b/pypy/interpreter/app_main.py --- a/pypy/interpreter/app_main.py +++ b/pypy/interpreter/app_main.py @@ -769,6 +769,7 @@ # import os, which is used a bit everywhere in app_main, but only imported # *after* setup_bootstrap_path setup_bootstrap_path(executable) +sys.pypy_initfsencoding() try: cmdline = parse_command_line(argv) except CommandLineError as e: @@ -862,7 +863,7 @@ sys.pypy_find_stdlib = pypy_find_stdlib sys.pypy_resolvedirof = pypy_resolvedirof sys.cpython_path = sys.path[:] - + try: sys.exit(int(entry_point(sys.argv[0], sys.argv[1:]))) finally: diff --git a/pypy/module/sys/__init__.py b/pypy/module/sys/__init__.py --- a/pypy/module/sys/__init__.py +++ b/pypy/module/sys/__init__.py @@ -40,6 +40,7 @@ 'pypy_find_stdlib' : 'initpath.pypy_find_stdlib', 'pypy_find_executable' : 'initpath.pypy_find_executable', 'pypy_resolvedirof' : 'initpath.pypy_resolvedirof', +'pypy_initfsencoding' : 'initpath.pypy_initfsencoding', '_getframe' : 'vm._getframe', '_current_frames' : 'currentframes._current_frames', @@ -97,12 +98,7 @@ def startup(self, space): if space.config.translating: -if not we_are_translated(): -# don't get the filesystemencoding at translation time -assert self.filesystemencoding is None -else: -from pypy.module.sys.interp_encoding import _getfilesystemencoding -self.filesystemencoding = _getfilesystemencoding(space) +assert self.filesystemencoding is None if not space.config.translating or we_are_translated(): from pypy.module.sys import version diff --git a/pypy/module/sys/initpath.py b/pypy/module/sys/initpath.py --- a/pypy/module/sys/initpath.py +++ b/pypy/module/sys/initpath.py @@ -12,6 +12,7 @@ from pypy.interpreter.gateway import unwrap_spec from pypy.module.sys.state import get as get_state +from pypy.module.sys.interp_encoding import _getfilesystemencoding PLATFORM = sys.platform _MACOSX = sys.platform == 'darwin' @@ -166,7 +167,9 @@ space.setitem(space.sys.w_dict, space.wrap('base_exec_prefix'), w_prefix) return space.newlist([_w_fsdecode(space, p) for p in path]) +def pypy_initfsencoding(space): +space.sys.filesystemencoding = _getfilesystemencoding(space) + def _w_fsdecode(space, b): return space.fsdecode(space.wrapbytes(b)) - ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.3-bootstrap-hack: Fix test_app_main
Author: Ronan Lamy Branch: py3.3-bootstrap-hack Changeset: r82987:5705d77f0311 Date: 2016-03-11 17:30 + http://bitbucket.org/pypy/pypy/changeset/5705d77f0311/ Log:Fix test_app_main diff --git a/pypy/interpreter/app_main.py b/pypy/interpreter/app_main.py --- a/pypy/interpreter/app_main.py +++ b/pypy/interpreter/app_main.py @@ -862,6 +862,7 @@ sys.pypy_find_executable = pypy_find_executable sys.pypy_find_stdlib = pypy_find_stdlib sys.pypy_resolvedirof = pypy_resolvedirof +sys.pypy_initfsencoding = lambda: None sys.cpython_path = sys.path[:] try: ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy rawrefcount-review: Add externally malloced gcobjects to the hypothesis test
Author: Ronan Lamy Branch: rawrefcount-review Changeset: r83012:579b1d5d2803 Date: 2016-03-13 16:50 + http://bitbucket.org/pypy/pypy/changeset/579b1d5d2803/ Log:Add externally malloced gcobjects to the hypothesis test diff --git a/rpython/memory/gc/test/test_rawrefcount.py b/rpython/memory/gc/test/test_rawrefcount.py --- a/rpython/memory/gc/test/test_rawrefcount.py +++ b/rpython/memory/gc/test/test_rawrefcount.py @@ -312,8 +312,14 @@ r1.ob_pypy_link = 0 return r1 -def new_gcobj(self, intval): -p1 = self.malloc(S) +def new_gcobj(self, intval, external=False): +saved = self.gc.nonlarge_max +try: +if external: +self.gc.nonlarge_max = 1 +p1 = self.malloc(S) +finally: +self.gc.nonlarge_max = saved p1.x = intval return p1 @@ -390,15 +396,15 @@ self.incref(r) self.rawobjs.append(r) -def add_gcobj(self): -p = self.space.new_gcobj(self.next_id) +def add_gcobj(self, external=False): +p = self.space.new_gcobj(self.next_id, external=external) self.space.stackroots.append(p) self.rootlinks.append(False) self.next_id += 1 return p -def create_gcpartner(self, raw, is_light=False, is_pyobj=False): -p = self.space.new_gcobj(self.next_id) +def create_gcpartner(self, raw, is_light=False, is_pyobj=False, external=False): +p = self.space.new_gcobj(self.next_id, external=external) self.next_id += 1 self.space.create_link(raw, p, is_light=is_light, is_pyobj=is_pyobj) @@ -427,7 +433,7 @@ Action('major_collection', ()), ] valid_st.append(sampled_from(global_actions)) -valid_st.append(builds(Action, just('add_gcobj'), tuples())) +valid_st.append(builds(Action, just('add_gcobj'), tuples(booleans( if self.rawobjs: valid_st.append(builds(Action, just('incref'), tuples( sampled_from(self.rawobjs @@ -439,7 +445,7 @@ if candidates: st = builds(Action, just('create_gcpartner'), tuples( sampled_from(candidates), -booleans(), booleans())) +booleans(), booleans(), booleans())) valid_st.append(st) candidates = self.get_linkable_gcobjs() if candidates: ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy rawrefcount-review: hg merge default
Author: Ronan Lamy Branch: rawrefcount-review Changeset: r83011:ac298f2c6197 Date: 2016-03-13 16:26 + http://bitbucket.org/pypy/pypy/changeset/ac298f2c6197/ Log:hg merge default diff too long, truncating to 2000 out of 14492 lines diff --git a/.hgignore b/.hgignore --- a/.hgignore +++ b/.hgignore @@ -74,5 +74,6 @@ ^rpython/doc/_build/.*$ ^compiled ^.git/ +^.hypothesis/ ^release/ ^rpython/_cache$ diff --git a/.hgtags b/.hgtags --- a/.hgtags +++ b/.hgtags @@ -18,3 +18,4 @@ f3ad1e1e1d6215e20d34bb65ab85ff9188c9f559 release-2.6.1 850edf14b2c75573720f59e95767335fb1affe55 release-4.0.0 5f8302b8bf9f53056e40426f10c72151564e5b19 release-4.0.1 +246c9cf22037b11dc0e8c29ce3f291d3b8c5935a release-5.0 diff --git a/LICENSE b/LICENSE --- a/LICENSE +++ b/LICENSE @@ -240,6 +240,7 @@ Kristjan Valur Jonsson David Lievens Neil Blakey-Milner + Sergey Matyunin Lutz Paelike Lucio Torre Lars Wassermann @@ -271,6 +272,7 @@ Aaron Tubbs Ben Darnell Roberto De Ioris + Logan Chien Juan Francisco Cantero Hurtado Ruochen Huang Jeong YunWon diff --git a/lib-python/2.7/xml/etree/ElementTree.py b/lib-python/2.7/xml/etree/ElementTree.py --- a/lib-python/2.7/xml/etree/ElementTree.py +++ b/lib-python/2.7/xml/etree/ElementTree.py @@ -1606,7 +1606,17 @@ pubid = pubid[1:-1] if hasattr(self.target, "doctype"): self.target.doctype(name, pubid, system[1:-1]) -elif self.doctype is not self._XMLParser__doctype: +elif 1: # XXX PyPy fix, used to be + # elif self.doctype is not self._XMLParser__doctype: + # but that condition is always True on CPython, as far + # as I can tell: self._XMLParser__doctype always + # returns a fresh unbound method object. + # On PyPy, unbound and bound methods have stronger + # unicity guarantees: self._XMLParser__doctype + # can return the same unbound method object, in + # some cases making the test above incorrectly False. + # (My guess would be that the line above is a backport + # from Python 3.) # warn about deprecated call self._XMLParser__doctype(name, pubid, system[1:-1]) self.doctype(name, pubid, system[1:-1]) diff --git a/lib_pypy/ctypes_config_cache/rebuild.py b/lib_pypy/ctypes_config_cache/rebuild.py --- a/lib_pypy/ctypes_config_cache/rebuild.py +++ b/lib_pypy/ctypes_config_cache/rebuild.py @@ -9,9 +9,8 @@ _dirpath = os.path.dirname(__file__) or os.curdir -from rpython.tool.ansi_print import ansi_log -log = py.log.Producer("ctypes_config_cache") -py.log.setconsumer("ctypes_config_cache", ansi_log) +from rpython.tool.ansi_print import AnsiLogger +log = AnsiLogger("ctypes_config_cache") def rebuild_one(name): diff --git a/pypy/doc/conf.py b/pypy/doc/conf.py --- a/pypy/doc/conf.py +++ b/pypy/doc/conf.py @@ -123,7 +123,7 @@ # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". -#html_title = None +html_title = 'PyPy documentation' # A shorter title for the navigation bar. Default is the same as html_title. #html_short_title = None diff --git a/pypy/doc/contributor.rst b/pypy/doc/contributor.rst --- a/pypy/doc/contributor.rst +++ b/pypy/doc/contributor.rst @@ -210,6 +210,7 @@ Kristjan Valur Jonsson David Lievens Neil Blakey-Milner + Sergey Matyunin Lutz Paelike Lucio Torre Lars Wassermann @@ -241,6 +242,7 @@ Aaron Tubbs Ben Darnell Roberto De Ioris + Logan Chien Juan Francisco Cantero Hurtado Ruochen Huang Jeong YunWon diff --git a/pypy/doc/cpython_differences.rst b/pypy/doc/cpython_differences.rst --- a/pypy/doc/cpython_differences.rst +++ b/pypy/doc/cpython_differences.rst @@ -265,7 +265,7 @@ return False def evil(y): -d = {x(): 1} +d = {X(): 1} X.__eq__ = __evil_eq__ d[y] # might trigger a call to __eq__? diff --git a/pypy/doc/how-to-release.rst b/pypy/doc/how-to-release.rst --- a/pypy/doc/how-to-release.rst +++ b/pypy/doc/how-to-release.rst @@ -76,5 +76,4 @@ * add a tag on the pypy/jitviewer repo that corresponds to pypy release * add a tag on the codespeed web site that corresponds to pypy release -* update the version number in {rpython,pypy}/doc/conf.py. * revise versioning at https://readthedocs.org/projects/pypy diff --git a/pypy/doc/project-ideas.rst b/pypy/doc/project-ideas.rst --- a/pypy/doc/project-ideas.rst +++ b/pypy/doc/project-ideas.rst @@ -167,22 +167,13 @@ * `hg` -Embedding PyPy and improving CFFI -- - -PyPy has some basic :doc:`embedding infrastructure `. The idea would be to improve -upon that with cffi hacks that can automatically generate embeddable .so/.dll -li
[pypy-commit] pypy py3.3-bootstrap-hack: Close branch py3.3-bootstrap-hack
Author: Ronan Lamy Branch: py3.3-bootstrap-hack Changeset: r83018:54a2d1b980a4 Date: 2016-03-13 19:29 + http://bitbucket.org/pypy/pypy/changeset/54a2d1b980a4/ Log:Close branch py3.3-bootstrap-hack ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.3: Merged in py3.3-bootstrap-hack (pull request #415)
Author: Ronan Lamy Branch: py3.3 Changeset: r83019:0113d6e6d5ca Date: 2016-03-13 19:29 + http://bitbucket.org/pypy/pypy/changeset/0113d6e6d5ca/ Log:Merged in py3.3-bootstrap-hack (pull request #415) Initialise the filesystem encoding only after imports have been bootstrapped. Creating it requires importing the 'encodings' module from the stdlib, so the stdlib path needs to have been computed first. diff --git a/pypy/interpreter/app_main.py b/pypy/interpreter/app_main.py --- a/pypy/interpreter/app_main.py +++ b/pypy/interpreter/app_main.py @@ -769,6 +769,7 @@ # import os, which is used a bit everywhere in app_main, but only imported # *after* setup_bootstrap_path setup_bootstrap_path(executable) +sys.pypy_initfsencoding() try: cmdline = parse_command_line(argv) except CommandLineError as e: @@ -861,8 +862,9 @@ sys.pypy_find_executable = pypy_find_executable sys.pypy_find_stdlib = pypy_find_stdlib sys.pypy_resolvedirof = pypy_resolvedirof +sys.pypy_initfsencoding = lambda: None sys.cpython_path = sys.path[:] - + try: sys.exit(int(entry_point(sys.argv[0], sys.argv[1:]))) finally: diff --git a/pypy/module/sys/__init__.py b/pypy/module/sys/__init__.py --- a/pypy/module/sys/__init__.py +++ b/pypy/module/sys/__init__.py @@ -40,6 +40,7 @@ 'pypy_find_stdlib' : 'initpath.pypy_find_stdlib', 'pypy_find_executable' : 'initpath.pypy_find_executable', 'pypy_resolvedirof' : 'initpath.pypy_resolvedirof', +'pypy_initfsencoding' : 'initpath.pypy_initfsencoding', '_getframe' : 'vm._getframe', '_current_frames' : 'currentframes._current_frames', @@ -97,12 +98,7 @@ def startup(self, space): if space.config.translating: -if not we_are_translated(): -# don't get the filesystemencoding at translation time -assert self.filesystemencoding is None -else: -from pypy.module.sys.interp_encoding import _getfilesystemencoding -self.filesystemencoding = _getfilesystemencoding(space) +assert self.filesystemencoding is None if not space.config.translating or we_are_translated(): from pypy.module.sys import version diff --git a/pypy/module/sys/initpath.py b/pypy/module/sys/initpath.py --- a/pypy/module/sys/initpath.py +++ b/pypy/module/sys/initpath.py @@ -12,6 +12,7 @@ from pypy.interpreter.gateway import unwrap_spec from pypy.module.sys.state import get as get_state +from pypy.module.sys.interp_encoding import _getfilesystemencoding PLATFORM = sys.platform _MACOSX = sys.platform == 'darwin' @@ -166,7 +167,9 @@ space.setitem(space.sys.w_dict, space.wrap('base_exec_prefix'), w_prefix) return space.newlist([_w_fsdecode(space, p) for p in path]) +def pypy_initfsencoding(space): +space.sys.filesystemencoding = _getfilesystemencoding(space) + def _w_fsdecode(space, b): return space.fsdecode(space.wrapbytes(b)) - ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy bootstrap-clarity: Make module _cleanup_ explicit
Author: Ronan Lamy Branch: bootstrap-clarity Changeset: r83077:11e9cab4e26f Date: 2016-03-15 20:10 + http://bitbucket.org/pypy/pypy/changeset/11e9cab4e26f/ Log:Make module _cleanup_ explicit diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py --- a/pypy/interpreter/baseobjspace.py +++ b/pypy/interpreter/baseobjspace.py @@ -633,6 +633,8 @@ self.getbuiltinmodule('__builtin__') for mod in self.builtin_modules.values(): mod.setup_after_space_initialization() +for mod in self.builtin_modules.values(): +mod.cleanup() def initialize(self): """NOT_RPYTHON: Abstract method that should put some minimal diff --git a/pypy/interpreter/mixedmodule.py b/pypy/interpreter/mixedmodule.py --- a/pypy/interpreter/mixedmodule.py +++ b/pypy/interpreter/mixedmodule.py @@ -123,7 +123,7 @@ self.save_module_content_for_future_reload() return self.w_dict -def _cleanup_(self): +def cleanup(self): self.getdict(self.space) self.w_initialdict = None self.startup_called = False diff --git a/pypy/interpreter/module.py b/pypy/interpreter/module.py --- a/pypy/interpreter/module.py +++ b/pypy/interpreter/module.py @@ -29,7 +29,7 @@ space.w_None) self.startup_called = False -def _cleanup_(self): +def cleanup(self): """Called by the annotator on prebuilt Module instances. We don't have many such modules, but for the ones that show up, remove their __file__ rather than translate it diff --git a/pypy/interpreter/test/test_appinterp.py b/pypy/interpreter/test/test_appinterp.py --- a/pypy/interpreter/test/test_appinterp.py +++ b/pypy/interpreter/test/test_appinterp.py @@ -3,30 +3,30 @@ from pypy.interpreter.gateway import appdef, ApplevelClass, applevel_temp from pypy.interpreter.error import OperationError -def test_execwith_novars(space): -val = space.appexec([], """ -(): -return 42 -""") +def test_execwith_novars(space): +val = space.appexec([], """ +(): +return 42 +""") assert space.eq_w(val, space.wrap(42)) -def test_execwith_withvars(space): +def test_execwith_withvars(space): val = space.appexec([space.wrap(7)], """ -(x): -y = 6 * x -return y -""") +(x): +y = 6 * x +return y +""") assert space.eq_w(val, space.wrap(42)) -def test_execwith_compile_error(space): +def test_execwith_compile_error(space): excinfo = py.test.raises(OperationError, space.appexec, [], """ -(): -y y +(): +y y """) -assert str(excinfo.value.errorstr(space)).find('y y') != -1 +assert str(excinfo.value.errorstr(space)).find('y y') != -1 def test_simple_applevel(space): -app = appdef("""app(x,y): +app = appdef("""app(x,y): return x + y """) assert app.func_name == 'app' @@ -34,15 +34,15 @@ assert space.eq_w(w_result, space.wrap(42)) def test_applevel_with_one_default(space): -app = appdef("""app(x,y=1): +app = appdef("""app(x,y=1): return x + y """) assert app.func_name == 'app' -w_result = app(space, space.wrap(41)) +w_result = app(space, space.wrap(41)) assert space.eq_w(w_result, space.wrap(42)) def test_applevel_with_two_defaults(space): -app = appdef("""app(x=1,y=2): +app = appdef("""app(x=1,y=2): return x + y """) w_result = app(space, space.wrap(41), space.wrap(1)) @@ -56,19 +56,19 @@ def test_applevel_noargs(space): -app = appdef("""app(): -return 42 +app = appdef("""app(): +return 42 """) assert app.func_name == 'app' -w_result = app(space) +w_result = app(space) assert space.eq_w(w_result, space.wrap(42)) -def somefunc(arg2=42): -return arg2 +def somefunc(arg2=42): +return arg2 -def test_app2interp_somefunc(space): -app = appdef(somefunc) -w_result = app(space) +def test_app2interp_somefunc(space): +app = appdef(somefunc) +w_result = app(space) assert space.eq_w(w_result, space.wrap(42)) def test_applevel_functions(space, applevel_temp = applevel_temp): @@ -85,45 +85,45 @@ def test_applevel_class(space, applevel_temp = applevel_temp): app = applevel_temp(''' class C(object): -clsattr = 42 -def __init__(self, x=13): -self.attr = x +clsattr = 42 +def __init__(self, x=13): +self.attr = x ''') C = app.interphook('C') -c = C(space, space.wrap(17)) +c = C(space, space.wrap(17)) w_attr = space.getattr(c, space.wrap('clsattr')) assert space.eq_w(w_attr, space.wrap(42)) w_clsattr = space.getattr(c, space.wrap('attr')) assert space.eq_w(w_clsattr, space.wrap(17)) -def app_test_something_at_app_level(): +def app_test_something_at_app
[pypy-commit] pypy bootstrap-clarity: Create space._is_runtime attribute.
Author: Ronan Lamy Branch: bootstrap-clarity Changeset: r83076:006b04e6249a Date: 2016-03-15 19:06 + http://bitbucket.org/pypy/pypy/changeset/006b04e6249a/ Log:Create space._is_runtime attribute. This is meant to allow cleanly separating translation-time objspace configuration from run-time interpreter initialisation. The attribute is initially False and must be set to True before running space.startup() or exectuting any annotator-visible RPython code. diff --git a/pypy/bin/pyinteractive.py b/pypy/bin/pyinteractive.py --- a/pypy/bin/pyinteractive.py +++ b/pypy/bin/pyinteractive.py @@ -42,7 +42,7 @@ StrOption("warn", "warning control (arg is action:message:category:module:lineno)", default=None, cmdline="-W"), - + ]) pypy_init = gateway.applevel(''' @@ -118,7 +118,7 @@ # set warning control options (if any) warn_arg = interactiveconfig.warn if warn_arg is not None: -space.appexec([space.wrap(warn_arg)], """(arg): +space.appexec([space.wrap(warn_arg)], """(arg): import sys sys.warnoptions.append(arg)""") @@ -167,6 +167,7 @@ try: def do_start(): +space._is_runtime = True space.startup() pypy_init(space, space.wrap(not interactiveconfig.no_site_import)) if main.run_toplevel(space, do_start, @@ -200,6 +201,6 @@ if __name__ == '__main__': if hasattr(sys, 'setrecursionlimit'): -# for running "python -i pyinteractive.py -Si -- py.py -Si" +# for running "python -i pyinteractive.py -Si -- py.py -Si" sys.setrecursionlimit(3000) sys.exit(main_(sys.argv)) diff --git a/pypy/goal/targetpypystandalone.py b/pypy/goal/targetpypystandalone.py --- a/pypy/goal/targetpypystandalone.py +++ b/pypy/goal/targetpypystandalone.py @@ -292,7 +292,7 @@ self.hack_for_cffi_modules(driver) return self.get_entry_point(config) - + def hack_for_cffi_modules(self, driver): # HACKHACKHACK # ugly hack to modify target goal from compile_* to build_cffi_imports @@ -319,7 +319,7 @@ while not basedir.join('include').exists(): _basedir = basedir.dirpath() if _basedir == basedir: -raise ValueError('interpreter %s not inside pypy repo', +raise ValueError('interpreter %s not inside pypy repo', str(exename)) basedir = _basedir modules = self.config.objspace.usemodules.getpaths() @@ -350,6 +350,7 @@ app = gateway.applevel(open(filename).read(), 'app_main.py', 'app_main') app.hidden_applevel = False w_dict = app.getwdict(space) +space._is_runtime = True entry_point, _ = create_entry_point(space, w_dict) return entry_point, None, PyPyAnnotatorPolicy() diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py --- a/pypy/interpreter/baseobjspace.py +++ b/pypy/interpreter/baseobjspace.py @@ -374,6 +374,7 @@ def __init__(self, config=None): "NOT_RPYTHON: Basic initialization of objects." +self._is_runtime = False self.fromcache = InternalSpaceCache(self).getorbuild self.threadlocals = ThreadLocals() # set recursion limit @@ -391,7 +392,7 @@ self.check_signal_action = None # changed by the signal module self.user_del_action = UserDelAction(self) self._code_of_sys_exc_info = None - + # can be overridden to a subclass self.initialize() @@ -643,21 +644,14 @@ # you should not see frames while you translate # so we make sure that the threadlocals never *have* an # ExecutionContext during translation. -if not we_are_translated(): -if self.config.translating: -assert self.threadlocals.get_ec() is None, ( -"threadlocals got an ExecutionContext during translation!") -try: -return self._ec_during_translation -except AttributeError: -ec = self.createexecutioncontext() -self._ec_during_translation = ec -return ec -else: -ec = self.threadlocals.get_ec() -if ec is None: -self.threadlocals.enter_thread(self) -ec = self.threadlocals.get_ec() +if not self._is_runtime: +assert self.threadlocals.get_ec() is None, ( +"threadlocals got an ExecutionContext during translation!") +try: +return self._ec_during_translation +except AttributeError: +ec = self.createexecutioncontext() +self._ec_during_translation = ec return ec else: # tr
[pypy-commit] pypy py3k: hg merge default
Author: Ronan Lamy Branch: py3k Changeset: r83154:9a167de52a1f Date: 2016-03-19 04:26 + http://bitbucket.org/pypy/pypy/changeset/9a167de52a1f/ Log:hg merge default diff too long, truncating to 2000 out of 13776 lines diff --git a/.hgignore b/.hgignore --- a/.hgignore +++ b/.hgignore @@ -74,5 +74,6 @@ ^rpython/doc/_build/.*$ ^compiled ^.git/ +^.hypothesis/ ^release/ ^rpython/_cache$ diff --git a/.hgtags b/.hgtags --- a/.hgtags +++ b/.hgtags @@ -18,3 +18,4 @@ f3ad1e1e1d6215e20d34bb65ab85ff9188c9f559 release-2.6.1 850edf14b2c75573720f59e95767335fb1affe55 release-4.0.0 5f8302b8bf9f53056e40426f10c72151564e5b19 release-4.0.1 +246c9cf22037b11dc0e8c29ce3f291d3b8c5935a release-5.0 diff --git a/lib-python/2.7/xml/etree/ElementTree.py b/lib-python/2.7/xml/etree/ElementTree.py --- a/lib-python/2.7/xml/etree/ElementTree.py +++ b/lib-python/2.7/xml/etree/ElementTree.py @@ -1606,7 +1606,17 @@ pubid = pubid[1:-1] if hasattr(self.target, "doctype"): self.target.doctype(name, pubid, system[1:-1]) -elif self.doctype is not self._XMLParser__doctype: +elif 1: # XXX PyPy fix, used to be + # elif self.doctype is not self._XMLParser__doctype: + # but that condition is always True on CPython, as far + # as I can tell: self._XMLParser__doctype always + # returns a fresh unbound method object. + # On PyPy, unbound and bound methods have stronger + # unicity guarantees: self._XMLParser__doctype + # can return the same unbound method object, in + # some cases making the test above incorrectly False. + # (My guess would be that the line above is a backport + # from Python 3.) # warn about deprecated call self._XMLParser__doctype(name, pubid, system[1:-1]) self.doctype(name, pubid, system[1:-1]) diff --git a/lib_pypy/ctypes_config_cache/rebuild.py b/lib_pypy/ctypes_config_cache/rebuild.py --- a/lib_pypy/ctypes_config_cache/rebuild.py +++ b/lib_pypy/ctypes_config_cache/rebuild.py @@ -9,9 +9,8 @@ _dirpath = os.path.dirname(__file__) or os.curdir -from rpython.tool.ansi_print import ansi_log -log = py.log.Producer("ctypes_config_cache") -py.log.setconsumer("ctypes_config_cache", ansi_log) +from rpython.tool.ansi_print import AnsiLogger +log = AnsiLogger("ctypes_config_cache") def rebuild_one(name): diff --git a/pypy/doc/config/translation.gc.txt b/pypy/doc/config/translation.gc.txt --- a/pypy/doc/config/translation.gc.txt +++ b/pypy/doc/config/translation.gc.txt @@ -1,24 +1,26 @@ Choose the Garbage Collector used by the translated program. -The good performing collectors are "hybrid" and "minimark". -The default is "minimark". +The recommended default is "incminimark". - "ref": reference counting. Takes very long to translate and the result is -slow. +slow. Used only for tests. Don't use it for real RPython programs. - - "marksweep": naive mark & sweep. + - "none": no GC. Leaks everything. Don't use it for real RPython +programs: the rate of leaking is immense. - "semispace": a copying semi-space GC. - "generation": a generational GC using the semi-space GC for the older generation. - - "boehm": use the Boehm conservative GC. - - "hybrid": a hybrid collector of "generation" together with a mark-n-sweep old space - - "markcompact": a slow, but memory-efficient collector, -influenced e.g. by Smalltalk systems. + - "boehm": use the Boehm conservative GC. - "minimark": a generational mark-n-sweep collector with good performance. Includes page marking for large arrays. + + - "incminimark": like minimark, but adds incremental major +collections. Seems to come with no performance drawback over +"minimark", so it is the default. A few recent features of PyPy +(like cpyext) are only working with this GC. diff --git a/pypy/doc/extradoc.rst b/pypy/doc/extradoc.rst --- a/pypy/doc/extradoc.rst +++ b/pypy/doc/extradoc.rst @@ -80,7 +80,7 @@ .. _How to *not* write Virtual Machines for Dynamic Languages: https://bitbucket.org/pypy/extradoc/raw/tip/talk/dyla2007/dyla.pdf .. _`Tracing the Meta-Level: PyPy's Tracing JIT Compiler`: https://bitbucket.org/pypy/extradoc/raw/tip/talk/icooolps2009/bolz-tracing-jit.pdf .. _`Faster than C#: Efficient Implementation of Dynamic Languages on .NET`: https://bitbucket.org/pypy/extradoc/raw/tip/talk/icooolps2009-dotnet/cli-jit.pdf -.. _Automatic JIT Compiler Generation with Runtime Partial Evaluation: http://wwwold.cobra.cs.uni-duesseldorf.de/thesis/final-master.pdf +.. _Automatic JIT Compiler Generation with Runtime Partial Evaluation: http://stups.hhu.de/mediawiki/images/b/b9/Master_bolz.pdf .. _`RPython:
[pypy-commit] pypy default: Remove debug artifact (backout 18bd2d236f85)
Author: Ronan Lamy Branch: Changeset: r83155:c3f763db98bb Date: 2016-03-19 04:29 + http://bitbucket.org/pypy/pypy/changeset/c3f763db98bb/ Log:Remove debug artifact (backout 18bd2d236f85) diff --git a/pypy/module/select/test/test_select.py b/pypy/module/select/test/test_select.py --- a/pypy/module/select/test/test_select.py +++ b/pypy/module/select/test/test_select.py @@ -287,8 +287,7 @@ t = thread.start_new_thread(pollster.poll, ()) try: time.sleep(0.3) -# TODO restore print '', if this is not the reason -for i in range(5): print 'release gil select' # to release GIL untranslated +for i in range(5): print '', # to release GIL untranslated # trigger ufds array reallocation for fd in rfds: pollster.unregister(fd) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.3-bootstrap-again: Do not import importlib during objspace creation.
Author: Ronan Lamy Branch: py3.3-bootstrap-again Changeset: r83114:90e05aa7339c Date: 2016-03-17 16:40 + http://bitbucket.org/pypy/pypy/changeset/90e05aa7339c/ Log:Do not import importlib during objspace creation. This freezed importlib into a pre-built constant which prevents importing the rest of the package at run-time. diff --git a/pypy/module/imp/__init__.py b/pypy/module/imp/__init__.py --- a/pypy/module/imp/__init__.py +++ b/pypy/module/imp/__init__.py @@ -51,11 +51,3 @@ add_fork_hook('before', interp_imp.acquire_lock) add_fork_hook('parent', interp_imp.release_lock) add_fork_hook('child', interp_imp.reinit_lock) - -def setup_after_space_initialization(self): -# Install importlib as __import__ -self.space.appexec([], '''(): -import importlib._bootstrap, sys, _imp -sys.path_importer_cache.clear() -importlib._bootstrap._install(sys, _imp) -''') ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy follow_symlinks: Import a bunch of docstrings from CPython 3.3 (b9c8f1c80f47)
Author: Ronan Lamy Branch: follow_symlinks Changeset: r83156:664a8d8d8eb4 Date: 2016-03-19 06:31 + http://bitbucket.org/pypy/pypy/changeset/664a8d8d8eb4/ Log:Import a bunch of docstrings from CPython 3.3 (b9c8f1c80f47) Update docstrings for all functions that support the new keyword- only arguments 'follow_symlinks' and 'dir_fd'. Add stubs for the missing posix.* functions chflags(), lchflags(), getxattr(), setxattr(), removexattr() and listxattr(). diff --git a/pypy/module/posix/interp_posix.py b/pypy/module/posix/interp_posix.py --- a/pypy/module/posix/interp_posix.py +++ b/pypy/module/posix/interp_posix.py @@ -106,8 +106,14 @@ @unwrap_spec(flag=c_int, mode=c_int) def open(space, w_fname, flag, mode=0777): -"""Open a file (for low level IO). -Return a file descriptor (a small integer).""" +"""open(path, flags, mode=0o777, *, dir_fd=None) + +Open a file for low level IO. Returns a file handle (integer). + +If dir_fd is not None, it should be a file descriptor open to a directory, + and path should be relative; path will then be relative to that directory. +dir_fd may not be implemented on your platform. + If it is unavailable, using it will raise a NotImplementedError.""" try: fd = dispatch_filename(rposix.open)( space, w_fname, flag, mode) @@ -298,20 +304,21 @@ return build_stat_result(space, st) def stat(space, w_path): -"""Perform a stat system call on the given path. Return an object -with (at least) the following attributes: -st_mode -st_ino -st_dev -st_nlink -st_uid -st_gid -st_size -st_atime -st_mtime -st_ctime -""" +"""stat(path, *, dir_fd=None, follow_symlinks=True) -> stat result +Perform a stat system call on the given path. + +path may be specified as either a string or as an open file descriptor. + +If dir_fd is not None, it should be a file descriptor open to a directory, + and path should be relative; path will then be relative to that directory. + dir_fd may not be supported on your platform; if it is unavailable, using + it will raise a NotImplementedError. +If follow_symlinks is False, and the last element of the path is a symbolic + link, stat will examine the symbolic link itself instead of the file the + link points to. +It is an error to use dir_fd or follow_symlinks when specifying path as + an open file descriptor.""" try: st = dispatch_filename(rposix_stat.stat, 0, allow_fd_fn=rposix_stat.fstat)(space, w_path) @@ -321,7 +328,11 @@ return build_stat_result(space, st) def lstat(space, w_path): -"Like stat(path), but do not follow symbolic links." +"""lstat(path, *, dir_fd=None) -> stat result + +Like stat(), but do not follow symbolic links. +Equivalent to stat(path, follow_symlinks=False).""" + try: st = dispatch_filename(rposix_stat.lstat)(space, w_path) except OSError, e: @@ -360,6 +371,13 @@ def statvfs(space, w_path): +"""statvfs(path) + +Perform a statvfs system call on the given path. + +path may always be specified as a string. +On some platforms, path may also be specified as an open file descriptor. + If this functionality is unavailable, using it raises an exception.""" try: st = dispatch_filename(rposix_stat.statvfs)(space, w_path) except OSError as e: @@ -389,15 +407,27 @@ @unwrap_spec(mode=c_int) def access(space, w_path, mode): -""" -access(path, mode) -> 1 if granted, 0 otherwise +"""access(path, mode, *, dir_fd=None, effective_ids=False, follow_symlinks=True) -Use the real uid/gid to test for access to a path. Note that most -operations will use the effective uid/gid, therefore this routine can -be used in a suid/sgid environment to test if the invoking user has the -specified access to the path. The mode argument can be F_OK to test -existence, or the inclusive-OR of R_OK, W_OK, and X_OK. -""" +Use the real uid/gid to test for access to a path. Returns True if granted, +False otherwise. + +If dir_fd is not None, it should be a file descriptor open to a directory, + and path should be relative; path will then be relative to that directory. +If effective_ids is True, access will use the effective uid/gid instead of + the real uid/gid. +If follow_symlinks is False, and the last element of the path is a symbolic + link, access will examine the symbolic link itself instead of the file the + link points to. +dir_fd, effective_ids, and follow_symlinks may not be implemented + on your platform. If they are unavailable, using them will raise a + NotImplementedError. + +Note that most operations will use the effective uid/gid, therefore this + routine can be used in a suid/sgid environment to test if the invoking user + has the specified access to the path. +The mode argument can be F_OK to test existence, or the inclusive-OR + of R_OK, W_OK, and X_OK."""
[pypy-commit] pypy py3.3-bootstrap-again: Close branch py3.3-bootstrap-again
Author: Ronan Lamy Branch: py3.3-bootstrap-again Changeset: r83116:8d273b40ca8d Date: 2016-03-18 01:13 + http://bitbucket.org/pypy/pypy/changeset/8d273b40ca8d/ Log:Close branch py3.3-bootstrap-again ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.3: Merged in py3.3-bootstrap-again (pull request #417)
Author: Ronan Lamy Branch: py3.3 Changeset: r83117:f52e4b4b7338 Date: 2016-03-18 01:13 + http://bitbucket.org/pypy/pypy/changeset/f52e4b4b7338/ Log:Merged in py3.3-bootstrap-again (pull request #417) Do not import importlib during objspace creation diff --git a/pypy/module/imp/__init__.py b/pypy/module/imp/__init__.py --- a/pypy/module/imp/__init__.py +++ b/pypy/module/imp/__init__.py @@ -51,11 +51,3 @@ add_fork_hook('before', interp_imp.acquire_lock) add_fork_hook('parent', interp_imp.release_lock) add_fork_hook('child', interp_imp.reinit_lock) - -def setup_after_space_initialization(self): -# Install importlib as __import__ -self.space.appexec([], '''(): -import importlib._bootstrap, sys, _imp -sys.path_importer_cache.clear() -importlib._bootstrap._install(sys, _imp) -''') ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3k: hg merge py3.3
Author: Ronan Lamy Branch: py3k Changeset: r83133:5ce0c542f4d8 Date: 2016-03-18 16:57 + http://bitbucket.org/pypy/pypy/changeset/5ce0c542f4d8/ Log:hg merge py3.3 diff --git a/pypy/module/imp/__init__.py b/pypy/module/imp/__init__.py --- a/pypy/module/imp/__init__.py +++ b/pypy/module/imp/__init__.py @@ -51,11 +51,3 @@ add_fork_hook('before', interp_imp.acquire_lock) add_fork_hook('parent', interp_imp.release_lock) add_fork_hook('child', interp_imp.reinit_lock) - -def setup_after_space_initialization(self): -# Install importlib as __import__ -self.space.appexec([], '''(): -import importlib._bootstrap, sys, _imp -sys.path_importer_cache.clear() -importlib._bootstrap._install(sys, _imp) -''') ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit