Skip to content

Commit 0366111

Browse files
Do not call PyType_Ready() unnecessarily.
1 parent b590c91 commit 0366111

File tree

9 files changed

+2
-71
lines changed

9 files changed

+2
-71
lines changed

Include/internal/pycore_bytesobject.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ extern "C" {
99
#endif
1010

1111

12-
/* runtime lifecycle */
13-
14-
extern PyStatus _PyBytes_InitTypes(PyInterpreterState *);
15-
16-
1712
/* Substring Search.
1813
1914
Returns the index of the first occurrence of

Include/internal/pycore_tuple.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ extern "C" {
1414
/* runtime lifecycle */
1515

1616
extern PyStatus _PyTuple_InitGlobalObjects(PyInterpreterState *);
17-
extern PyStatus _PyTuple_InitTypes(PyInterpreterState *);
1817
extern void _PyTuple_Fini(PyInterpreterState *);
1918

2019

Modules/symtablemodule.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,6 @@ static PyMethodDef symtable_methods[] = {
6666
{NULL, NULL} /* sentinel */
6767
};
6868

69-
static int
70-
symtable_init_stentry_type(PyObject *m)
71-
{
72-
return PyType_Ready(&PySTEntry_Type);
73-
}
74-
7569
static int
7670
symtable_init_constants(PyObject *m)
7771
{
@@ -105,7 +99,6 @@ symtable_init_constants(PyObject *m)
10599
}
106100

107101
static PyModuleDef_Slot symtable_slots[] = {
108-
{Py_mod_exec, symtable_init_stentry_type},
109102
{Py_mod_exec, symtable_init_constants},
110103
{0, NULL}
111104
};

Objects/bytesobject.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3090,25 +3090,6 @@ _Py_COMP_DIAG_POP
30903090
}
30913091

30923092

3093-
PyStatus
3094-
_PyBytes_InitTypes(PyInterpreterState *interp)
3095-
{
3096-
if (!_Py_IsMainInterpreter(interp)) {
3097-
return _PyStatus_OK();
3098-
}
3099-
3100-
if (PyType_Ready(&PyBytes_Type) < 0) {
3101-
return _PyStatus_ERR("Can't initialize bytes type");
3102-
}
3103-
3104-
if (PyType_Ready(&PyBytesIter_Type) < 0) {
3105-
return _PyStatus_ERR("Can't initialize bytes iterator type");
3106-
}
3107-
3108-
return _PyStatus_OK();
3109-
}
3110-
3111-
31123093
/*********************** Bytes Iterator ****************************/
31133094

31143095
typedef struct {

Objects/floatobject.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,10 +1990,6 @@ _PyFloat_InitState(PyInterpreterState *interp)
19901990
PyStatus
19911991
_PyFloat_InitTypes(PyInterpreterState *interp)
19921992
{
1993-
if (PyType_Ready(&PyFloat_Type) < 0) {
1994-
return _PyStatus_ERR("Can't initialize float type");
1995-
}
1996-
19971993
/* Init float info */
19981994
if (_PyStructSequence_InitBuiltin(&FloatInfoType,
19991995
&floatinfo_desc) < 0) {

Objects/longobject.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6351,10 +6351,6 @@ PyLong_GetInfo(void)
63516351
PyStatus
63526352
_PyLong_InitTypes(PyInterpreterState *interp)
63536353
{
6354-
if (PyType_Ready(&PyLong_Type) < 0) {
6355-
return _PyStatus_ERR("Can't initialize int type");
6356-
}
6357-
63586354
/* initialize int_info */
63596355
if (_PyStructSequence_InitBuiltin(&Int_InfoType, &int_info_desc) < 0) {
63606356
return _PyStatus_ERR("can't init int info type");

Objects/tupleobject.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -960,24 +960,6 @@ _PyTuple_Resize(PyObject **pv, Py_ssize_t newsize)
960960
}
961961

962962

963-
PyStatus
964-
_PyTuple_InitTypes(PyInterpreterState *interp)
965-
{
966-
if (!_Py_IsMainInterpreter(interp)) {
967-
return _PyStatus_OK();
968-
}
969-
970-
if (PyType_Ready(&PyTuple_Type) < 0) {
971-
return _PyStatus_ERR("Can't initialize tuple type");
972-
}
973-
974-
if (PyType_Ready(&PyTupleIter_Type) < 0) {
975-
return _PyStatus_ERR("Can't initialize tuple iterator type");
976-
}
977-
978-
return _PyStatus_OK();
979-
}
980-
981963
static void maybe_freelist_clear(PyInterpreterState *, int);
982964

983965
void

Python/modsupport.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "Python.h"
55
#include "pycore_abstract.h" // _PyIndex_Check()
6+
#include "pycore_object.h" // _PyType_IsReady()
67

78
#define FLAG_SIZE_T 1
89
typedef double va_double;
@@ -693,7 +694,7 @@ PyModule_AddStringConstant(PyObject *m, const char *name, const char *value)
693694
int
694695
PyModule_AddType(PyObject *module, PyTypeObject *type)
695696
{
696-
if (PyType_Ready(type) < 0) {
697+
if (!_PyType_IsReady(type) && PyType_Ready(type) < 0) {
697698
return -1;
698699
}
699700

Python/pylifecycle.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include "Python.h"
44

5-
#include "pycore_bytesobject.h" // _PyBytes_InitTypes()
65
#include "pycore_ceval.h" // _PyEval_FiniGIL()
76
#include "pycore_context.h" // _PyContext_Init()
87
#include "pycore_exceptions.h" // _PyExc_InitTypes()
@@ -26,7 +25,6 @@
2625
#include "pycore_sliceobject.h" // _PySlice_Fini()
2726
#include "pycore_sysmodule.h" // _PySys_ClearAuditHooks()
2827
#include "pycore_traceback.h" // _Py_DumpTracebackThreads()
29-
#include "pycore_tuple.h" // _PyTuple_InitTypes()
3028
#include "pycore_typeobject.h" // _PyTypes_InitTypes()
3129
#include "pycore_unicodeobject.h" // _PyUnicode_InitTypes()
3230
#include "opcode.h"
@@ -684,11 +682,6 @@ pycore_init_types(PyInterpreterState *interp)
684682
return status;
685683
}
686684

687-
status = _PyBytes_InitTypes(interp);
688-
if (_PyStatus_EXCEPTION(status)) {
689-
return status;
690-
}
691-
692685
status = _PyLong_InitTypes(interp);
693686
if (_PyStatus_EXCEPTION(status)) {
694687
return status;
@@ -704,11 +697,6 @@ pycore_init_types(PyInterpreterState *interp)
704697
return status;
705698
}
706699

707-
status = _PyTuple_InitTypes(interp);
708-
if (_PyStatus_EXCEPTION(status)) {
709-
return status;
710-
}
711-
712700
if (_PyExc_InitTypes(interp) < 0) {
713701
return _PyStatus_ERR("failed to initialize an exception type");
714702
}

0 commit comments

Comments
 (0)