Skip to content

Commit e0ea1b1

Browse files
Fixes for PyStackRefs in debug builds.
1 parent f39dea3 commit e0ea1b1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Include/internal/pycore_stackref.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@ static const _PyStackRef PyStackRef_ERROR = { .index = 2 };
7272

7373
#define INITIAL_STACKREF_INDEX 10
7474

75+
static inline _PyStackRef
76+
PyStackRef_Wrap(void *ptr)
77+
{
78+
assert(ptr != NULL);
79+
return (_PyStackRef){ .index = (uint64_t)ptr };
80+
}
81+
82+
static inline void *
83+
PyStackRef_Unwrap(_PyStackRef ref)
84+
{
85+
return (void *)(ref.index);
86+
}
87+
7588
static inline int
7689
PyStackRef_IsNull(_PyStackRef ref)
7790
{
@@ -151,6 +164,7 @@ _PyStackRef_FromPyObjectSteal(PyObject *obj, const char *filename, int linenumbe
151164
static inline _PyStackRef
152165
_PyStackRef_FromPyObjectBorrow(PyObject *obj, const char *filename, int linenumber)
153166
{
167+
Py_INCREF(obj);
154168
return _Py_stackref_create(obj, filename, linenumber);
155169
}
156170
#define PyStackRef_FromPyObjectBorrow(obj) _PyStackRef_FromPyObjectBorrow(_PyObject_CAST(obj), __FILE__, __LINE__)

0 commit comments

Comments
 (0)