[Python-checkins] r60312 - in python/trunk: Doc/c-api/set.rst Objects/setobject.c Python/marshal.c
raymond.hettinger
python-checkins at python.org
Sat Jan 26 10:31:11 CET 2008
Author: raymond.hettinger
Date: Sat Jan 26 10:31:11 2008
New Revision: 60312
Modified:
python/trunk/Doc/c-api/set.rst
python/trunk/Objects/setobject.c
python/trunk/Python/marshal.c
Log:
Revert PySet_Add() changes.
Modified: python/trunk/Doc/c-api/set.rst
==============================================================================
--- python/trunk/Doc/c-api/set.rst (original)
+++ python/trunk/Doc/c-api/set.rst Sat Jan 26 10:31:11 2008
@@ -112,6 +112,9 @@
the *key* is unhashable. Raise :exc:`PyExc_SystemError` if *anyset* is not a
:class:`set`, :class:`frozenset`, or an instance of a subtype.
+The following functions are available for instances of :class:`set` or its
+subtypes but not for instances of :class:`frozenset` or its subtypes.
+
.. cfunction:: int PySet_Add(PyObject *set, PyObject *key)
@@ -121,14 +124,6 @@
Raise a :exc:`SystemError` if *set* is an not an instance of :class:`set` or its
subtype.
- .. versionchanged:: 2.6
- Now works with instances of :class:`frozenset` or its subtypes.
- Like :cfunc:`PyTuple_SetItem` in that it can be used to fill-in the
- values of brand new frozensets before they are exposed to other code.
-
-The following functions are available for instances of :class:`set` or its
-subtypes but not for instances of :class:`frozenset` or its subtypes.
-
.. cfunction:: int PySet_Discard(PyObject *set, PyObject *key)
Modified: python/trunk/Objects/setobject.c
==============================================================================
--- python/trunk/Objects/setobject.c (original)
+++ python/trunk/Objects/setobject.c Sat Jan 26 10:31:11 2008
@@ -2198,6 +2198,10 @@
int
PySet_Add(PyObject *set, PyObject *key)
{
+ if (!PyType_IsSubtype(Py_TYPE(set), &PySet_Type)) {
+ PyErr_BadInternalCall();
+ return -1;
+ }
return set_add_key((PySetObject *)set, key);
}
@@ -2341,6 +2345,7 @@
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);
Modified: python/trunk/Python/marshal.c
==============================================================================
--- python/trunk/Python/marshal.c (original)
+++ python/trunk/Python/marshal.c Sat Jan 26 10:31:11 2008
@@ -860,7 +860,7 @@
retval = NULL;
break;
}
- v = (type == TYPE_SET) ? PySet_New(NULL) : PyFrozenSet_New(NULL);
+ v = PyTuple_New((int)n);
if (v == NULL) {
retval = NULL;
break;
@@ -875,14 +875,18 @@
v = NULL;
break;
}
- if (PySet_Add(v, v2) == -1) {
- Py_DECREF(v);
- Py_DECREF(v2);
- v = NULL;
- break;
- }
+ PyTuple_SET_ITEM(v, (int)i, v2);
}
- retval = (v == NULL) ? NULL : v;
+ if (v == NULL) {
+ retval = NULL;
+ break;
+ }
+ if (type == TYPE_SET)
+ v3 = PySet_New(v);
+ else
+ v3 = PyFrozenSet_New(v);
+ Py_DECREF(v);
+ retval = v3;
break;
case TYPE_CODE:
More information about the Python-checkins
mailing list