[pypy-svn] pypy default: Implemented PyDict_DelItemString in cpyext.
alex_gaynor
commits-noreply at bitbucket.org
Wed Feb 9 18:31:32 CET 2011
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch:
Changeset: r41745:14abe2b13d33
Date: 2011-02-09 12:31 -0500
http://bitbucket.org/pypy/pypy/changeset/14abe2b13d33/
Log: Implemented PyDict_DelItemString in cpyext.
diff --git a/pypy/module/cpyext/dictobject.py b/pypy/module/cpyext/dictobject.py
--- a/pypy/module/cpyext/dictobject.py
+++ b/pypy/module/cpyext/dictobject.py
@@ -60,6 +60,19 @@
return None
return borrow_from(w_dict, w_res)
+ at cpython_api([PyObject, rffi.CCHARP], rffi.INT_real, error=-1)
+def PyDict_DelItemString(space, w_dict, key_ptr):
+ """Remove the entry in dictionary p which has a key specified by the string
+ key. Return 0 on success or -1 on failure."""
+ if PyDict_Check(space, w_dict):
+ key = rffi.charp2str(key_ptr)
+ # our dicts dont have a standardized interface, so we need
+ # to go through the space
+ space.delitem(w_dict, space.wrap(key))
+ return 0
+ else:
+ PyErr_BadInternalCall(space)
+
@cpython_api([PyObject], Py_ssize_t, error=-1)
def PyDict_Size(space, w_obj):
"""
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
@@ -564,12 +564,6 @@
"""
raise NotImplementedError
- at cpython_api([PyObject, rffi.CCHARP], rffi.INT_real, error=-1)
-def PyDict_DelItemString(space, p, key):
- """Remove the entry in dictionary p which has a key specified by the string
- key. Return 0 on success or -1 on failure."""
- raise NotImplementedError
-
@cpython_api([PyObject, PyObject, rffi.INT_real], rffi.INT_real, error=-1)
def PyDict_Merge(space, a, b, override):
"""Iterate over mapping object b adding key-value pairs to dictionary a.
diff --git a/pypy/module/cpyext/test/test_dictobject.py b/pypy/module/cpyext/test/test_dictobject.py
--- a/pypy/module/cpyext/test/test_dictobject.py
+++ b/pypy/module/cpyext/test/test_dictobject.py
@@ -38,6 +38,15 @@
api.PyErr_Clear()
assert api.PyDict_Size(d) == 0
+ space.setitem(d, space.wrap("some_key"), space.wrap(3))
+ buf = rffi.str2charp("some_key")
+ assert api.PyDict_DelItemString(d, buf) == 0
+ assert api.PyDict_Size(d) == 0
+ assert api.PyDict_DelItemString(d, buf) < 0
+ assert api.PyErr_Occurred() is space.w_KeyError
+ api.PyErr_Clear()
+ rffi.free_charp(buf)
+
d = space.wrap({'a': 'b'})
api.PyDict_Clear(d)
assert api.PyDict_Size(d) == 0
More information about the Pypy-commit
mailing list