[pypy-svn] r73989 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test

afa at codespeak.net afa at codespeak.net
Thu Apr 22 20:28:21 CEST 2010


Author: afa
Date: Thu Apr 22 20:28:20 2010
New Revision: 73989

Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/dictobject.py
   pypy/branch/cpython-extension/pypy/module/cpyext/test/test_dictobject.py
Log:
PyDict_DelItem


Modified: pypy/branch/cpython-extension/pypy/module/cpyext/dictobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/dictobject.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/dictobject.py	Thu Apr 22 20:28:20 2010
@@ -26,6 +26,14 @@
     else:
         PyErr_BadInternalCall(space)
 
+ at cpython_api([PyObject, PyObject], rffi.INT_real, error=-1)
+def PyDict_DelItem(space, w_dict, w_key):
+    if PyDict_Check(space, w_dict):
+        space.delitem(w_dict, w_key)
+        return 0
+    else:
+        PyErr_BadInternalCall(space)
+
 @cpython_api([PyObject, CONST_STRING, PyObject], rffi.INT_real, error=-1)
 def PyDict_SetItemString(space, w_dict, key_ptr, w_obj):
     if PyDict_Check(space, w_dict):

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_dictobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/test/test_dictobject.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_dictobject.py	Thu Apr 22 20:28:20 2010
@@ -22,6 +22,12 @@
         assert api.PyErr_Occurred() is space.w_KeyError
         api.PyErr_Clear()
 
+        assert api.PyDict_DelItem(d, space.wrap("c")) == 0
+        assert api.PyDict_DelItem(d, space.wrap("name")) < 0
+        assert api.PyErr_Occurred() is space.w_KeyError
+        api.PyErr_Clear()
+        assert api.PyDict_Size(d) == 0
+
     def test_check(self, space, api):
         d = api.PyDict_New()
         assert api.PyDict_Check(d)



More information about the Pypy-commit mailing list