gh-133476: Assert with the PyStackRef_IsTaggedInt
function (GH-133477)
This commit is contained in:
parent
c492ac7252
commit
6d5a8c2ec1
@ -95,10 +95,16 @@ PyStackRef_IsNone(_PyStackRef ref)
|
|||||||
return _Py_stackref_get_object(ref) == Py_None;
|
return _Py_stackref_get_object(ref) == Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool
|
||||||
|
PyStackRef_IsTaggedInt(_PyStackRef ref)
|
||||||
|
{
|
||||||
|
return (ref.index & 1) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
static inline PyObject *
|
static inline PyObject *
|
||||||
_PyStackRef_AsPyObjectBorrow(_PyStackRef ref, const char *filename, int linenumber)
|
_PyStackRef_AsPyObjectBorrow(_PyStackRef ref, const char *filename, int linenumber)
|
||||||
{
|
{
|
||||||
assert((ref.index & 1) == 0);
|
assert(!PyStackRef_IsTaggedInt(ref));
|
||||||
_Py_stackref_record_borrow(ref, filename, linenumber);
|
_Py_stackref_record_borrow(ref, filename, linenumber);
|
||||||
return _Py_stackref_get_object(ref);
|
return _Py_stackref_get_object(ref);
|
||||||
}
|
}
|
||||||
@ -135,12 +141,6 @@ _PyStackRef_FromPyObjectImmortal(PyObject *obj, const char *filename, int linenu
|
|||||||
}
|
}
|
||||||
#define PyStackRef_FromPyObjectImmortal(obj) _PyStackRef_FromPyObjectImmortal(_PyObject_CAST(obj), __FILE__, __LINE__)
|
#define PyStackRef_FromPyObjectImmortal(obj) _PyStackRef_FromPyObjectImmortal(_PyObject_CAST(obj), __FILE__, __LINE__)
|
||||||
|
|
||||||
static inline bool
|
|
||||||
PyStackRef_IsTaggedInt(_PyStackRef ref)
|
|
||||||
{
|
|
||||||
return (ref.index & 1) == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
_PyStackRef_CLOSE(_PyStackRef ref, const char *filename, int linenumber)
|
_PyStackRef_CLOSE(_PyStackRef ref, const char *filename, int linenumber)
|
||||||
{
|
{
|
||||||
@ -256,7 +256,7 @@ PyStackRef_TagInt(intptr_t i)
|
|||||||
static inline intptr_t
|
static inline intptr_t
|
||||||
PyStackRef_UntagInt(_PyStackRef i)
|
PyStackRef_UntagInt(_PyStackRef i)
|
||||||
{
|
{
|
||||||
assert((i.bits & Py_INT_TAG) == Py_INT_TAG);
|
assert(PyStackRef_IsTaggedInt(i));
|
||||||
intptr_t val = (intptr_t)i.bits;
|
intptr_t val = (intptr_t)i.bits;
|
||||||
return Py_ARITHMETIC_RIGHT_SHIFT(intptr_t, val, 2);
|
return Py_ARITHMETIC_RIGHT_SHIFT(intptr_t, val, 2);
|
||||||
}
|
}
|
||||||
@ -286,6 +286,7 @@ static const _PyStackRef PyStackRef_NULL = { .bits = Py_TAG_DEFERRED};
|
|||||||
static inline PyObject *
|
static inline PyObject *
|
||||||
PyStackRef_AsPyObjectBorrow(_PyStackRef stackref)
|
PyStackRef_AsPyObjectBorrow(_PyStackRef stackref)
|
||||||
{
|
{
|
||||||
|
assert(!PyStackRef_IsTaggedInt(stackref));
|
||||||
PyObject *cleared = ((PyObject *)((stackref).bits & (~Py_TAG_BITS)));
|
PyObject *cleared = ((PyObject *)((stackref).bits & (~Py_TAG_BITS)));
|
||||||
return cleared;
|
return cleared;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user