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.
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 @@
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 @@
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 */