Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Do not call PyType_Ready() unnecessarily.
  • Loading branch information
ericsnowcurrently committed Apr 27, 2023
commit 447f89aaf73814853100595d6162f59aabe9f16b
5 changes: 0 additions & 5 deletions Include/internal/pycore_bytesobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ extern "C" {
#endif


/* runtime lifecycle */

extern PyStatus _PyBytes_InitTypes(PyInterpreterState *);


/* Substring Search.

Returns the index of the first occurrence of
Expand Down
1 change: 0 additions & 1 deletion Include/internal/pycore_tuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ extern "C" {
/* runtime lifecycle */

extern PyStatus _PyTuple_InitGlobalObjects(PyInterpreterState *);
extern PyStatus _PyTuple_InitTypes(PyInterpreterState *);
extern void _PyTuple_Fini(PyInterpreterState *);


Expand Down
7 changes: 0 additions & 7 deletions Modules/symtablemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ static PyMethodDef symtable_methods[] = {
{NULL, NULL} /* sentinel */
};

static int
symtable_init_stentry_type(PyObject *m)
{
return PyType_Ready(&PySTEntry_Type);
}

static int
symtable_init_constants(PyObject *m)
{
Expand Down Expand Up @@ -105,7 +99,6 @@ symtable_init_constants(PyObject *m)
}

static PyModuleDef_Slot symtable_slots[] = {
{Py_mod_exec, symtable_init_stentry_type},
{Py_mod_exec, symtable_init_constants},
{0, NULL}
};
Expand Down
19 changes: 0 additions & 19 deletions Objects/bytesobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3090,25 +3090,6 @@ _Py_COMP_DIAG_POP
}


PyStatus
_PyBytes_InitTypes(PyInterpreterState *interp)
{
if (!_Py_IsMainInterpreter(interp)) {
return _PyStatus_OK();
}

if (PyType_Ready(&PyBytes_Type) < 0) {
return _PyStatus_ERR("Can't initialize bytes type");
}

if (PyType_Ready(&PyBytesIter_Type) < 0) {
return _PyStatus_ERR("Can't initialize bytes iterator type");
}

return _PyStatus_OK();
}


/*********************** Bytes Iterator ****************************/

typedef struct {
Expand Down
4 changes: 0 additions & 4 deletions Objects/floatobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1990,10 +1990,6 @@ _PyFloat_InitState(PyInterpreterState *interp)
PyStatus
_PyFloat_InitTypes(PyInterpreterState *interp)
{
if (PyType_Ready(&PyFloat_Type) < 0) {
return _PyStatus_ERR("Can't initialize float type");
}

/* Init float info */
if (_PyStructSequence_InitBuiltin(&FloatInfoType,
&floatinfo_desc) < 0) {
Expand Down
4 changes: 0 additions & 4 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -6351,10 +6351,6 @@ PyLong_GetInfo(void)
PyStatus
_PyLong_InitTypes(PyInterpreterState *interp)
{
if (PyType_Ready(&PyLong_Type) < 0) {
return _PyStatus_ERR("Can't initialize int type");
}

/* initialize int_info */
if (_PyStructSequence_InitBuiltin(&Int_InfoType, &int_info_desc) < 0) {
return _PyStatus_ERR("can't init int info type");
Expand Down
18 changes: 0 additions & 18 deletions Objects/tupleobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -960,24 +960,6 @@ _PyTuple_Resize(PyObject **pv, Py_ssize_t newsize)
}


PyStatus
_PyTuple_InitTypes(PyInterpreterState *interp)
{
if (!_Py_IsMainInterpreter(interp)) {
return _PyStatus_OK();
}

if (PyType_Ready(&PyTuple_Type) < 0) {
return _PyStatus_ERR("Can't initialize tuple type");
}

if (PyType_Ready(&PyTupleIter_Type) < 0) {
return _PyStatus_ERR("Can't initialize tuple iterator type");
}

return _PyStatus_OK();
}

static void maybe_freelist_clear(PyInterpreterState *, int);

void
Expand Down
3 changes: 2 additions & 1 deletion Python/modsupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
12 changes: 0 additions & 12 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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"
Expand Down Expand Up @@ -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;
Expand All @@ -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");
}
Expand Down