[Python-checkins] python/dist/src/Objects setobject.c,1.8,1.9
rhettinger at users.sourceforge.net
rhettinger at users.sourceforge.net
Fri Nov 21 22:55:25 EST 2003
Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1:/tmp/cvs-serv15693/Objects
Modified Files:
setobject.c
Log Message:
Extend temporary hashability to remove() and discard().
Brings the functionality back in line with sets.py.
Index: setobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/setobject.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** setobject.c 21 Nov 2003 18:36:53 -0000 1.8
--- setobject.c 22 Nov 2003 03:55:23 -0000 1.9
***************
*** 74,77 ****
--- 74,92 ----
}
+ static PyObject *
+ frozenset_dict_wrapper(PyObject *d)
+ {
+ PySetObject *w;
+
+ assert(PyDict_Check(d));
+ w = (PySetObject *)make_new_set(&PyFrozenSet_Type, NULL);
+ if (w == NULL)
+ return NULL;
+ Py_DECREF(w->data);
+ Py_INCREF(d);
+ w->data = d;
+ return (PyObject *)w;
+ }
+
static void
set_dealloc(PySetObject *so)
***************
*** 105,110 ****
set_contains(PySetObject *so, PyObject *key)
{
! PyObject *olddict;
! PySetObject *tmp;
int result;
--- 120,124 ----
set_contains(PySetObject *so, PyObject *key)
{
! PyObject *tmp;
int result;
***************
*** 112,122 ****
if (result == -1 && PyType_IsSubtype(key->ob_type, &PySet_Type)) {
PyErr_Clear();
! tmp = (PySetObject *)make_new_set(&PyFrozenSet_Type, NULL);
if (tmp == NULL)
return -1;
! olddict = tmp->data;
! tmp->data = ((PySetObject *)(key))->data;
! result = PySequence_Contains(so->data, (PyObject *)tmp);
! tmp->data = olddict;
Py_DECREF(tmp);
}
--- 126,133 ----
if (result == -1 && PyType_IsSubtype(key->ob_type, &PySet_Type)) {
PyErr_Clear();
! tmp = frozenset_dict_wrapper(((PySetObject *)(key))->data);
if (tmp == NULL)
return -1;
! result = PySequence_Contains(so->data, tmp);
Py_DECREF(tmp);
}
***************
*** 821,826 ****
set_remove(PySetObject *so, PyObject *item)
{
! if (PyDict_DelItem(so->data, item) == -1)
! return NULL;
Py_INCREF(Py_None);
return Py_None;
--- 832,850 ----
set_remove(PySetObject *so, PyObject *item)
{
! PyObject *tmp;
!
! if (PyDict_DelItem(so->data, item) == -1) {
! if (!PyType_IsSubtype(item->ob_type, &PySet_Type))
! return NULL;
! PyErr_Clear();
! tmp = frozenset_dict_wrapper(((PySetObject *)(item))->data);
! if (tmp == NULL)
! return NULL;
! if (PyDict_DelItem(so->data, tmp) == -1) {
! Py_DECREF(tmp);
! return NULL;
! }
! Py_DECREF(tmp);
! }
Py_INCREF(Py_None);
return Py_None;
***************
*** 835,843 ****
set_discard(PySetObject *so, PyObject *item)
{
if (PyDict_DelItem(so->data, item) == -1) {
if (PyErr_ExceptionMatches(PyExc_KeyError))
PyErr_Clear();
! else
! return NULL;
}
Py_INCREF(Py_None);
--- 859,884 ----
set_discard(PySetObject *so, PyObject *item)
{
+ PyObject *tmp;
+
if (PyDict_DelItem(so->data, item) == -1) {
if (PyErr_ExceptionMatches(PyExc_KeyError))
PyErr_Clear();
! else {
! if (!PyType_IsSubtype(item->ob_type, &PySet_Type))
! return NULL;
! PyErr_Clear();
! tmp = frozenset_dict_wrapper(((PySetObject *)(item))->data);
! if (tmp == NULL)
! return NULL;
! if (PyDict_DelItem(so->data, tmp) == -1) {
! if (PyErr_ExceptionMatches(PyExc_KeyError))
! PyErr_Clear();
! else {
! Py_DECREF(tmp);
! return NULL;
! }
! }
! Py_DECREF(tmp);
! }
}
Py_INCREF(Py_None);
More information about the Python-checkins
mailing list