[pypy-svn] r79783 - in pypy/branch/fast-forward/pypy/module/cpyext: . test
afa at codespeak.net
afa at codespeak.net
Fri Dec 3 17:00:36 CET 2010
Author: afa
Date: Fri Dec 3 17:00:35 2010
New Revision: 79783
Modified:
pypy/branch/fast-forward/pypy/module/cpyext/dictobject.py
pypy/branch/fast-forward/pypy/module/cpyext/stubs.py
pypy/branch/fast-forward/pypy/module/cpyext/test/test_dictobject.py
Log:
Add PyDict_Contains
Modified: pypy/branch/fast-forward/pypy/module/cpyext/dictobject.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/cpyext/dictobject.py (original)
+++ pypy/branch/fast-forward/pypy/module/cpyext/dictobject.py Fri Dec 3 17:00:35 2010
@@ -67,6 +67,15 @@
len(p) on a dictionary."""
return space.int_w(space.len(w_obj))
+ at cpython_api([PyObject, PyObject], rffi.INT_real, error=-1)
+def PyDict_Contains(space, w_obj, w_value):
+ """Determine if dictionary p contains key. If an item in p is matches
+ key, return 1, otherwise return 0. On error, return -1.
+ This is equivalent to the Python expression key in p.
+ """
+ w_res = space.contains(w_obj, w_value)
+ return space.int_w(w_res)
+
@cpython_api([PyObject], lltype.Void)
def PyDict_Clear(space, w_obj):
"""Empty an existing dictionary of all key-value pairs."""
Modified: pypy/branch/fast-forward/pypy/module/cpyext/stubs.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/cpyext/stubs.py (original)
+++ pypy/branch/fast-forward/pypy/module/cpyext/stubs.py Fri Dec 3 17:00:35 2010
@@ -615,14 +615,6 @@
"""
raise NotImplementedError
- at cpython_api([PyObject, PyObject], rffi.INT_real, error=-1)
-def PyDict_Contains(space, p, key):
- """Determine if dictionary p contains key. If an item in p is matches
- key, return 1, otherwise return 0. On error, return -1.
- This is equivalent to the Python expression key in p.
- """
- raise NotImplementedError
-
@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
Modified: pypy/branch/fast-forward/pypy/module/cpyext/test/test_dictobject.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/cpyext/test/test_dictobject.py (original)
+++ pypy/branch/fast-forward/pypy/module/cpyext/test/test_dictobject.py Fri Dec 3 17:00:35 2010
@@ -29,6 +29,9 @@
rffi.free_charp(buf)
assert not api.PyErr_Occurred()
+ assert api.PyDict_Contains(d, space.wrap("c"))
+ assert not api.PyDict_Contains(d, space.wrap("z"))
+
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
More information about the Pypy-commit
mailing list