Author: Armin Rigo <ar...@tunes.org> Branch: SpecialisedTuples Changeset: r50309:7ad77a6f050c Date: 2011-12-08 17:43 +0100 http://bitbucket.org/pypy/pypy/changeset/7ad77a6f050c/
Log: Fix. Previously, we would risk getting a specialised tuple if enabled. That makes little sense: we can only handle setting arbitrary items in a generic W_TupleObject. 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 @@ -6,13 +6,12 @@ borrow_from, make_ref, from_ref) from pypy.module.cpyext.pyerrors import PyErr_BadInternalCall from pypy.objspace.std.tupleobject import W_TupleObject -from pypy.objspace.std.smalltupleobject import W_SmallTupleObject PyTuple_Check, PyTuple_CheckExact = build_type_checkers("Tuple") @cpython_api([Py_ssize_t], PyObject) def PyTuple_New(space, size): - return space.newtuple([space.w_None] * size) + return W_TupleObject([space.w_None] * size) @cpython_api([PyObject, Py_ssize_t, PyObject], rffi.INT_real, error=-1) def PyTuple_SetItem(space, w_t, pos, w_obj): @@ -24,12 +23,12 @@ return 0 def _setitem_tuple(w_t, pos, w_obj): - if isinstance(w_t, W_TupleObject): - w_t.wrappeditems[pos] = w_obj - elif isinstance(w_t, W_SmallTupleObject): - w_t.setitem(pos, w_obj) - else: - assert False + # this function checks that w_t is really a W_TupleObject. It + # should only ever be called with a freshly built tuple from + # PyTuple_New(), which always return a W_TupleObject, even if there + # are also other implementations of tuples. + assert isinstance(w_t, W_TupleObject) + w_t.wrappeditems[pos] = w_obj @cpython_api([PyObject, Py_ssize_t], PyObject) def PyTuple_GetItem(space, w_t, pos): _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit