Skip to content

Commit 64ec384

Browse files
committed
Fix Py_STACKREF_DEBUG build
1 parent b0f77c4 commit 64ec384

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

Include/internal/pycore_stackref.h

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,15 @@ _PyStackRef_CLOSE(_PyStackRef ref, const char *filename, int linenumber)
146146
#define PyStackRef_CLOSE(REF) _PyStackRef_CLOSE((REF), __FILE__, __LINE__)
147147

148148
static inline void
149-
PyStackRef_XCLOSE(_PyStackRef ref)
149+
_PyStackRef_XCLOSE(_PyStackRef ref, const char *filename, int linenumber)
150150
{
151151
if (PyStackRef_IsNull(ref)) {
152152
return;
153153
}
154-
PyObject *obj = _Py_stackref_close(ref);
154+
PyObject *obj = _Py_stackref_close(ref, filename, linenumber);
155155
Py_DECREF(obj);
156156
}
157+
#define PyStackRef_XCLOSE(REF) _PyStackRef_XCLOSE((REF), __FILE__, __LINE__)
157158

158159
static inline _PyStackRef
159160
_PyStackRef_DUP(_PyStackRef ref, const char *filename, int linenumber)
@@ -164,7 +165,8 @@ _PyStackRef_DUP(_PyStackRef ref, const char *filename, int linenumber)
164165
}
165166
#define PyStackRef_DUP(REF) _PyStackRef_DUP(REF, __FILE__, __LINE__)
166167

167-
extern void PyStackRef_CLOSE_SPECIALIZED(_PyStackRef ref, destructor destruct);
168+
extern void _PyStackRef_CLOSE_SPECIALIZED(_PyStackRef ref, destructor destruct, const char *filename, int linenumber);
169+
#define PyStackRef_CLOSE_SPECIALIZED(REF, DESTRUCT) _PyStackRef_CLOSE_SPECIALIZED(REF, DESTRUCT, __FILE__, __LINE__)
168170

169171
static inline _PyStackRef
170172
PyStackRef_MakeHeapSafe(_PyStackRef ref)
@@ -175,7 +177,7 @@ PyStackRef_MakeHeapSafe(_PyStackRef ref)
175177
static inline _PyStackRef
176178
PyStackRef_Borrow(_PyStackRef ref)
177179
{
178-
return PyStackRef_DUP(ref)
180+
return PyStackRef_DUP(ref);
179181
}
180182

181183
#define PyStackRef_CLEAR(REF) \
@@ -200,6 +202,18 @@ PyStackRef_IsHeapSafe(_PyStackRef ref)
200202
return true;
201203
}
202204

205+
static inline _PyStackRef
206+
_PyStackRef_FromPyObjectNewMortal(PyObject *obj, const char *filename, int linenumber)
207+
{
208+
assert(!_Py_IsStaticImmortal(obj));
209+
Py_INCREF(obj);
210+
return _Py_stackref_create(obj, filename, linenumber);
211+
}
212+
#define PyStackRef_FromPyObjectNewMortal(obj) _PyStackRef_FromPyObjectNewMortal(_PyObject_CAST(obj), __FILE__, __LINE__)
213+
214+
#define PyStackRef_RefcountOnObject(REF) 1
215+
216+
extern int PyStackRef_Is(_PyStackRef a, _PyStackRef b);
203217

204218
#else
205219

@@ -616,6 +630,7 @@ PyStackRef_XCLOSE(_PyStackRef ref)
616630

617631
#define PyStackRef_Is(a, b) (((a).bits & (~Py_TAG_BITS)) == ((b).bits & (~Py_TAG_BITS)))
618632

633+
619634
#endif // !defined(Py_GIL_DISABLED) && defined(Py_STACKREF_DEBUG)
620635

621636
#define PyStackRef_TYPE(stackref) Py_TYPE(PyStackRef_AsPyObjectBorrow(stackref))

Python/stackrefs.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ _Py_stackref_get_object(_PyStackRef ref)
5555
return entry->obj;
5656
}
5757

58+
int
59+
PyStackRef_Is(_PyStackRef a, _PyStackRef b)
60+
{
61+
return _Py_stackref_get_object(a) == _Py_stackref_get_object(b);
62+
}
63+
5864
PyObject *
5965
_Py_stackref_close(_PyStackRef ref, const char *filename, int linenumber)
6066
{
@@ -182,9 +188,9 @@ _Py_stackref_report_leaks(PyInterpreterState *interp)
182188
}
183189

184190
void
185-
PyStackRef_CLOSE_SPECIALIZED(_PyStackRef ref, destructor destruct)
191+
_PyStackRef_CLOSE_SPECIALIZED(_PyStackRef ref, destructor destruct, const char *filename, int linenumber)
186192
{
187-
PyObject *obj = _Py_stackref_close(ref);
193+
PyObject *obj = _Py_stackref_close(ref, filename, linenumber);
188194
_Py_DECREF_SPECIALIZED(obj, destruct);
189195
}
190196

0 commit comments

Comments
 (0)