diff options
author | Raymond Hettinger <python@rcn.com> | 2008-01-28 20:34:33 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2008-01-28 20:34:33 (GMT) |
commit | ecdcb5895029c83c8bb5f98de502beaa56b78c9e (patch) | |
tree | 92e2ac58fc2e7f4d2d1e0514ba3a26c4adbad6af /Objects | |
parent | 99120c4f7ea621ba2386c11d1300da335853dd68 (diff) | |
download | cpython-ecdcb5895029c83c8bb5f98de502beaa56b78c9e.zip cpython-ecdcb5895029c83c8bb5f98de502beaa56b78c9e.tar.gz cpython-ecdcb5895029c83c8bb5f98de502beaa56b78c9e.tar.bz2 |
Make PySet_Add() work with frozensets.
Works like PyTuple_SetItem() to build-up values in a brand new frozenset.
Also, PyFrozenSet_New() is now guaranteed to produce a distinct new frozenset.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/setobject.c | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c index c8db7ce..ee11b9f 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -2142,17 +2142,7 @@ PySet_New(PyObject *iterable) PyObject * PyFrozenSet_New(PyObject *iterable) { - PyObject *args, *result; - - if (iterable == NULL) - args = PyTuple_New(0); - else - args = PyTuple_Pack(1, iterable); - if (args == NULL) - return NULL; - result = frozenset_new(&PyFrozenSet_Type, args, NULL); - Py_DECREF(args); - return result; + return make_new_set(&PyFrozenSet_Type, iterable); } Py_ssize_t @@ -2196,13 +2186,13 @@ PySet_Discard(PyObject *set, PyObject *key) } int -PySet_Add(PyObject *set, PyObject *key) +PySet_Add(PyObject *anyset, PyObject *key) { - if (!PyType_IsSubtype(Py_TYPE(set), &PySet_Type)) { + if (!PyAnySet_Check(anyset)) { PyErr_BadInternalCall(); return -1; } - return set_add_key((PySetObject *)set, key); + return set_add_key((PySetObject *)anyset, key); } int @@ -2345,7 +2335,6 @@ test_c_api(PySetObject *so) f = PyFrozenSet_New(dup); assert(PySet_Size(f) == 3); assert(PyFrozenSet_CheckExact(f)); - assertRaises(PySet_Add(f, elem) == -1, PyExc_SystemError); assertRaises(PySet_Discard(f, elem) == -1, PyExc_SystemError); assertRaises(PySet_Pop(f) == NULL, PyExc_SystemError); Py_DECREF(f); |