Skip to content
Open
Prev Previous commit
Next Next commit
address requested changes
  • Loading branch information
NekoAsakura committed Apr 25, 2026
commit 35592b18dde0ae2aacba7778555b9b1896a223ae
1 change: 1 addition & 0 deletions Include/internal/pycore_interp_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,7 @@ struct _is {
struct ast_state ast;
struct types_state types;
struct callable_cache callable_cache;
PyObject *common_consts[NUM_COMMON_CONSTANTS];
bool jit;
bool compiling;

Expand Down
3 changes: 0 additions & 3 deletions Include/internal/pycore_opcode_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ extern "C" {
PyAPI_DATA(PyCFunctionObject) _PyBuiltin_All;
PyAPI_DATA(PyCFunctionObject) _PyBuiltin_Any;

/* Filled once by pycore_init_builtins; every entry is immortal. */
PyAPI_DATA(PyObject *) _PyCommonConsts[NUM_COMMON_CONSTANTS];

/* Non-static: used by static _PyBuiltin_All/_Any in bltinmodule.c. */
extern PyObject *_PyCFunction_vectorcall_O(
PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames);
Expand Down
2 changes: 1 addition & 1 deletion Modules/_testinternalcapi/test_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions Objects/methodobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,15 +394,7 @@ PyTypeObject PyCFunction_Type = {
meth_getsets, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
0, /* tp_free */
/* Static immortal instances have no PyGC_Head prefix. */
cfunction_is_gc, /* tp_is_gc */
.tp_is_gc = cfunction_is_gc,
};

PyTypeObject PyCMethod_Type = {
Expand Down
2 changes: 0 additions & 2 deletions Python/bltinmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,6 @@ PyCFunctionObject _PyBuiltin_Any = {
.vectorcall = _PyCFunction_vectorcall_O,
};

PyObject *_PyCommonConsts[NUM_COMMON_CONSTANTS];

/*[clinic input]
ascii as builtin_ascii

Expand Down
2 changes: 1 addition & 1 deletion Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1885,7 +1885,7 @@ dummy_func(

inst(LOAD_COMMON_CONSTANT, ( -- value)) {
assert(oparg < NUM_COMMON_CONSTANTS);
value = load_common_constant(oparg);
value = load_common_constant(tstate->interp, oparg);
}

inst(LOAD_BUILD_CLASS, ( -- bc)) {
Expand Down
14 changes: 3 additions & 11 deletions Python/ceval_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -630,17 +630,9 @@ gen_try_set_executing(PyGenObject *gen)
}

static inline _PyStackRef
load_common_constant(unsigned int oparg)
load_common_constant(PyInterpreterState *interp, unsigned int oparg)
{
switch (oparg) {
case CONSTANT_NONE:
return PyStackRef_None;
case CONSTANT_TRUE:
return PyStackRef_True;
case CONSTANT_FALSE:
return PyStackRef_False;
}
assert(oparg < NUM_COMMON_CONSTANTS);
assert(_Py_IsImmortal(_PyCommonConsts[oparg]));
return PyStackRef_FromPyObjectBorrow(_PyCommonConsts[oparg]);
assert(_Py_IsImmortal(interp->common_consts[oparg]));
return PyStackRef_FromPyObjectBorrow(interp->common_consts[oparg]);
}
6 changes: 3 additions & 3 deletions Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 3 additions & 28 deletions Python/flowgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "pycore_opcode_utils.h"
#include "pycore_opcode_metadata.h" // OPCODE_HAS_ARG, etc
#include "pycore_pystate.h" // _PyInterpreterState_GET()

#include <stdbool.h>

Expand Down Expand Up @@ -1319,34 +1320,8 @@ get_const_value(int opcode, int oparg, PyObject *co_consts)
return PyLong_FromLong(oparg);
}
if (opcode == LOAD_COMMON_CONSTANT) {
switch (oparg) {
case CONSTANT_ASSERTIONERROR:
return Py_NewRef(PyExc_AssertionError);
case CONSTANT_NOTIMPLEMENTEDERROR:
return Py_NewRef(PyExc_NotImplementedError);
case CONSTANT_BUILTIN_TUPLE:
return Py_NewRef((PyObject *)&PyTuple_Type);
case CONSTANT_BUILTIN_ALL:
return Py_NewRef((PyObject *)&_PyBuiltin_All);
case CONSTANT_BUILTIN_ANY:
return Py_NewRef((PyObject *)&_PyBuiltin_Any);
case CONSTANT_BUILTIN_LIST:
return Py_NewRef((PyObject *)&PyList_Type);
case CONSTANT_BUILTIN_SET:
return Py_NewRef((PyObject *)&PySet_Type);
case CONSTANT_NONE:
return Py_NewRef(Py_None);
case CONSTANT_EMPTY_STR:
return Py_NewRef(Py_GetConstantBorrowed(Py_CONSTANT_EMPTY_STR));
case CONSTANT_TRUE:
return Py_NewRef(Py_True);
case CONSTANT_FALSE:
return Py_NewRef(Py_False);
case CONSTANT_MINUS_ONE:
return PyLong_FromLong(-1);
default:
Py_UNREACHABLE();
}
assert(oparg < NUM_COMMON_CONSTANTS);
return _PyInterpreterState_GET()->common_consts[oparg];
}

if (constant == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 2 additions & 38 deletions Python/optimizer_bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,44 +874,8 @@ dummy_func(void) {

op(_LOAD_COMMON_CONSTANT, (-- value)) {
assert(oparg < NUM_COMMON_CONSTANTS);
PyObject *val;
if (oparg == CONSTANT_ASSERTIONERROR) {
val = PyExc_AssertionError;
}
else if (oparg == CONSTANT_NOTIMPLEMENTEDERROR) {
val = PyExc_NotImplementedError;
}
else if (oparg == CONSTANT_BUILTIN_TUPLE) {
val = (PyObject *)&PyTuple_Type;
}
else if (oparg == CONSTANT_BUILTIN_ALL) {
val = (PyObject *)&_PyBuiltin_All;
}
else if (oparg == CONSTANT_BUILTIN_ANY) {
val = (PyObject *)&_PyBuiltin_Any;
}
else if (oparg == CONSTANT_BUILTIN_LIST) {
val = (PyObject *)&PyList_Type;
}
else if (oparg == CONSTANT_BUILTIN_SET) {
val = (PyObject *)&PySet_Type;
}
else if (oparg == CONSTANT_NONE) {
val = Py_None;
}
else if (oparg == CONSTANT_EMPTY_STR) {
val = Py_GetConstantBorrowed(Py_CONSTANT_EMPTY_STR);
}
else if (oparg == CONSTANT_TRUE) {
val = Py_True;
}
else if (oparg == CONSTANT_FALSE) {
val = Py_False;
}
else {
assert(oparg == CONSTANT_MINUS_ONE);
val = (PyObject *)&_PyLong_SMALL_INTS[_PY_NSMALLNEGINTS - 1];
}
PyObject *val = _PyInterpreterState_GET()->common_consts[oparg];
assert(_Py_IsImmortal(val));
ADD_OP(_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)val);
value = PyJitRef_Borrow(sym_new_const(ctx, val));
}
Expand Down
40 changes: 2 additions & 38 deletions Python/optimizer_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,23 +878,23 @@ pycore_init_builtins(PyThreadState *tstate)
goto error;
}

_PyCommonConsts[CONSTANT_ASSERTIONERROR] = PyExc_AssertionError;
_PyCommonConsts[CONSTANT_NOTIMPLEMENTEDERROR] = PyExc_NotImplementedError;
_PyCommonConsts[CONSTANT_BUILTIN_TUPLE] = (PyObject *)&PyTuple_Type;
_PyCommonConsts[CONSTANT_BUILTIN_ALL] = (PyObject *)&_PyBuiltin_All;
_PyCommonConsts[CONSTANT_BUILTIN_ANY] = (PyObject *)&_PyBuiltin_Any;
_PyCommonConsts[CONSTANT_BUILTIN_LIST] = (PyObject *)&PyList_Type;
_PyCommonConsts[CONSTANT_BUILTIN_SET] = (PyObject *)&PySet_Type;
_PyCommonConsts[CONSTANT_NONE] = Py_None;
_PyCommonConsts[CONSTANT_EMPTY_STR] =
interp->common_consts[CONSTANT_ASSERTIONERROR] = PyExc_AssertionError;
interp->common_consts[CONSTANT_NOTIMPLEMENTEDERROR] = PyExc_NotImplementedError;
interp->common_consts[CONSTANT_BUILTIN_TUPLE] = (PyObject *)&PyTuple_Type;
interp->common_consts[CONSTANT_BUILTIN_ALL] = (PyObject *)&_PyBuiltin_All;
interp->common_consts[CONSTANT_BUILTIN_ANY] = (PyObject *)&_PyBuiltin_Any;
interp->common_consts[CONSTANT_BUILTIN_LIST] = (PyObject *)&PyList_Type;
interp->common_consts[CONSTANT_BUILTIN_SET] = (PyObject *)&PySet_Type;
interp->common_consts[CONSTANT_NONE] = Py_None;
interp->common_consts[CONSTANT_EMPTY_STR] =
Py_GetConstantBorrowed(Py_CONSTANT_EMPTY_STR);
_PyCommonConsts[CONSTANT_TRUE] = Py_True;
_PyCommonConsts[CONSTANT_FALSE] = Py_False;
_PyCommonConsts[CONSTANT_MINUS_ONE] =
interp->common_consts[CONSTANT_TRUE] = Py_True;
interp->common_consts[CONSTANT_FALSE] = Py_False;
interp->common_consts[CONSTANT_MINUS_ONE] =
(PyObject *)&_PyLong_SMALL_INTS[_PY_NSMALLNEGINTS - 1];
for (int i = 0; i < NUM_COMMON_CONSTANTS; i++) {
assert(_PyCommonConsts[i] != NULL);
assert(_Py_IsImmortal(_PyCommonConsts[i]));
assert(interp->common_consts[i] != NULL);
assert(_Py_IsStaticImmortal(interp->common_consts[i]));
}

PyObject *list_append = _PyType_Lookup(&PyList_Type, &_Py_ID(append));
Expand Down
3 changes: 0 additions & 3 deletions Tools/c-analyzer/cpython/globals-to-fix.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ Objects/weakrefobject.c - _PyWeakref_RefType -
Python/bltinmodule.c - PyFilter_Type -
Python/bltinmodule.c - PyMap_Type -
Python/bltinmodule.c - PyZip_Type -
Python/bltinmodule.c - _PyBuiltin_All -
Python/bltinmodule.c - _PyBuiltin_Any -
Python/bltinmodule.c - _PyCommonConsts -
Python/context.c - PyContextToken_Type -
Python/context.c - PyContextVar_Type -
Python/context.c - PyContext_Type -
Expand Down
3 changes: 3 additions & 0 deletions Tools/c-analyzer/cpython/ignored.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ Modules/getbuildinfo.c - buildinfo -
Modules/getbuildinfo.c - initialized -
Python/getversion.c - initialized -
Python/getversion.c - version -
## builtin singletons
Python/bltinmodule.c - _PyBuiltin_All -
Python/bltinmodule.c - _PyBuiltin_Any -

## public C-API - set during first init
Python/bootstrap_hash.c - _Py_HashSecret_Initialized -
Expand Down
Loading