summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2023-04-27 22:19:43 (GMT)
committerGitHub <noreply@github.com>2023-04-27 22:19:43 (GMT)
commitd2e2e53f733f8c8098035bbbc452bd1892796cb3 (patch)
tree4f01c11ff1f6ad9ebbcd4786bca991878226a4c6 /Python
parent56c7176d1de3a0770085cad3865c1de42ba86f42 (diff)
downloadcpython-d2e2e53f733f8c8098035bbbc452bd1892796cb3.zip
cpython-d2e2e53f733f8c8098035bbbc452bd1892796cb3.tar.gz
cpython-d2e2e53f733f8c8098035bbbc452bd1892796cb3.tar.bz2
gh-94673: Ensure Builtin Static Types are Readied Properly (gh-103940)
There were cases where we do unnecessary work for builtin static types. This also simplifies some work necessary for a per-interpreter GIL.
Diffstat (limited to 'Python')
-rw-r--r--Python/bltinmodule.c2
-rw-r--r--Python/errors.c12
-rw-r--r--Python/modsupport.c3
-rw-r--r--Python/pylifecycle.c12
-rw-r--r--Python/sysmodule.c22
-rw-r--r--Python/thread.c6
6 files changed, 16 insertions, 41 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index fcb4d7a..8840bba 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -2316,7 +2316,7 @@ builtin_round_impl(PyObject *module, PyObject *number, PyObject *ndigits)
{
PyObject *round, *result;
- if (Py_TYPE(number)->tp_dict == NULL) {
+ if (!_PyType_IsReady(Py_TYPE(number))) {
if (PyType_Ready(Py_TYPE(number)) < 0)
return NULL;
}
diff --git a/Python/errors.c b/Python/errors.c
index 0ff6a0d..7fc2673 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -1342,15 +1342,9 @@ static PyStructSequence_Desc UnraisableHookArgs_desc = {
PyStatus
_PyErr_InitTypes(PyInterpreterState *interp)
{
- if (!_Py_IsMainInterpreter(interp)) {
- return _PyStatus_OK();
- }
-
- if (UnraisableHookArgsType.tp_name == NULL) {
- if (_PyStructSequence_InitBuiltin(&UnraisableHookArgsType,
- &UnraisableHookArgs_desc) < 0) {
- return _PyStatus_ERR("failed to initialize UnraisableHookArgs type");
- }
+ if (_PyStructSequence_InitBuiltin(&UnraisableHookArgsType,
+ &UnraisableHookArgs_desc) < 0) {
+ return _PyStatus_ERR("failed to initialize UnraisableHookArgs type");
}
return _PyStatus_OK();
}
diff --git a/Python/modsupport.c b/Python/modsupport.c
index 7569845..be229c9 100644
--- a/Python/modsupport.c
+++ b/Python/modsupport.c
@@ -3,6 +3,7 @@
#include "Python.h"
#include "pycore_abstract.h" // _PyIndex_Check()
+#include "pycore_object.h" // _PyType_IsReady()
#define FLAG_SIZE_T 1
typedef double va_double;
@@ -693,7 +694,7 @@ PyModule_AddStringConstant(PyObject *m, const char *name, const char *value)
int
PyModule_AddType(PyObject *module, PyTypeObject *type)
{
- if (PyType_Ready(type) < 0) {
+ if (!_PyType_IsReady(type) && PyType_Ready(type) < 0) {
return -1;
}
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index ebf1a0b..d525fb1 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -2,7 +2,6 @@
#include "Python.h"
-#include "pycore_bytesobject.h" // _PyBytes_InitTypes()
#include "pycore_ceval.h" // _PyEval_FiniGIL()
#include "pycore_context.h" // _PyContext_Init()
#include "pycore_exceptions.h" // _PyExc_InitTypes()
@@ -26,7 +25,6 @@
#include "pycore_sliceobject.h" // _PySlice_Fini()
#include "pycore_sysmodule.h" // _PySys_ClearAuditHooks()
#include "pycore_traceback.h" // _Py_DumpTracebackThreads()
-#include "pycore_tuple.h" // _PyTuple_InitTypes()
#include "pycore_typeobject.h" // _PyTypes_InitTypes()
#include "pycore_unicodeobject.h" // _PyUnicode_InitTypes()
#include "opcode.h"
@@ -684,11 +682,6 @@ pycore_init_types(PyInterpreterState *interp)
return status;
}
- status = _PyBytes_InitTypes(interp);
- if (_PyStatus_EXCEPTION(status)) {
- return status;
- }
-
status = _PyLong_InitTypes(interp);
if (_PyStatus_EXCEPTION(status)) {
return status;
@@ -704,11 +697,6 @@ pycore_init_types(PyInterpreterState *interp)
return status;
}
- status = _PyTuple_InitTypes(interp);
- if (_PyStatus_EXCEPTION(status)) {
- return status;
- }
-
if (_PyExc_InitTypes(interp) < 0) {
return _PyStatus_ERR("failed to initialize an exception type");
}
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 58ed488..d673e40 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -3166,10 +3166,8 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict)
SET_SYS("float_info", PyFloat_GetInfo());
SET_SYS("int_info", PyLong_GetInfo());
/* initialize hash_info */
- if (Hash_InfoType.tp_name == NULL) {
- if (_PyStructSequence_InitBuiltin(&Hash_InfoType, &hash_info_desc) < 0) {
- goto type_init_failed;
- }
+ if (_PyStructSequence_InitBuiltin(&Hash_InfoType, &hash_info_desc) < 0) {
+ goto type_init_failed;
}
SET_SYS("hash_info", get_hash_info(tstate));
SET_SYS("maxunicode", PyLong_FromLong(0x10FFFF));
@@ -3191,11 +3189,9 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict)
#define ENSURE_INFO_TYPE(TYPE, DESC) \
do { \
- if (TYPE.tp_name == NULL) { \
- if (_PyStructSequence_InitBuiltinWithFlags( \
- &TYPE, &DESC, Py_TPFLAGS_DISALLOW_INSTANTIATION) < 0) { \
- goto type_init_failed; \
- } \
+ if (_PyStructSequence_InitBuiltinWithFlags( \
+ &TYPE, &DESC, Py_TPFLAGS_DISALLOW_INSTANTIATION) < 0) { \
+ goto type_init_failed; \
} \
} while (0)
@@ -3230,11 +3226,9 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict)
SET_SYS("thread_info", PyThread_GetInfo());
/* initialize asyncgen_hooks */
- if (AsyncGenHooksType.tp_name == NULL) {
- if (_PyStructSequence_InitBuiltin(
- &AsyncGenHooksType, &asyncgen_hooks_desc) < 0) {
- goto type_init_failed;
- }
+ if (_PyStructSequence_InitBuiltin(
+ &AsyncGenHooksType, &asyncgen_hooks_desc) < 0) {
+ goto type_init_failed;
}
#ifdef __EMSCRIPTEN__
diff --git a/Python/thread.c b/Python/thread.c
index 4581f1a..7fdedb0 100644
--- a/Python/thread.c
+++ b/Python/thread.c
@@ -137,10 +137,8 @@ PyThread_GetInfo(void)
int len;
#endif
- if (ThreadInfoType.tp_name == 0) {
- if (_PyStructSequence_InitBuiltin(&ThreadInfoType,
- &threadinfo_desc) < 0)
- return NULL;
+ if (_PyStructSequence_InitBuiltin(&ThreadInfoType, &threadinfo_desc) < 0) {
+ return NULL;
}
threadinfo = PyStructSequence_New(&ThreadInfoType);