bpo-40521: Disable free lists in subinterpreters (GH-19937)
When Python is built with experimental isolated interpreters, disable
tuple, dict and free free lists.
Temporary workaround until these caches are made per-interpreter.
Add frame_alloc() and frame_get_builtins() subfunctions to simplify
_PyFrame_New_NoTrack().
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c
index f8648d2..c0b59c0 100644
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -22,6 +22,12 @@
#define PyTuple_MAXFREELIST 2000 /* Maximum number of tuples of each size to save */
#endif
+/* bpo-40521: tuple free lists are shared by all interpreters. */
+#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
+# undef PyTuple_MAXSAVESIZE
+# define PyTuple_MAXSAVESIZE 0
+#endif
+
#if PyTuple_MAXSAVESIZE > 0
/* Entries 1 up to PyTuple_MAXSAVESIZE are free lists, entry 0 is the empty
tuple () of which at most one instance will be allocated.
@@ -248,7 +254,9 @@
#endif
}
Py_TYPE(op)->tp_free((PyObject *)op);
+#if PyTuple_MAXSAVESIZE > 0
done:
+#endif
Py_TRASHCAN_END
}