Skip to content

Commit 8ea82b5

Browse files
committed
Implement PyStackRef_{Is,Make}HeapSafe
1 parent b4b7f73 commit 8ea82b5

File tree

10 files changed

+374
-180
lines changed

10 files changed

+374
-180
lines changed

Include/internal/pycore_stackref.h

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,6 @@ PyStackRef_XCLOSE(_PyStackRef ref)
167167
Py_DECREF(obj);
168168
}
169169

170-
static inline _PyStackRef
171-
_PyStackRef_NewIfBorrowedOrSteal(_PyStackRef ref)
172-
{
173-
return ref;
174-
}
175-
176170
static inline _PyStackRef
177171
_PyStackRef_DUP(_PyStackRef ref, const char *filename, int linenumber)
178172
{
@@ -285,9 +279,18 @@ PyStackRef_IsBorrowed(_PyStackRef stackref)
285279
return !(_Py_IsImmortal(obj) || _PyObject_HasDeferredRefcount(obj));
286280
}
287281

282+
static inline bool
283+
PyStackRef_IsHeapSafe(_PyStackRef stackref)
284+
{
285+
if (PyStackRef_IsDeferred(stackref)) {
286+
PyObject *obj = PyStackRef_AsPyObjectBorrow(stackref);
287+
return obj == NULL || _Py_IsImmortal(obj) || _PyObject_HasDeferredRefcount(obj);
288+
}
289+
return true;
290+
}
288291

289292
static inline _PyStackRef
290-
_PyStackRef_NewIfBorrowedOrSteal(_PyStackRef stackref)
293+
PyStackRef_MakeHeapSafe(_PyStackRef stackref)
291294
{
292295
if (PyStackRef_IsBorrowed(stackref)) {
293296
PyObject *obj = PyStackRef_AsPyObjectBorrow(stackref);
@@ -365,18 +368,6 @@ PyStackRef_AsDeferred(_PyStackRef stackref)
365368
return (_PyStackRef){ .bits = stackref.bits | Py_TAG_DEFERRED };
366369
}
367370

368-
static inline bool
369-
PyStackRef_IsHeapSafe(_PyStackRef ref)
370-
{
371-
return true;
372-
}
373-
374-
static inline _PyStackRef
375-
PyStackRef_MakeHeapSafe(_PyStackRef ref)
376-
{
377-
return ref;
378-
}
379-
380371
// Convert a possibly deferred reference to a strong reference.
381372
static inline _PyStackRef
382373
PyStackRef_AsStrongReference(_PyStackRef stackref)

Include/internal/pycore_uop_ids.h

Lines changed: 59 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/opcode_ids.h

Lines changed: 35 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)