Commits

Amaury Forgeot d'Arc committed f46e309

issue887: cpyext: add support for mp_ass_subscript

  • Participants
  • Parent commits fe60321

Comments (0)

Files changed (2)

File pypy/module/cpyext/slotdefs.py

     unaryfunc, wrapperfunc, ternaryfunc, PyTypeObjectPtr, binaryfunc,
     getattrfunc, getattrofunc, setattrofunc, lenfunc, ssizeargfunc,
     ssizessizeargfunc, ssizeobjargproc, iternextfunc, initproc, richcmpfunc,
-    cmpfunc, hashfunc, descrgetfunc, descrsetfunc, objobjproc, readbufferproc)
+    cmpfunc, hashfunc, descrgetfunc, descrsetfunc, objobjproc, objobjargproc,
+    readbufferproc)
 from pypy.module.cpyext.pyobject import from_ref
 from pypy.module.cpyext.pyerrors import PyErr_Occurred
 from pypy.module.cpyext.state import State
         space.fromcache(State).check_and_raise_exception(always=True)
     return space.wrap(res)
 
+def wrap_objobjargproc(space, w_self, w_args, func):
+    func_target = rffi.cast(objobjargproc, func)
+    check_num_args(space, w_args, 2)
+    w_key, w_value = space.fixedview(w_args)
+    res = generic_cpy_call(space, func_target, w_self, w_key, w_value)
+    if rffi.cast(lltype.Signed, res) == -1:
+        space.fromcache(State).check_and_raise_exception(always=True)
+    return space.wrap(res)
+
 def wrap_ssizessizeargfunc(space, w_self, w_args, func):
     func_target = rffi.cast(ssizessizeargfunc, func)
     check_num_args(space, w_args, 2)

File pypy/module/cpyext/test/test_typeobject.py

             def __str__(self):
                 return "text"
         assert module.tp_str(C()) == "text"
+
+    def test_mp_ass_subscript(self):
+        module = self.import_extension('foo', [
+           ("new_obj", "METH_NOARGS",
+            '''
+                PyObject *obj;
+                Foo_Type.tp_as_mapping = &tp_as_mapping;
+                tp_as_mapping.mp_ass_subscript = mp_ass_subscript;
+                if (PyType_Ready(&Foo_Type) < 0) return NULL;
+                obj = PyObject_New(PyObject, &Foo_Type);
+                return obj;
+            '''
+            )],
+            '''
+            static int
+            mp_ass_subscript(PyObject *self, PyObject *key, PyObject *value)
+            {
+                PyErr_SetNone(PyExc_ZeroDivisionError);
+                return -1;
+            }
+            PyMappingMethods tp_as_mapping;
+            static PyTypeObject Foo_Type = {
+                PyVarObject_HEAD_INIT(NULL, 0)
+                "foo.foo",
+            };
+            ''')
+        obj = module.new_obj()
+        raises(ZeroDivisionError, obj.__setitem__, 5, None)