mirror of
https://github.com/python/cpython.git
synced 2025-11-03 03:22:27 +00:00
bpo-40521: Empty frozenset is no longer a singleton (GH-21085)
* Revert "bpo-40521: Make the empty frozenset per interpreter (GH-21068)"
This reverts commit 261cfedf76.
* bpo-40521: Empty frozensets are no longer singletons
* Complete the removal of the frozenset singleton
This commit is contained in:
parent
522691c46e
commit
f9bd05e83e
8 changed files with 8 additions and 54 deletions
|
|
@ -978,38 +978,16 @@ make_new_set_basetype(PyTypeObject *type, PyObject *iterable)
|
|||
static PyObject *
|
||||
make_new_frozenset(PyTypeObject *type, PyObject *iterable)
|
||||
{
|
||||
PyObject *res;
|
||||
|
||||
if (type != &PyFrozenSet_Type) {
|
||||
return make_new_set(type, iterable);
|
||||
}
|
||||
|
||||
if (iterable != NULL) {
|
||||
if (PyFrozenSet_CheckExact(iterable)) {
|
||||
/* frozenset(f) is idempotent */
|
||||
Py_INCREF(iterable);
|
||||
return iterable;
|
||||
}
|
||||
res = make_new_set((PyTypeObject *)type, iterable);
|
||||
if (res == NULL || PySet_GET_SIZE(res) != 0) {
|
||||
return res;
|
||||
}
|
||||
/* If the created frozenset is empty, return the empty frozenset singleton instead */
|
||||
Py_DECREF(res);
|
||||
if (iterable != NULL && PyFrozenSet_CheckExact(iterable)) {
|
||||
/* frozenset(f) is idempotent */
|
||||
Py_INCREF(iterable);
|
||||
return iterable;
|
||||
}
|
||||
|
||||
// The empty frozenset is a singleton
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
res = interp->empty_frozenset;
|
||||
if (res == NULL) {
|
||||
interp->empty_frozenset = make_new_set((PyTypeObject *)type, NULL);
|
||||
res = interp->empty_frozenset;
|
||||
if (res == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
Py_INCREF(res);
|
||||
return res;
|
||||
return make_new_set((PyTypeObject *)type, iterable);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
|
@ -2304,12 +2282,6 @@ PySet_Add(PyObject *anyset, PyObject *key)
|
|||
return set_add_key((PySetObject *)anyset, key);
|
||||
}
|
||||
|
||||
void
|
||||
_PySet_Fini(PyThreadState *tstate)
|
||||
{
|
||||
Py_CLEAR(tstate->interp->empty_frozenset);
|
||||
}
|
||||
|
||||
int
|
||||
_PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, Py_hash_t *hash)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue