[pypy-svn] r79908 - in pypy/branch/psycopg2compatibility/pypy/module/cpyext: . test

dan at codespeak.net dan at codespeak.net
Wed Dec 8 19:25:15 CET 2010


Author: dan
Date: Wed Dec  8 19:25:12 2010
New Revision: 79908

Modified:
   pypy/branch/psycopg2compatibility/pypy/module/cpyext/sequence.py
   pypy/branch/psycopg2compatibility/pypy/module/cpyext/test/test_sequence.py
Log:
Don't allow PySequence_SetItem on tuples, change the the test to reflect this.

Modified: pypy/branch/psycopg2compatibility/pypy/module/cpyext/sequence.py
==============================================================================
--- pypy/branch/psycopg2compatibility/pypy/module/cpyext/sequence.py	(original)
+++ pypy/branch/psycopg2compatibility/pypy/module/cpyext/sequence.py	Wed Dec  8 19:25:12 2010
@@ -7,7 +7,7 @@
 from pypy.objspace.std import listobject, tupleobject
 
 from pypy.module.cpyext.tupleobject import PyTuple_Check, PyTuple_SetItem
-from pypy.module.cpyext.object import Py_IncRef
+from pypy.module.cpyext.object import Py_IncRef, Py_DecRef
 
 @cpython_api([PyObject, Py_ssize_t], PyObject)
 def PySequence_Repeat(space, w_obj, count):
@@ -136,15 +136,10 @@
     This function used an int type for i. This might require
     changes in your code for properly supporting 64-bit systems."""
 
-    Py_IncRef(space, w_v) # XXX: seriously CPython, why should one Py*_SetItem steal but not another!?
-    if PyTuple_Check(space, w_o):
-        return PyTuple_SetItem(space, w_o, i, w_v)
-
     try:
+        Py_IncRef(space, w_v)
         space.setitem(w_o, space.wrap(i), w_v)
         return 0
-    except OperationError, e:
-        if e.match(space, space.w_IndexError):
-            return -1
-        else:
-            raise
+    except:
+        Py_DecRef(space, w_v)
+        raise

Modified: pypy/branch/psycopg2compatibility/pypy/module/cpyext/test/test_sequence.py
==============================================================================
--- pypy/branch/psycopg2compatibility/pypy/module/cpyext/test/test_sequence.py	(original)
+++ pypy/branch/psycopg2compatibility/pypy/module/cpyext/test/test_sequence.py	Wed Dec  8 19:25:12 2010
@@ -75,10 +75,8 @@
         value = api.PyInt_FromLong(42)
         tup = api.PyTuple_New(1)
 
-        result = api.PySequence_SetItem(tup, 0, value)
-        assert result != -1
-
-        assert space.eq_w(space.getitem(tup, space.wrap(0)), value)
+        exc = raises(OperationError, sequence.PySequence_SetItem, space, tup, 0, value)
+        assert exc.value.match(space, space.w_TypeError)
 
         l = api.PyList_New(1)
 
@@ -87,4 +85,3 @@
 
         assert space.eq_w(space.getitem(l, space.wrap(0)), value)
         api.Py_DecRef(value)
-



More information about the Pypy-commit mailing list