mirror of https://github.com/python/cpython
gh-123091: Use _Py_IsImmortalLoose() (#123511)
Use _Py_IsImmortalLoose() in bytesobject.c, typeobject.c
and ceval.c.
(cherry picked from commit f1a0d96f41
)
This commit is contained in:
parent
b76a4a5db7
commit
10735bff9e
|
@ -1161,10 +1161,10 @@ const struct opcode_metadata _PyOpcode_opcode_metadata[268] = {
|
||||||
[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 },
|
||||||
|
|
|
@ -52,10 +52,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,
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -452,7 +452,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);
|
||||||
}
|
}
|
||||||
|
@ -469,7 +469,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -534,7 +534,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5657,7 +5657,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);
|
||||||
|
|
||||||
|
|
|
@ -362,7 +362,7 @@ dummy_func(
|
||||||
EXIT_IF(!PyLong_CheckExact(value));
|
EXIT_IF(!PyLong_CheckExact(value));
|
||||||
STAT_INC(TO_BOOL, hit);
|
STAT_INC(TO_BOOL, hit);
|
||||||
if (_PyLong_IsZero((PyLongObject *)value)) {
|
if (_PyLong_IsZero((PyLongObject *)value)) {
|
||||||
assert(_Py_IsImmortal(value));
|
assert(_Py_IsImmortalLoose(value));
|
||||||
res = Py_False;
|
res = Py_False;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -389,7 +389,7 @@ dummy_func(
|
||||||
EXIT_IF(!PyUnicode_CheckExact(value));
|
EXIT_IF(!PyUnicode_CheckExact(value));
|
||||||
STAT_INC(TO_BOOL, hit);
|
STAT_INC(TO_BOOL, hit);
|
||||||
if (value == &_Py_STR(empty)) {
|
if (value == &_Py_STR(empty)) {
|
||||||
assert(_Py_IsImmortal(value));
|
assert(_Py_IsImmortalLoose(value));
|
||||||
res = Py_False;
|
res = Py_False;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -347,7 +347,7 @@
|
||||||
}
|
}
|
||||||
STAT_INC(TO_BOOL, hit);
|
STAT_INC(TO_BOOL, hit);
|
||||||
if (_PyLong_IsZero((PyLongObject *)value)) {
|
if (_PyLong_IsZero((PyLongObject *)value)) {
|
||||||
assert(_Py_IsImmortal(value));
|
assert(_Py_IsImmortalLoose(value));
|
||||||
res = Py_False;
|
res = Py_False;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -398,7 +398,7 @@
|
||||||
}
|
}
|
||||||
STAT_INC(TO_BOOL, hit);
|
STAT_INC(TO_BOOL, hit);
|
||||||
if (value == &_Py_STR(empty)) {
|
if (value == &_Py_STR(empty)) {
|
||||||
assert(_Py_IsImmortal(value));
|
assert(_Py_IsImmortalLoose(value));
|
||||||
res = Py_False;
|
res = Py_False;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -5939,7 +5939,7 @@
|
||||||
DEOPT_IF(!PyLong_CheckExact(value), TO_BOOL);
|
DEOPT_IF(!PyLong_CheckExact(value), TO_BOOL);
|
||||||
STAT_INC(TO_BOOL, hit);
|
STAT_INC(TO_BOOL, hit);
|
||||||
if (_PyLong_IsZero((PyLongObject *)value)) {
|
if (_PyLong_IsZero((PyLongObject *)value)) {
|
||||||
assert(_Py_IsImmortal(value));
|
assert(_Py_IsImmortalLoose(value));
|
||||||
res = Py_False;
|
res = Py_False;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -5999,7 +5999,7 @@
|
||||||
DEOPT_IF(!PyUnicode_CheckExact(value), TO_BOOL);
|
DEOPT_IF(!PyUnicode_CheckExact(value), TO_BOOL);
|
||||||
STAT_INC(TO_BOOL, hit);
|
STAT_INC(TO_BOOL, hit);
|
||||||
if (value == &_Py_STR(empty)) {
|
if (value == &_Py_STR(empty)) {
|
||||||
assert(_Py_IsImmortal(value));
|
assert(_Py_IsImmortalLoose(value));
|
||||||
res = Py_False;
|
res = Py_False;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Reference in New Issue