From 0430dfac629b4eb0e899a09b899a494aa92145f6 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 24 Jun 2020 15:21:54 +0200 Subject: bpo-40521: Always create the empty tuple singleton (GH-21116) Py_InitializeFromConfig() now always creates the empty tuple singleton as soon as possible. Optimize PyTuple_New(0): it no longer has to check if the empty tuple was created or not, it is always creatd. * Add tuple_create_empty_tuple_singleton() function. * Add tuple_get_empty() function. * Remove state parameter of tuple_alloc(). --- Python/pylifecycle.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'Python/pylifecycle.c') diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index eda4c6ad7e..4b658f847b 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -583,6 +583,14 @@ pycore_init_types(PyThreadState *tstate) return status; } + // Create the empty tuple singleton. It must be created before the first + // PyType_Ready() call since PyType_Ready() creates tuples, for tp_bases + // for example. + status = _PyTuple_Init(tstate); + if (_PyStatus_EXCEPTION(status)) { + return status; + } + if (is_main_interp) { status = _PyTypes_Init(); if (_PyStatus_EXCEPTION(status)) { @@ -590,7 +598,6 @@ pycore_init_types(PyThreadState *tstate) } } - if (!_PyLong_Init(tstate)) { return _PyStatus_ERR("can't init longs"); } -- cgit v1.2.1