[pypy-commit] pypy SpecialisedTuples: Fix. Previously, we would risk getting a specialised tuple if enabled.

arigo noreply at buildbot.pypy.org
Thu Dec 8 17:43:23 CET 2011

Author: Armin Rigo <arigo at tunes.org>
Branch: SpecialisedTuples
Changeset: r50309:7ad77a6f050c
Date: 2011-12-08 17:43 +0100

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):

More information about the pypy-commit mailing list