diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2020-06-23 15:42:55 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-23 15:42:55 (GMT) |
commit | f9bd05e83e32bece49de5af0c9a232325c57648a (patch) | |
tree | f332a6f5041e64595b8569ca34ae6eb598c8e951 /Objects | |
parent | 522691c46e2ae51faaad5bbbce7d959dd61770df (diff) | |
download | cpython-f9bd05e83e32bece49de5af0c9a232325c57648a.zip cpython-f9bd05e83e32bece49de5af0c9a232325c57648a.tar.gz cpython-f9bd05e83e32bece49de5af0c9a232325c57648a.tar.bz2 |
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 261cfedf7657a515e04428bba58eba2a9bb88208.
* bpo-40521: Empty frozensets are no longer singletons
* Complete the removal of the frozenset singleton
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/setobject.c | 38 |
1 files changed, 5 insertions, 33 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c index 69bfc7d..b271149 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -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) { |