[pypy-commit] pypy default: cpyext: implement PySet_Pop(), PySet_Clear()
amauryfa
noreply at buildbot.pypy.org
Wed Feb 15 23:48:43 CET 2012
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch:
Changeset: r52524:176ba45b109b
Date: 2012-02-15 18:50 +0100
http://bitbucket.org/pypy/pypy/changeset/176ba45b109b/
Log: cpyext: implement PySet_Pop(), PySet_Clear()
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
@@ -384,6 +384,7 @@
"Dict": "space.w_dict",
"Tuple": "space.w_tuple",
"List": "space.w_list",
+ "Set": "space.w_set",
"Int": "space.w_int",
"Bool": "space.w_bool",
"Float": "space.w_float",
diff --git a/pypy/module/cpyext/setobject.py b/pypy/module/cpyext/setobject.py
--- a/pypy/module/cpyext/setobject.py
+++ b/pypy/module/cpyext/setobject.py
@@ -54,6 +54,20 @@
return 0
+ at cpython_api([PyObject], PyObject)
+def PySet_Pop(space, w_set):
+ """Return a new reference to an arbitrary object in the set, and removes the
+ object from the set. Return NULL on failure. Raise KeyError if the
+ set is empty. Raise a SystemError if set is an not an instance of
+ set or its subtype."""
+ return space.call_method(w_set, "pop")
+
+ at cpython_api([PyObject], rffi.INT_real, error=-1)
+def PySet_Clear(space, w_set):
+ """Empty an existing set of all elements."""
+ space.call_method(w_set, 'clear')
+ return 0
+
@cpython_api([PyObject], Py_ssize_t, error=CANNOT_FAIL)
def PySet_GET_SIZE(space, w_s):
"""Macro form of PySet_Size() without error checking."""
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
@@ -1755,19 +1755,6 @@
building-up new frozensets with PySet_Add()."""
raise NotImplementedError
- at cpython_api([PyObject], PyObject)
-def PySet_Pop(space, set):
- """Return a new reference to an arbitrary object in the set, and removes the
- object from the set. Return NULL on failure. Raise KeyError if the
- set is empty. Raise a SystemError if set is an not an instance of
- set or its subtype."""
- raise NotImplementedError
-
- at cpython_api([PyObject], rffi.INT_real, error=-1)
-def PySet_Clear(space, set):
- """Empty an existing set of all elements."""
- raise NotImplementedError
-
@cpython_api([rffi.CCHARP, Py_ssize_t, rffi.CCHARP, rffi.CCHARP], PyObject)
def PyString_Decode(space, s, size, encoding, errors):
"""Create an object by decoding size bytes of the encoded buffer s using the
diff --git a/pypy/module/cpyext/test/test_setobject.py b/pypy/module/cpyext/test/test_setobject.py
--- a/pypy/module/cpyext/test/test_setobject.py
+++ b/pypy/module/cpyext/test/test_setobject.py
@@ -32,3 +32,13 @@
w_set = api.PySet_New(space.wrap([1,2,3,4]))
assert api.PySet_Contains(w_set, space.wrap(1))
assert not api.PySet_Contains(w_set, space.wrap(0))
+
+ def test_set_pop_clear(self, space, api):
+ w_set = api.PySet_New(space.wrap([1,2,3,4]))
+ w_obj = api.PySet_Pop(w_set)
+ assert space.int_w(w_obj) in (1,2,3,4)
+ assert space.len_w(w_set) == 3
+ api.PySet_Clear(w_set)
+ assert space.len_w(w_set) == 0
+
+
More information about the pypy-commit
mailing list