gh-123091: Use _Py_IsImmortalLoose() (#123511)

Use _Py_IsImmortalLoose() in bytesobject.c, typeobject.c
and ceval.c.
This commit is contained in:
Victor Stinner 2024-09-02 14:25:19 +02:00 committed by GitHub
parent 22fdb8cf89
commit f1a0d96f41
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 17 additions and 17 deletions

View File

@ -1208,10 +1208,10 @@ const struct opcode_metadata _PyOpcode_opcode_metadata[264] = {
[TO_BOOL] = { true, INSTR_FMT_IXC00, HAS_ERROR_FLAG | HAS_ESCAPES_FLAG }, [TO_BOOL] = { true, INSTR_FMT_IXC00, HAS_ERROR_FLAG | HAS_ESCAPES_FLAG },
[TO_BOOL_ALWAYS_TRUE] = { true, INSTR_FMT_IXC00, HAS_EXIT_FLAG }, [TO_BOOL_ALWAYS_TRUE] = { true, INSTR_FMT_IXC00, HAS_EXIT_FLAG },
[TO_BOOL_BOOL] = { true, INSTR_FMT_IXC00, HAS_EXIT_FLAG }, [TO_BOOL_BOOL] = { true, INSTR_FMT_IXC00, HAS_EXIT_FLAG },
[TO_BOOL_INT] = { true, INSTR_FMT_IXC00, HAS_EXIT_FLAG }, [TO_BOOL_INT] = { true, INSTR_FMT_IXC00, HAS_EXIT_FLAG | HAS_ESCAPES_FLAG },
[TO_BOOL_LIST] = { true, INSTR_FMT_IXC00, HAS_EXIT_FLAG }, [TO_BOOL_LIST] = { true, INSTR_FMT_IXC00, HAS_EXIT_FLAG },
[TO_BOOL_NONE] = { true, INSTR_FMT_IXC00, HAS_EXIT_FLAG }, [TO_BOOL_NONE] = { true, INSTR_FMT_IXC00, HAS_EXIT_FLAG },
[TO_BOOL_STR] = { true, INSTR_FMT_IXC00, HAS_EXIT_FLAG }, [TO_BOOL_STR] = { true, INSTR_FMT_IXC00, HAS_EXIT_FLAG | HAS_ESCAPES_FLAG },
[UNARY_INVERT] = { true, INSTR_FMT_IX, HAS_ERROR_FLAG | HAS_ESCAPES_FLAG }, [UNARY_INVERT] = { true, INSTR_FMT_IX, HAS_ERROR_FLAG | HAS_ESCAPES_FLAG },
[UNARY_NEGATIVE] = { true, INSTR_FMT_IX, HAS_ERROR_FLAG | HAS_ESCAPES_FLAG }, [UNARY_NEGATIVE] = { true, INSTR_FMT_IX, HAS_ERROR_FLAG | HAS_ESCAPES_FLAG },
[UNARY_NOT] = { true, INSTR_FMT_IX, HAS_PURE_FLAG }, [UNARY_NOT] = { true, INSTR_FMT_IX, HAS_PURE_FLAG },

View File

@ -54,10 +54,10 @@ const uint16_t _PyUop_Flags[MAX_UOP_ID+1] = {
[_UNARY_NOT] = HAS_PURE_FLAG, [_UNARY_NOT] = HAS_PURE_FLAG,
[_TO_BOOL] = HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, [_TO_BOOL] = HAS_ERROR_FLAG | HAS_ESCAPES_FLAG,
[_TO_BOOL_BOOL] = HAS_EXIT_FLAG, [_TO_BOOL_BOOL] = HAS_EXIT_FLAG,
[_TO_BOOL_INT] = HAS_EXIT_FLAG, [_TO_BOOL_INT] = HAS_EXIT_FLAG | HAS_ESCAPES_FLAG,
[_TO_BOOL_LIST] = HAS_EXIT_FLAG, [_TO_BOOL_LIST] = HAS_EXIT_FLAG,
[_TO_BOOL_NONE] = HAS_EXIT_FLAG, [_TO_BOOL_NONE] = HAS_EXIT_FLAG,
[_TO_BOOL_STR] = HAS_EXIT_FLAG, [_TO_BOOL_STR] = HAS_EXIT_FLAG | HAS_ESCAPES_FLAG,
[_REPLACE_WITH_TRUE] = 0, [_REPLACE_WITH_TRUE] = 0,
[_UNARY_INVERT] = HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, [_UNARY_INVERT] = HAS_ERROR_FLAG | HAS_ESCAPES_FLAG,
[_GUARD_BOTH_INT] = HAS_EXIT_FLAG, [_GUARD_BOTH_INT] = HAS_EXIT_FLAG,

View File

@ -46,7 +46,7 @@ Py_LOCAL_INLINE(Py_ssize_t) _PyBytesWriter_GetSize(_PyBytesWriter *writer,
static inline PyObject* bytes_get_empty(void) static inline PyObject* bytes_get_empty(void)
{ {
PyObject *empty = &EMPTY->ob_base.ob_base; PyObject *empty = &EMPTY->ob_base.ob_base;
assert(_Py_IsImmortal(empty)); assert(_Py_IsImmortalLoose(empty));
return empty; return empty;
} }
@ -119,7 +119,7 @@ PyBytes_FromStringAndSize(const char *str, Py_ssize_t size)
} }
if (size == 1 && str != NULL) { if (size == 1 && str != NULL) {
op = CHARACTER(*str & 255); op = CHARACTER(*str & 255);
assert(_Py_IsImmortal(op)); assert(_Py_IsImmortalLoose(op));
return (PyObject *)op; return (PyObject *)op;
} }
if (size == 0) { if (size == 0) {
@ -155,7 +155,7 @@ PyBytes_FromString(const char *str)
} }
else if (size == 1) { else if (size == 1) {
op = CHARACTER(*str & 255); op = CHARACTER(*str & 255);
assert(_Py_IsImmortal(op)); assert(_Py_IsImmortalLoose(op));
return (PyObject *)op; return (PyObject *)op;
} }

View File

@ -485,7 +485,7 @@ set_tp_bases(PyTypeObject *self, PyObject *bases, int initial)
assert(PyTuple_GET_SIZE(bases) == 1); assert(PyTuple_GET_SIZE(bases) == 1);
assert(PyTuple_GET_ITEM(bases, 0) == (PyObject *)self->tp_base); assert(PyTuple_GET_ITEM(bases, 0) == (PyObject *)self->tp_base);
assert(self->tp_base->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN); assert(self->tp_base->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN);
assert(_Py_IsImmortal(self->tp_base)); assert(_Py_IsImmortalLoose(self->tp_base));
} }
_Py_SetImmortal(bases); _Py_SetImmortal(bases);
} }
@ -502,7 +502,7 @@ clear_tp_bases(PyTypeObject *self, int final)
Py_CLEAR(self->tp_bases); Py_CLEAR(self->tp_bases);
} }
else { else {
assert(_Py_IsImmortal(self->tp_bases)); assert(_Py_IsImmortalLoose(self->tp_bases));
_Py_ClearImmortal(self->tp_bases); _Py_ClearImmortal(self->tp_bases);
} }
} }
@ -567,7 +567,7 @@ clear_tp_mro(PyTypeObject *self, int final)
Py_CLEAR(self->tp_mro); Py_CLEAR(self->tp_mro);
} }
else { else {
assert(_Py_IsImmortal(self->tp_mro)); assert(_Py_IsImmortalLoose(self->tp_mro));
_Py_ClearImmortal(self->tp_mro); _Py_ClearImmortal(self->tp_mro);
} }
} }
@ -5869,7 +5869,7 @@ fini_static_type(PyInterpreterState *interp, PyTypeObject *type,
int isbuiltin, int final) int isbuiltin, int final)
{ {
assert(type->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN); assert(type->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN);
assert(_Py_IsImmortal((PyObject *)type)); assert(_Py_IsImmortalLoose((PyObject *)type));
type_dealloc_common(type); type_dealloc_common(type);

View File

@ -374,7 +374,7 @@ dummy_func(
EXIT_IF(!PyLong_CheckExact(value_o)); EXIT_IF(!PyLong_CheckExact(value_o));
STAT_INC(TO_BOOL, hit); STAT_INC(TO_BOOL, hit);
if (_PyLong_IsZero((PyLongObject *)value_o)) { if (_PyLong_IsZero((PyLongObject *)value_o)) {
assert(_Py_IsImmortal(value_o)); assert(_Py_IsImmortalLoose(value_o));
res = PyStackRef_False; res = PyStackRef_False;
} }
else { else {
@ -403,7 +403,7 @@ dummy_func(
EXIT_IF(!PyUnicode_CheckExact(value_o)); EXIT_IF(!PyUnicode_CheckExact(value_o));
STAT_INC(TO_BOOL, hit); STAT_INC(TO_BOOL, hit);
if (value_o == &_Py_STR(empty)) { if (value_o == &_Py_STR(empty)) {
assert(_Py_IsImmortal(value_o)); assert(_Py_IsImmortalLoose(value_o));
res = PyStackRef_False; res = PyStackRef_False;
} }
else { else {

View File

@ -390,7 +390,7 @@
} }
STAT_INC(TO_BOOL, hit); STAT_INC(TO_BOOL, hit);
if (_PyLong_IsZero((PyLongObject *)value_o)) { if (_PyLong_IsZero((PyLongObject *)value_o)) {
assert(_Py_IsImmortal(value_o)); assert(_Py_IsImmortalLoose(value_o));
res = PyStackRef_False; res = PyStackRef_False;
} }
else { else {
@ -443,7 +443,7 @@
} }
STAT_INC(TO_BOOL, hit); STAT_INC(TO_BOOL, hit);
if (value_o == &_Py_STR(empty)) { if (value_o == &_Py_STR(empty)) {
assert(_Py_IsImmortal(value_o)); assert(_Py_IsImmortalLoose(value_o));
res = PyStackRef_False; res = PyStackRef_False;
} }
else { else {

View File

@ -7330,7 +7330,7 @@
DEOPT_IF(!PyLong_CheckExact(value_o), TO_BOOL); DEOPT_IF(!PyLong_CheckExact(value_o), TO_BOOL);
STAT_INC(TO_BOOL, hit); STAT_INC(TO_BOOL, hit);
if (_PyLong_IsZero((PyLongObject *)value_o)) { if (_PyLong_IsZero((PyLongObject *)value_o)) {
assert(_Py_IsImmortal(value_o)); assert(_Py_IsImmortalLoose(value_o));
res = PyStackRef_False; res = PyStackRef_False;
} }
else { else {
@ -7392,7 +7392,7 @@
DEOPT_IF(!PyUnicode_CheckExact(value_o), TO_BOOL); DEOPT_IF(!PyUnicode_CheckExact(value_o), TO_BOOL);
STAT_INC(TO_BOOL, hit); STAT_INC(TO_BOOL, hit);
if (value_o == &_Py_STR(empty)) { if (value_o == &_Py_STR(empty)) {
assert(_Py_IsImmortal(value_o)); assert(_Py_IsImmortalLoose(value_o));
res = PyStackRef_False; res = PyStackRef_False;
} }
else { else {