Skip to content

Commit a46f4e6

Browse files
committed
Move mortal decrefs to internal header and make sure _PyReftracerTrack is called
1 parent a45f253 commit a46f4e6

File tree

2 files changed

+68
-58
lines changed

2 files changed

+68
-58
lines changed

Include/internal/pycore_object.h

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

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

Include/refcount.h

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

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

427391
static inline void Py_DECREF(const char *filename, int lineno, PyObject *op)
428392
{
@@ -448,28 +412,6 @@ static inline void Py_DECREF(const char *filename, int lineno, PyObject *op)
448412
#define Py_DECREF(op) Py_DECREF(__FILE__, __LINE__, _PyObject_CAST(op))
449413

450414
#else
451-
static inline void Py_DECREF_MORTAL(PyObject *op)
452-
{
453-
assert(!_Py_IsStaticImmortal(op));
454-
_Py_DECREF_STAT_INC();
455-
if (--op->ob_refcnt == 0) {
456-
_Py_Dealloc(op);
457-
}
458-
}
459-
#define Py_DECREF_MORTAL(op) Py_DECREF_MORTAL(_PyObject_CAST(op))
460-
461-
static inline void Py_DECREF_MORTAL_SPECIALIZED(PyObject *op, destructor destruct)
462-
{
463-
assert(!_Py_IsStaticImmortal(op));
464-
_Py_DECREF_STAT_INC();
465-
if (--op->ob_refcnt == 0) {
466-
#ifdef Py_TRACE_REFS
467-
_Py_ForgetReference(op);
468-
#endif
469-
destruct(op);
470-
}
471-
}
472-
#define Py_DECREF_MORTAL_SPECIALIZED(op, destruct) Py_DECREF_MORTAL_SPECIALIZED(_PyObject_CAST(op), destruct)
473415

474416
static inline Py_ALWAYS_INLINE void Py_DECREF(PyObject *op)
475417
{

0 commit comments

Comments
 (0)