[pypy-commit] pypy dynamic-specialized-tuple: random cpyext changes

alex_gaynor noreply at buildbot.pypy.org
Tue Mar 13 09:15:34 CET 2012


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: dynamic-specialized-tuple
Changeset: r53435:0cfdda05f00a
Date: 2012-03-13 00:38 -0700
http://bitbucket.org/pypy/pypy/changeset/0cfdda05f00a/

Log:	random cpyext changes

diff --git a/pypy/module/cpyext/test/test_tupleobject.py b/pypy/module/cpyext/test/test_tupleobject.py
--- a/pypy/module/cpyext/test/test_tupleobject.py
+++ b/pypy/module/cpyext/test/test_tupleobject.py
@@ -10,12 +10,12 @@
     def test_tupleobject(self, space, api):
         assert not api.PyTuple_Check(space.w_None)
         assert api.PyTuple_SetItem(space.w_None, 0, space.w_None) == -1
-        atuple = space.newtuple([0, 1, 'yay'])
+        atuple = space.wrap((0, 1, 'yay'))
         assert api.PyTuple_Size(atuple) == 3
         assert api.PyTuple_GET_SIZE(atuple) == 3
         raises(TypeError, api.PyTuple_Size(space.newlist([])))
         api.PyErr_Clear()
-    
+
     def test_tuple_resize(self, space, api):
         py_tuple = api.PyTuple_New(3)
         ar = lltype.malloc(PyObjectP.TO, 1, flavor='raw')
@@ -23,11 +23,11 @@
         api._PyTuple_Resize(ar, 2)
         py_tuple = from_ref(space, ar[0])
         assert space.int_w(space.len(py_tuple)) == 2
-        
+
         api._PyTuple_Resize(ar, 10)
         py_tuple = from_ref(space, ar[0])
         assert space.int_w(space.len(py_tuple)) == 10
-        
+
         api.Py_DecRef(ar[0])
         lltype.free(ar, flavor='raw')
 
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
@@ -11,24 +11,25 @@
 
 @cpython_api([Py_ssize_t], PyObject)
 def PyTuple_New(space, size):
-    return W_TupleObject([space.w_None] * size)
+    return space.newtuple([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):
     if not PyTuple_Check(space, w_t):
         # XXX this should also steal a reference, test it!!!
         PyErr_BadInternalCall(space)
-    _setitem_tuple(w_t, pos, w_obj)
+    _setitem_tuple(space, w_t, pos, w_obj)
     Py_DecRef(space, w_obj) # SetItem steals a reference!
     return 0
 
-def _setitem_tuple(w_t, pos, w_obj):
+def _setitem_tuple(space, w_t, pos, w_obj):
     # 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.
+    from pypy.objspace.std.tupletype import store_obj
     assert isinstance(w_t, W_TupleObject)
-    w_t.wrappeditems[pos] = w_obj
+    store_obj(space, w_t.tuplestorage, pos, w_obj)
 
 @cpython_api([PyObject, Py_ssize_t], PyObject)
 def PyTuple_GetItem(space, w_t, pos):
@@ -68,13 +69,13 @@
     if not PyTuple_Check(space, py_tuple):
         PyErr_BadInternalCall(space)
     py_newtuple = PyTuple_New(space, newsize)
-    
+
     to_cp = newsize
     oldsize = space.int_w(space.len(py_tuple))
     if oldsize < newsize:
         to_cp = oldsize
     for i in range(to_cp):
-        _setitem_tuple(py_newtuple, i, space.getitem(py_tuple, space.wrap(i)))
+        _setitem_tuple(space, py_newtuple, i, space.getitem(py_tuple, space.wrap(i)))
     Py_DecRef(space, ref[0])
     ref[0] = make_ref(space, py_newtuple)
     return 0


More information about the pypy-commit mailing list