Skip to content

Commit 0f5437c

Browse files
committed
Revert "GH-127705: Move mortal decrefs to internal header and make sure _PyReftracerTrack is called"
This broke Py_TRACE_REFS builds. This reverts commit fd545d7.
1 parent 86d5fa9 commit 0f5437c

File tree

2 files changed

+58
-68
lines changed

2 files changed

+58
-68
lines changed

Include/internal/pycore_object.h

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -431,74 +431,6 @@ _Py_DECREF_CODE(PyCodeObject *co)
431431
}
432432
#endif
433433

434-
#ifndef Py_GIL_DISABLED
435-
#ifdef Py_REF_DEBUG
436-
437-
static inline void Py_DECREF_MORTAL(const char *filename, int lineno, PyObject *op)
438-
{
439-
if (op->ob_refcnt <= 0) {
440-
_Py_NegativeRefcount(filename, lineno, op);
441-
}
442-
_Py_DECREF_STAT_INC();
443-
assert(!_Py_IsStaticImmortal(op));
444-
if (!_Py_IsImmortal(op)) {
445-
_Py_DECREF_DecRefTotal();
446-
}
447-
if (--op->ob_refcnt == 0) {
448-
#ifdef Py_TRACE_REFS
449-
_Py_ForgetReference(op);
450-
#endif
451-
_Py_Dealloc(op);
452-
}
453-
}
454-
#define Py_DECREF_MORTAL(op) Py_DECREF_MORTAL(__FILE__, __LINE__, _PyObject_CAST(op))
455-
456-
static inline void _Py_DECREF_MORTAL_SPECIALIZED(const char *filename, int lineno, PyObject *op, destructor destruct)
457-
{
458-
if (op->ob_refcnt <= 0) {
459-
_Py_NegativeRefcount(filename, lineno, op);
460-
}
461-
_Py_DECREF_STAT_INC();
462-
assert(!_Py_IsStaticImmortal(op));
463-
if (!_Py_IsImmortal(op)) {
464-
_Py_DECREF_DecRefTotal();
465-
}
466-
if (--op->ob_refcnt == 0) {
467-
#ifdef Py_TRACE_REFS
468-
_Py_ForgetReference(op);
469-
#endif
470-
_PyReftracerTrack(op, PyRefTracer_DESTROY);
471-
destruct(op);
472-
}
473-
}
474-
#define Py_DECREF_MORTAL_SPECIALIZED(op, destruct) _Py_DECREF_MORTAL_SPECIALIZED(__FILE__, __LINE__, op, destruct)
475-
476-
#else
477-
478-
static inline void Py_DECREF_MORTAL(PyObject *op)
479-
{
480-
assert(!_Py_IsStaticImmortal(op));
481-
_Py_DECREF_STAT_INC();
482-
if (--op->ob_refcnt == 0) {
483-
_Py_Dealloc(op);
484-
}
485-
}
486-
#define Py_DECREF_MORTAL(op) Py_DECREF_MORTAL(_PyObject_CAST(op))
487-
488-
static inline void Py_DECREF_MORTAL_SPECIALIZED(PyObject *op, destructor destruct)
489-
{
490-
assert(!_Py_IsStaticImmortal(op));
491-
_Py_DECREF_STAT_INC();
492-
if (--op->ob_refcnt == 0) {
493-
_PyReftracerTrack(op, PyRefTracer_DESTROY);
494-
destruct(op);
495-
}
496-
}
497-
#define Py_DECREF_MORTAL_SPECIALIZED(op, destruct) Py_DECREF_MORTAL_SPECIALIZED(_PyObject_CAST(op), destruct)
498-
499-
#endif
500-
#endif
501-
502434
/* Inline functions trading binary compatibility for speed:
503435
_PyObject_Init() is the fast version of PyObject_Init(), and
504436
_PyObject_InitVar() is the fast version of PyObject_InitVar().

Include/refcount.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,42 @@ static inline void Py_DECREF(PyObject *op)
394394
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
395395

396396
#elif defined(Py_REF_DEBUG)
397+
static inline void Py_DECREF_MORTAL(const char *filename, int lineno, PyObject *op)
398+
{
399+
if (op->ob_refcnt <= 0) {
400+
_Py_NegativeRefcount(filename, lineno, op);
401+
}
402+
_Py_DECREF_STAT_INC();
403+
assert(!_Py_IsStaticImmortal(op));
404+
if (!_Py_IsImmortal(op)) {
405+
_Py_DECREF_DecRefTotal();
406+
}
407+
if (--op->ob_refcnt == 0) {
408+
_Py_Dealloc(op);
409+
}
410+
}
411+
#define Py_DECREF_MORTAL(op) Py_DECREF_MORTAL(__FILE__, __LINE__, _PyObject_CAST(op))
412+
413+
414+
415+
static inline void _Py_DECREF_MORTAL_SPECIALIZED(const char *filename, int lineno, PyObject *op, destructor destruct)
416+
{
417+
if (op->ob_refcnt <= 0) {
418+
_Py_NegativeRefcount(filename, lineno, op);
419+
}
420+
_Py_DECREF_STAT_INC();
421+
assert(!_Py_IsStaticImmortal(op));
422+
if (!_Py_IsImmortal(op)) {
423+
_Py_DECREF_DecRefTotal();
424+
}
425+
if (--op->ob_refcnt == 0) {
426+
#ifdef Py_TRACE_REFS
427+
_Py_ForgetReference(op);
428+
#endif
429+
destruct(op);
430+
}
431+
}
432+
#define Py_DECREF_MORTAL_SPECIALIZED(op, destruct) _Py_DECREF_MORTAL_SPECIALIZED(__FILE__, __LINE__, op, destruct)
397433

398434
static inline void Py_DECREF(const char *filename, int lineno, PyObject *op)
399435
{
@@ -419,6 +455,28 @@ static inline void Py_DECREF(const char *filename, int lineno, PyObject *op)
419455
#define Py_DECREF(op) Py_DECREF(__FILE__, __LINE__, _PyObject_CAST(op))
420456

421457
#else
458+
static inline void Py_DECREF_MORTAL(PyObject *op)
459+
{
460+
assert(!_Py_IsStaticImmortal(op));
461+
_Py_DECREF_STAT_INC();
462+
if (--op->ob_refcnt == 0) {
463+
_Py_Dealloc(op);
464+
}
465+
}
466+
#define Py_DECREF_MORTAL(op) Py_DECREF_MORTAL(_PyObject_CAST(op))
467+
468+
static inline void Py_DECREF_MORTAL_SPECIALIZED(PyObject *op, destructor destruct)
469+
{
470+
assert(!_Py_IsStaticImmortal(op));
471+
_Py_DECREF_STAT_INC();
472+
if (--op->ob_refcnt == 0) {
473+
#ifdef Py_TRACE_REFS
474+
_Py_ForgetReference(op);
475+
#endif
476+
destruct(op);
477+
}
478+
}
479+
#define Py_DECREF_MORTAL_SPECIALIZED(op, destruct) Py_DECREF_MORTAL_SPECIALIZED(_PyObject_CAST(op), destruct)
422480

423481
static inline Py_ALWAYS_INLINE void Py_DECREF(PyObject *op)
424482
{

0 commit comments

Comments
 (0)