summaryrefslogtreecommitdiffstats
path: root/Objects/setobject.c
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-02-03 22:51:43 (GMT)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-02-03 22:51:43 (GMT)
commitcab3d98ca19659698a29108aabb040f2741d1a2a (patch)
tree5f44e6c9c4b24b5112690c81e8cef8707a334406 /Objects/setobject.c
parente6a8074892810f551d9b1c1f16ebde9ebe9cc09d (diff)
downloadcpython-cab3d98ca19659698a29108aabb040f2741d1a2a.zip
cpython-cab3d98ca19659698a29108aabb040f2741d1a2a.tar.gz
cpython-cab3d98ca19659698a29108aabb040f2741d1a2a.tar.bz2
Ensure that PySet_Add() operates on a newly created frozenset, like PyTuple_SetItem does.
Add PyFrozenSet_Check(), which was not needed before; The list of Py*Set_Check* macros seems to be complete now. Add missing NEWS entries about all this.
Diffstat (limited to 'Objects/setobject.c')
-rw-r--r--Objects/setobject.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c
index 4b4213a..53d284f 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -2188,7 +2188,8 @@ PySet_Discard(PyObject *set, PyObject *key)
int
PySet_Add(PyObject *anyset, PyObject *key)
{
- if (!PyAnySet_Check(anyset)) {
+ if (!PySet_Check(anyset) &&
+ (!PyFrozenSet_Check(anyset) || Py_REFCNT(anyset) != 1)) {
PyErr_BadInternalCall();
return -1;
}
@@ -2306,6 +2307,10 @@ test_c_api(PySetObject *so)
f = PyFrozenSet_New(dup);
assertRaises(PySet_Clear(f) == -1, PyExc_SystemError);
assertRaises(_PySet_Update(f, dup) == -1, PyExc_SystemError);
+ assert(PySet_Add(f, elem) == 0);
+ Py_INCREF(f);
+ assertRaises(PySet_Add(f, elem) == -1, PyExc_SystemError);
+ Py_DECREF(f);
Py_DECREF(f);
/* Exercise direct iteration */