Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 64fbb33

Browse files
committed
Patch #448194: Debuging negative reference counts.
1 parent 5821272 commit 64fbb33

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

Include/object.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -489,11 +489,12 @@ extern DL_IMPORT(long) _Py_RefTotal;
489489
#endif /* !Py_TRACE_REFS */
490490

491491
#define Py_INCREF(op) (_Py_RefTotal++, (op)->ob_refcnt++)
492-
#define Py_DECREF(op) \
493-
if (--_Py_RefTotal, (--((op)->ob_refcnt) != 0)) \
494-
; \
495-
else \
496-
_Py_Dealloc((PyObject *)(op))
492+
/* under Py_REF_DEBUG: also log negative ref counts after Py_DECREF() !! */
493+
#define Py_DECREF(op) \
494+
if (--_Py_RefTotal, 0 < (--((op)->ob_refcnt))) ; \
495+
else if (0 == (op)->ob_refcnt) _Py_Dealloc( (PyObject*)(op)); \
496+
else (void)fprintf( stderr, "%s:%i negative ref count %i\n", \
497+
__FILE__, __LINE__, (op)->ob_refcnt)
497498
#else /* !Py_REF_DEBUG */
498499

499500
#ifdef COUNT_ALLOCS

0 commit comments

Comments
 (0)