Author: Ronan Lamy <ronan.l...@gmail.com>
Branch: 
Changeset: r95179:a5735c0b1edd
Date: 2018-10-03 18:29 +0100
http://bitbucket.org/pypy/pypy/changeset/a5735c0b1edd/

Log:    Add C implementations for PyObject_DelItemString, PyMapping_DelItem,
        PyMapping_DelItemString

diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -603,10 +603,11 @@
     'PyObject_CallMethod', 'PyObject_CallFunctionObjArgs', 
'PyObject_CallMethodObjArgs',
     '_PyObject_CallFunction_SizeT', '_PyObject_CallMethod_SizeT',
 
-    'PyObject_GetBuffer', 'PyBuffer_Release',
-    'PyBuffer_FromMemory', 'PyBuffer_FromReadWriteMemory', 
'PyBuffer_FromObject',
-    'PyBuffer_FromReadWriteObject', 'PyBuffer_New', 'PyBuffer_Type', 
'_Py_get_buffer_type',
-    '_Py_setfilesystemdefaultencoding',
+    'PyObject_DelItemString', 'PyObject_GetBuffer', 'PyBuffer_Release',
+
+    'PyBuffer_FromMemory', 'PyBuffer_FromReadWriteMemory',
+    'PyBuffer_FromObject', 'PyBuffer_FromReadWriteObject', 'PyBuffer_New',
+    'PyBuffer_Type', '_Py_get_buffer_type', '_Py_setfilesystemdefaultencoding',
 
     'PyCObject_FromVoidPtr', 'PyCObject_FromVoidPtrAndDesc', 
'PyCObject_AsVoidPtr',
     'PyCObject_GetDesc', 'PyCObject_Import', 'PyCObject_SetVoidPtr',
@@ -1299,7 +1300,7 @@
     # if do tuple_attach of the prebuilt empty tuple, we need to call
     # _PyPy_Malloc)
     builder.attach_all(space)
-    
+
     setup_init_functions(eci, prefix)
     return modulename.new(ext='')
 
diff --git a/pypy/module/cpyext/include/abstract.h 
b/pypy/module/cpyext/include/abstract.h
--- a/pypy/module/cpyext/include/abstract.h
+++ b/pypy/module/cpyext/include/abstract.h
@@ -4,6 +4,15 @@
 extern "C" {
 #endif
 
+     PyAPI_FUNC(int) PyObject_DelItemString(PyObject *o, char *key);
+
+       /*
+     Remove the mapping for object, key, from the object *o.
+     Returns -1 on failure.  This is equivalent to
+     the Python statement: del o[key].
+       */
+
+
     /* new buffer API */
 
 #define PyObject_CheckBuffer(obj) \
@@ -28,6 +37,27 @@
        /* Releases a Py_buffer obtained from getbuffer ParseTuple's s*.
     */
 
+/*  Mapping protocol:*/
+
+     /* implemented as a macro:
+
+     int PyMapping_DelItemString(PyObject *o, char *key);
+
+     Remove the mapping for object, key, from the object *o.
+     Returns -1 on failure.  This is equivalent to
+     the Python statement: del o[key].
+       */
+#define PyMapping_DelItemString(O,K) PyObject_DelItemString((O),(K))
+
+     /* implemented as a macro:
+
+     int PyMapping_DelItem(PyObject *o, PyObject *key);
+
+     Remove the mapping for object, key, from the object *o.
+     Returns -1 on failure.  This is equivalent to
+     the Python statement: del o[key].
+       */
+#define PyMapping_DelItem(O,K) PyObject_DelItem((O),(K))
 
 #ifdef __cplusplus
 }
diff --git a/pypy/module/cpyext/src/abstract.c 
b/pypy/module/cpyext/src/abstract.c
--- a/pypy/module/cpyext/src/abstract.c
+++ b/pypy/module/cpyext/src/abstract.c
@@ -23,6 +23,23 @@
 /* Operations on any object */
 
 int
+PyObject_DelItemString(PyObject *o, char *key)
+{
+    PyObject *okey;
+    int ret;
+
+    if (o == NULL || key == NULL) {
+        null_error();
+        return -1;
+    }
+    okey = PyString_FromString(key);
+    if (okey == NULL)
+        return -1;
+    ret = PyObject_DelItem(o, okey);
+    Py_DECREF(okey);
+    return ret;
+}
+int
 PyObject_CheckReadBuffer(PyObject *obj)
 {
     PyBufferProcs *pb = obj->ob_type->tp_as_buffer;
@@ -101,6 +118,20 @@
     return 0;
 }
 
+/* Buffer C-API for Python 3.0 */
+
+int
+PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags)
+{
+    if (!PyObject_CheckBuffer(obj)) {
+        PyErr_Format(PyExc_TypeError,
+                     "'%100s' does not have the buffer interface",
+                     Py_TYPE(obj)->tp_name);
+        return -1;
+    }
+    return (*(obj->ob_type->tp_as_buffer->bf_getbuffer))(obj, view, flags);
+}
+
 void*
 PyBuffer_GetPointer(Py_buffer *view, Py_ssize_t *indices)
 {
@@ -116,6 +147,7 @@
     return (void*)pointer;
 }
 
+
 void
 _Py_add_one_to_index_F(int nd, Py_ssize_t *index, const Py_ssize_t *shape)
 {
@@ -258,19 +290,6 @@
 
 
 
-/* Buffer C-API for Python 3.0 */
-
-int
-PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags)
-{
-    if (!PyObject_CheckBuffer(obj)) {
-        PyErr_Format(PyExc_TypeError,
-                     "'%100s' does not have the buffer interface",
-                     Py_TYPE(obj)->tp_name);
-        return -1;
-    }
-    return (*(obj->ob_type->tp_as_buffer->bf_getbuffer))(obj, view, flags);
-}
 
 void
 PyBuffer_Release(Py_buffer *view)
@@ -428,6 +447,7 @@
     return retval;
 }
 
+
 static PyObject *
 objargs_mktuple(va_list va)
 {
diff --git a/pypy/module/cpyext/stubs.py b/pypy/module/cpyext/stubs.py
--- a/pypy/module/cpyext/stubs.py
+++ b/pypy/module/cpyext/stubs.py
@@ -1233,18 +1233,6 @@
     """
     raise NotImplementedError
 
-@cpython_api([PyObject, rffi.CCHARP], rffi.INT_real, error=-1)
-def PyMapping_DelItemString(space, o, key):
-    """Remove the mapping for object key from the object o. Return -1 on
-    failure.  This is equivalent to the Python statement del o[key]."""
-    raise NotImplementedError
-
-@cpython_api([PyObject, PyObject], rffi.INT_real, error=-1)
-def PyMapping_DelItem(space, o, key):
-    """Remove the mapping for object key from the object o. Return -1 on
-    failure.  This is equivalent to the Python statement del o[key]."""
-    raise NotImplementedError
-
 @cpython_api([lltype.Signed, FILE, rffi.INT_real], lltype.Void)
 def PyMarshal_WriteLongToFile(space, value, file, version):
     """Marshal a long integer, value, to file.  This will only write
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to