Author: Ronan Lamy <ronan.l...@gmail.com> Branch: py3k Changeset: r85450:62e370af096e Date: 2016-06-29 16:00 +0100 http://bitbucket.org/pypy/pypy/changeset/62e370af096e/
Log: hg merge default diff --git a/pypy/interpreter/astcompiler/tools/asdl_py.py b/pypy/interpreter/astcompiler/tools/asdl_py.py --- a/pypy/interpreter/astcompiler/tools/asdl_py.py +++ b/pypy/interpreter/astcompiler/tools/asdl_py.py @@ -421,7 +421,7 @@ if not (space.isinstance_w(w_obj, space.w_str) or space.isinstance_w(w_obj, space.w_unicode)): raise oefmt(space.w_TypeError, - "AST string must be of type str or unicode") + "AST string must be of type str or unicode") return w_obj def get_field(space, w_node, name, optional): diff --git a/pypy/interpreter/pyparser/automata.py b/pypy/interpreter/pyparser/automata.py --- a/pypy/interpreter/pyparser/automata.py +++ b/pypy/interpreter/pyparser/automata.py @@ -13,12 +13,11 @@ # PYPY Modification: removed the EMPTY class as it's not needed here -# PYPY Modification: we don't need a particuliar DEFAULT class here -# a simple None works fine. -# (Having a DefaultClass inheriting from str makes -# the annotator crash) -DEFAULT = "\00default" # XXX hack, the rtyper does not support dict of with str|None keys - # anyway using dicts doesn't seem the best final way to store these char indexed tables +# PYPY Modification: DEFAULT is a singleton, used only in the pre-RPython +# dicts (see pytokenize.py). Then DFA.__init__() turns these dicts into +# more compact strings. +DEFAULT = object() + # PYPY Modification : removed all automata functions (any, maybe, # newArcPair, etc.) diff --git a/pypy/interpreter/pyparser/gendfa.py b/pypy/interpreter/pyparser/gendfa.py --- a/pypy/interpreter/pyparser/gendfa.py +++ b/pypy/interpreter/pyparser/gendfa.py @@ -294,7 +294,7 @@ i = 0 for k, v in sorted(state.items()): i += 1 - if k == '\x00default': + if k == DEFAULT: k = "automata.DEFAULT" else: k = repr(k) 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 @@ -164,7 +164,7 @@ pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if pytype.c_tp_itemsize != 0: - itemcount = space.len_w(w_obj) # PyStringObject and subclasses + itemcount = space.len_w(w_obj) # PyBytesObject and subclasses else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount) diff --git a/pypy/module/cpyext/test/array.c b/pypy/module/cpyext/test/array.c --- a/pypy/module/cpyext/test/array.c +++ b/pypy/module/cpyext/test/array.c @@ -202,7 +202,6 @@ return PyLong_FromLong((long) ((short *)ap->ob_item)[i]); } - static int h_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v) { @@ -2317,6 +2316,56 @@ } } +static PyObject* +array_multiply(PyObject* obj1, PyObject* obj2) +{ + if (PyList_Check(obj1) && ((arrayobject*)obj2)->ob_descr->typecode == 'i' && Py_SIZE(obj2) == 1) + { + int ii, nn; + int n = PyList_Size(obj1); + PyObject *v = getarrayitem(obj2, 0); + long i = PyLong_AsLong(v); // XXX: error checking? + PyObject * ret = PyList_New(n*i); + for (ii = 0; ii < i; ii++) + for (nn = 0; nn < n; nn++) + { + v = PyList_GetItem(obj1, nn); + PyList_SetItem(ret, nn+ii*n, v); + } + return ret; + } + else if (PyList_Check(obj2) && ((arrayobject*)obj1)->ob_descr->typecode == 'i' && Py_SIZE(obj1) == 1) + { + int ii, nn; + int n = PyList_Size(obj2); + PyObject *v = getarrayitem(obj1, 0); + int i = ((PyIntObject*)v)->ob_ival; + PyObject * ret = PyList_New(n*i); + for (ii = 0; ii < i; ii++) + for (nn = 0; nn < n; nn++) + { + v = PyList_GetItem(obj2, nn); + PyList_SetItem(ret, nn+ii*n, v); + } + return ret; + } + else if(obj1->ob_type == &Arraytype) + fprintf(stderr, "\nCannot multiply array of type %c and %s\n", + ((arrayobject*)obj1)->ob_descr->typecode, obj2->ob_type->tp_name); + else if(obj2->ob_type == &Arraytype) + fprintf(stderr, "\nCannot multiply array of type %c and %s\n", + ((arrayobject*)obj2)->ob_descr->typecode, obj1->ob_type->tp_name); + Py_INCREF(Py_NotImplemented); + return Py_NotImplemented; +} + +static PyNumberMethods array_as_number = { + (binaryfunc)NULL, /* nb_add*/ + (binaryfunc)NULL, /* nb_subtract */ + (binaryfunc)array_multiply, /* nb_multiply */ + (binaryfunc)NULL, /* nb_divide */ +}; + static PyMappingMethods array_as_mapping = { (lenfunc)array_length, (binaryfunc)array_subscr, @@ -2586,7 +2635,7 @@ 0, /* tp_setattr */ 0, /* tp_reserved */ (reprfunc)array_repr, /* tp_repr */ - 0, /* tp_as_number*/ + &array_as_number, /* tp_as_number*/ &array_as_sequence, /* tp_as_sequence*/ &array_as_mapping, /* tp_as_mapping*/ 0, /* tp_hash */ @@ -2595,7 +2644,8 @@ PyObject_GenericGetAttr, /* tp_getattro */ 0, /* tp_setattro */ &array_as_buffer, /* tp_as_buffer*/ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | + Py_TPFLAGS_HAVE_WEAKREFS | Py_TPFLAGS_CHECKTYPES, /* tp_flags */ arraytype_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ diff --git a/pypy/module/cpyext/test/test_arraymodule.py b/pypy/module/cpyext/test/test_arraymodule.py --- a/pypy/module/cpyext/test/test_arraymodule.py +++ b/pypy/module/cpyext/test/test_arraymodule.py @@ -67,3 +67,10 @@ b'\x02\0\0\0' b'\x03\0\0\0' b'\x04\0\0\0') + + def test_binop_mul_impl(self): + # check that rmul is called + module = self.import_module(name='array') + arr = module.array('i', [2]) + res = [1, 2, 3] * arr + assert res == [1, 2, 3, 1, 2, 3] diff --git a/rpython/doc/rpython.rst b/rpython/doc/rpython.rst --- a/rpython/doc/rpython.rst +++ b/rpython/doc/rpython.rst @@ -135,6 +135,12 @@ hash functions and custom equality will not be honored. Use ``rpython.rlib.objectmodel.r_dict`` for custom hash functions. +**sets** + + sets are not directly supported in RPython. Instead you should use a + plain dict and fill the values with None. Values in that dict + will not consume space. + **list comprehensions** May be used to create allocated, initialized arrays. diff --git a/rpython/translator/c/test/test_boehm.py b/rpython/translator/c/test/test_boehm.py --- a/rpython/translator/c/test/test_boehm.py +++ b/rpython/translator/c/test/test_boehm.py @@ -416,8 +416,10 @@ print "not triggered!" return 50 seen = {} - for i in range(1000): + while True: a = fq.next_dead() + if a is None: + break assert a.i not in seen seen[a.i] = True if len(seen) < 500: _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit