diff options
author | Raymond Hettinger <python@rcn.com> | 2005-08-13 02:28:54 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2005-08-13 02:28:54 (GMT) |
commit | ab294199b772e47dd86ca665dbc1080715b844d2 (patch) | |
tree | 355e719f2cbc756be0d9c8a2943a9056cc304a77 /Objects/setobject.c | |
parent | 787b4c5fea8476a1146918f90a6da7f63d7aa31c (diff) | |
download | cpython-ab294199b772e47dd86ca665dbc1080715b844d2.zip cpython-ab294199b772e47dd86ca665dbc1080715b844d2.tar.gz cpython-ab294199b772e47dd86ca665dbc1080715b844d2.tar.bz2 |
Teach set modules to correctly compute s-=s and s^=s as the empty set.
Diffstat (limited to 'Objects/setobject.c')
-rw-r--r-- | Objects/setobject.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c index e77e7cd..0e65320 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -193,6 +193,16 @@ frozenset_copy(PySetObject *so) PyDoc_STRVAR(copy_doc, "Return a shallow copy of a set."); static PyObject * +set_clear(PySetObject *so) +{ + PyDict_Clear(so->data); + so->hash = -1; + Py_RETURN_NONE; +} + +PyDoc_STRVAR(clear_doc, "Remove all elements from this set."); + +static PyObject * set_union(PySetObject *so, PyObject *other) { PySetObject *result; @@ -379,6 +389,9 @@ static PyObject * set_difference_update(PySetObject *so, PyObject *other) { PyObject *item, *tgtdata, *it; + + if ((PyObject *)so == other) + return set_clear(so); it = PyObject_GetIter(other); if (it == NULL) @@ -758,16 +771,6 @@ set_tp_print(PySetObject *so, FILE *fp, int flags) return 0; } -static PyObject * -set_clear(PySetObject *so) -{ - PyDict_Clear(so->data); - so->hash = -1; - Py_RETURN_NONE; -} - -PyDoc_STRVAR(clear_doc, "Remove all elements from this set."); - static int set_tp_clear(PySetObject *so) { |