Skip to content

Commit 00c029a

Browse files
committed
Revert "bpo-40521: Make the empty frozenset per interpreter (pythonGH-21068)"
This reverts commit 261cfed.
1 parent bc43f6e commit 00c029a

File tree

5 files changed

+13
-24
lines changed

5 files changed

+13
-24
lines changed

Include/internal/pycore_interp.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,6 @@ struct _is {
244244
/* Using a cache is very effective since typically only a single slice is
245245
created and then deleted again. */
246246
PySliceObject *slice_cache;
247-
// The empty frozenset is a singleton.
248-
PyObject *empty_frozenset;
249247

250248
struct _Py_tuple_state tuple;
251249
struct _Py_list_state list;

Include/internal/pycore_pylifecycle.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ extern void _PyFrame_Fini(PyThreadState *tstate);
6262
extern void _PyDict_Fini(PyThreadState *tstate);
6363
extern void _PyTuple_Fini(PyThreadState *tstate);
6464
extern void _PyList_Fini(PyThreadState *tstate);
65-
extern void _PySet_Fini(PyThreadState *tstate);
6665
extern void _PyBytes_Fini(PyThreadState *tstate);
6766
extern void _PyFloat_Fini(PyThreadState *tstate);
6867
extern void _PySlice_Fini(PyThreadState *tstate);

Misc/NEWS.d/next/Core and Builtins/2020-05-20-01-17-34.bpo-40521.wvAehI.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ Each interpreter now its has own free lists, singletons and caches:
22

33
* Free lists: float, tuple, list, dict, frame, context,
44
asynchronous generator.
5-
* Singletons: empty tuple, empty frozenset, empty bytes string,
5+
* Singletons: empty tuple, empty bytes string,
66
single byte character.
77
* Slice cache.
88

99
They are no longer shared by all interpreters.
10+

Objects/setobject.c

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -975,11 +975,12 @@ make_new_set_basetype(PyTypeObject *type, PyObject *iterable)
975975
return make_new_set(type, iterable);
976976
}
977977

978+
/* The empty frozenset is a singleton */
979+
static PyObject *emptyfrozenset = NULL;
980+
978981
static PyObject *
979982
make_new_frozenset(PyTypeObject *type, PyObject *iterable)
980983
{
981-
PyObject *res;
982-
983984
if (type != &PyFrozenSet_Type) {
984985
return make_new_set(type, iterable);
985986
}
@@ -990,7 +991,7 @@ make_new_frozenset(PyTypeObject *type, PyObject *iterable)
990991
Py_INCREF(iterable);
991992
return iterable;
992993
}
993-
res = make_new_set((PyTypeObject *)type, iterable);
994+
PyObject *res = make_new_set((PyTypeObject *)type, iterable);
994995
if (res == NULL || PySet_GET_SIZE(res) != 0) {
995996
return res;
996997
}
@@ -999,17 +1000,11 @@ make_new_frozenset(PyTypeObject *type, PyObject *iterable)
9991000
}
10001001

10011002
// The empty frozenset is a singleton
1002-
PyInterpreterState *interp = _PyInterpreterState_GET();
1003-
res = interp->empty_frozenset;
1004-
if (res == NULL) {
1005-
interp->empty_frozenset = make_new_set((PyTypeObject *)type, NULL);
1006-
res = interp->empty_frozenset;
1007-
if (res == NULL) {
1008-
return NULL;
1009-
}
1003+
if (emptyfrozenset == NULL) {
1004+
emptyfrozenset = make_new_set((PyTypeObject *)type, NULL);
10101005
}
1011-
Py_INCREF(res);
1012-
return res;
1006+
Py_XINCREF(emptyfrozenset);
1007+
return emptyfrozenset;
10131008
}
10141009

10151010
static PyObject *
@@ -2304,12 +2299,6 @@ PySet_Add(PyObject *anyset, PyObject *key)
23042299
return set_add_key((PySetObject *)anyset, key);
23052300
}
23062301

2307-
void
2308-
_PySet_Fini(PyThreadState *tstate)
2309-
{
2310-
Py_CLEAR(tstate->interp->empty_frozenset);
2311-
}
2312-
23132302
int
23142303
_PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, Py_hash_t *hash)
23152304
{

Python/pylifecycle.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,9 @@ finalize_interp_types(PyThreadState *tstate, int is_main_interp)
12531253
_PyAsyncGen_Fini(tstate);
12541254
_PyContext_Fini(tstate);
12551255

1256-
_PySet_Fini(tstate);
1256+
if (is_main_interp) {
1257+
_PySet_Fini();
1258+
}
12571259
_PyDict_Fini(tstate);
12581260
_PyList_Fini(tstate);
12591261
_PyTuple_Fini(tstate);

0 commit comments

Comments
 (0)