mirror of
https://github.com/python/cpython.git
synced 2025-08-27 12:16:04 +00:00
GH-132508: Use tagged integers on the evaluation stack for the last instruction offset (GH-132545)
This commit is contained in:
parent
caee16f052
commit
ccf1b0b1c1
14 changed files with 129 additions and 60 deletions
|
@ -70,7 +70,7 @@ _Py_stackref_close(_PyStackRef ref, const char *filename, int linenumber)
|
|||
|
||||
}
|
||||
PyObject *obj;
|
||||
if (ref.index <= LAST_PREDEFINED_STACKREF_INDEX) {
|
||||
if (ref.index < INITIAL_STACKREF_INDEX) {
|
||||
if (ref.index == 0) {
|
||||
_Py_FatalErrorFormat(__func__, "Passing NULL to PyStackRef_CLOSE at %s:%d\n", filename, linenumber);
|
||||
}
|
||||
|
@ -113,7 +113,8 @@ _Py_stackref_create(PyObject *obj, const char *filename, int linenumber)
|
|||
Py_FatalError("Cannot create a stackref for NULL");
|
||||
}
|
||||
PyInterpreterState *interp = PyInterpreterState_Get();
|
||||
uint64_t new_id = interp->next_stackref++;
|
||||
uint64_t new_id = interp->next_stackref;
|
||||
interp->next_stackref = new_id + 2;
|
||||
TableEntry *entry = make_table_entry(obj, filename, linenumber);
|
||||
if (entry == NULL) {
|
||||
Py_FatalError("No memory left for stackref debug table");
|
||||
|
@ -127,7 +128,7 @@ _Py_stackref_create(PyObject *obj, const char *filename, int linenumber)
|
|||
void
|
||||
_Py_stackref_record_borrow(_PyStackRef ref, const char *filename, int linenumber)
|
||||
{
|
||||
if (ref.index <= LAST_PREDEFINED_STACKREF_INDEX) {
|
||||
if (ref.index < INITIAL_STACKREF_INDEX) {
|
||||
return;
|
||||
}
|
||||
PyInterpreterState *interp = PyInterpreterState_Get();
|
||||
|
@ -151,8 +152,7 @@ _Py_stackref_record_borrow(_PyStackRef ref, const char *filename, int linenumber
|
|||
void
|
||||
_Py_stackref_associate(PyInterpreterState *interp, PyObject *obj, _PyStackRef ref)
|
||||
{
|
||||
assert(interp->next_stackref >= ref.index);
|
||||
interp->next_stackref = ref.index+1;
|
||||
assert(ref.index < INITIAL_STACKREF_INDEX);
|
||||
TableEntry *entry = make_table_entry(obj, "builtin-object", 0);
|
||||
if (entry == NULL) {
|
||||
Py_FatalError("No memory left for stackref debug table");
|
||||
|
@ -197,4 +197,23 @@ _PyStackRef_CLOSE_SPECIALIZED(_PyStackRef ref, destructor destruct, const char *
|
|||
_Py_DECREF_SPECIALIZED(obj, destruct);
|
||||
}
|
||||
|
||||
_PyStackRef PyStackRef_TagInt(intptr_t i)
|
||||
{
|
||||
return (_PyStackRef){ .index = (i << 1) + 1 };
|
||||
}
|
||||
|
||||
intptr_t
|
||||
PyStackRef_UntagInt(_PyStackRef i)
|
||||
{
|
||||
assert(PyStackRef_IsTaggedInt(i));
|
||||
intptr_t val = (intptr_t)i.index;
|
||||
return Py_ARITHMETIC_RIGHT_SHIFT(intptr_t, val, 1);
|
||||
}
|
||||
|
||||
bool
|
||||
PyStackRef_IsNullOrInt(_PyStackRef ref)
|
||||
{
|
||||
return PyStackRef_IsNull(ref) || PyStackRef_IsTaggedInt(ref);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue