Author: Antonio Cuni <[email protected]>
Branch: cpyext-fast-typecheck
Changeset: r94103:0db3ba6fe311
Date: 2018-03-22 23:30 +0100
http://bitbucket.org/pypy/pypy/changeset/0db3ba6fe311/
Log: test and fix for wrap_sq_delitem
diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py
--- a/pypy/module/cpyext/slotdefs.py
+++ b/pypy/module/cpyext/slotdefs.py
@@ -312,15 +312,17 @@
if rffi.cast(lltype.Signed, res) == -1:
space.fromcache(State).check_and_raise_exception(always=True)
-def wrap_sq_delitem(space, w_self, w_args, func):
- func_target = rffi.cast(ssizeobjargproc, func)
- check_num_args(space, w_args, 1)
- args_w = space.fixedview(w_args)
- index = space.int_w(space.index(args_w[0]))
- null = rffi.cast(PyObject, 0)
- res = generic_cpy_call(space, func_target, w_self, index, null)
- if rffi.cast(lltype.Signed, res) == -1:
- space.fromcache(State).check_and_raise_exception(always=True)
+class wrap_sq_delitem(W_PyCWrapperObject):
+ def call(self, space, w_self, __args__):
+ self.check_args(__args__, 1)
+ func = self.get_func_to_call()
+ func_target = rffi.cast(ssizeobjargproc, func)
+ w_index = __args__.arguments_w[0]
+ index = space.int_w(space.index(w_index))
+ null = rffi.cast(PyObject, 0)
+ res = generic_cpy_call(space, func_target, w_self, index, null)
+ if rffi.cast(lltype.Signed, res) == -1:
+ space.fromcache(State).check_and_raise_exception(always=True)
# Warning, confusing function name (like CPython). Used only for sq_contains.
class wrap_objobjproc(W_PyCWrapperObject):
diff --git a/pypy/module/cpyext/test/test_typeobject.py
b/pypy/module/cpyext/test/test_typeobject.py
--- a/pypy/module/cpyext/test/test_typeobject.py
+++ b/pypy/module/cpyext/test/test_typeobject.py
@@ -938,7 +938,11 @@
static int
sq_ass_item(PyObject *self, Py_ssize_t i, PyObject *o)
{
- int expected = (i == 10 && PyInt_Check(o) && PyInt_AsLong(o)
== 42);
+ int expected;
+ if (o == NULL) // delitem
+ expected = (i == 12);
+ else // setitem
+ expected = (i == 10 && PyInt_Check(o) && PyInt_AsLong(o)
== 42);
if (!expected) {
PyErr_SetString(PyExc_ValueError, "test failed");
return -1;
@@ -960,6 +964,8 @@
obj[10] = 42
raises(ValueError, "obj[10] = 43")
raises(ValueError, "obj[11] = 42")
+ del obj[12]
+ raises(ValueError, "del obj[13]")
def test_tp_iter(self):
module = self.import_extension('foo', [
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit