@@ -210,6 +210,32 @@ _PyStackRef_FromPyObjectBorrow(PyObject *obj, const char *filename, int linenumb
210210}
211211#define PyStackRef_FromPyObjectBorrow (obj ) _PyStackRef_FromPyObjectBorrow(_PyObject_CAST(obj), __FILE__, __LINE__)
212212
213+ /* Tag a PyObject pointer as a borrowed operand for BORROW variants. */
214+ static inline uintptr_t
215+ PyStackRef_TagBorrow (PyObject * obj )
216+ {
217+ return (uintptr_t )obj | Py_TAG_REFCNT ;
218+ }
219+
220+ /* Strip tag bits from a pre-tagged operand to recover the PyObject pointer. */
221+ static inline PyObject *
222+ PyStackRef_UntagBorrow (PyObject * tagged )
223+ {
224+ return (PyObject * )((uintptr_t )tagged & ~Py_TAG_BITS );
225+ }
226+
227+ /* Create a stackref from a pre-tagged operand (tag bits already set).
228+ Used by _LOAD_CONST_INLINE_BORROW variants where the operand is
229+ tagged at trace creation time to avoid tagging on every execution. */
230+ static inline _PyStackRef
231+ _PyStackRef_FromPreTagged (PyObject * tagged , const char * filename , int linenumber )
232+ {
233+ assert ((uintptr_t )tagged & Py_TAG_REFCNT );
234+ PyObject * obj = (PyObject * )((uintptr_t )tagged & ~Py_TAG_BITS );
235+ return _Py_stackref_create (obj , Py_TAG_REFCNT , filename , linenumber );
236+ }
237+ #define PyStackRef_FromPreTagged (tagged ) _PyStackRef_FromPreTagged(_PyObject_CAST(tagged), __FILE__, __LINE__)
238+
213239static inline void
214240_PyStackRef_CLOSE (_PyStackRef ref , const char * filename , int linenumber )
215241{
@@ -615,24 +641,29 @@ PyStackRef_FromPyObjectBorrow(PyObject *obj)
615641 return (_PyStackRef ){ .bits = (uintptr_t )obj | Py_TAG_REFCNT };
616642}
617643
644+ /* Tag a PyObject pointer as a borrowed operand for BORROW variants. */
645+ static inline uintptr_t
646+ PyStackRef_TagBorrow (PyObject * obj )
647+ {
648+ return (uintptr_t )obj | Py_TAG_REFCNT ;
649+ }
650+
651+ /* Strip tag bits from a pre-tagged operand to recover the PyObject pointer. */
652+ static inline PyObject *
653+ PyStackRef_UntagBorrow (PyObject * tagged )
654+ {
655+ return (PyObject * )((uintptr_t )tagged & ~Py_TAG_BITS );
656+ }
657+
618658/* Create a stackref from a pre-tagged operand (tag bits already set).
619659 Used by _LOAD_CONST_INLINE_BORROW variants where the operand is
620660 tagged at trace creation time to avoid tagging on every execution. */
621661static inline _PyStackRef
622- _PyStackRef_FromPreTagged ( uintptr_t tagged )
662+ PyStackRef_FromPreTagged ( PyObject * tagged )
623663{
624- assert (tagged & Py_TAG_REFCNT );
625- return (_PyStackRef ){ .bits = tagged };
664+ assert (( uintptr_t ) tagged & Py_TAG_REFCNT );
665+ return (_PyStackRef ){ .bits = ( uintptr_t ) tagged };
626666}
627- #define PyStackRef_FromPreTagged (ptr ) _PyStackRef_FromPreTagged((uintptr_t)(ptr))
628-
629- /* Tag a PyObject pointer as a borrowed operand for BORROW variants. */
630- #define PyStackRef_TagBorrow (ptr ) \
631- ((uintptr_t)(ptr) | Py_TAG_REFCNT)
632-
633- /* Strip tag bits from a pre-tagged operand to recover the PyObject pointer. */
634- #define PyStackRef_UntagBorrow (tagged ) \
635- ((PyObject *)((uintptr_t)(tagged) & ~Py_TAG_BITS))
636667
637668/* WARNING: This macro evaluates its argument more than once */
638669#ifdef _WIN32
0 commit comments