@@ -379,25 +379,11 @@ decision that's up to the implementer of each new type so if you want,
379379you can count such references to the type object.)
380380*/
381381
382- /* First define a pile of simple helper macros, one set per special
383- * build symbol. These either expand to the obvious things, or to
384- * nothing at all when the special mode isn't in effect. The main
385- * macros can later be defined just once then, yet expand to different
386- * things depending on which special build options are and aren't in effect.
387- * Trust me <wink>: while painful, this is 20x easier to understand than,
388- * e.g, defining _Py_NewReference five different times in a maze of nested
389- * #ifdefs (we used to do that -- it was impenetrable).
390- */
391382#ifdef Py_REF_DEBUG
392383PyAPI_DATA (Py_ssize_t ) _Py_RefTotal ;
393384PyAPI_FUNC (void ) _Py_NegativeRefcount (const char * filename , int lineno ,
394385 PyObject * op );
395386PyAPI_FUNC (Py_ssize_t ) _Py_GetRefTotal (void );
396- #define _Py_INC_REFTOTAL _Py_RefTotal++
397- #define _Py_DEC_REFTOTAL _Py_RefTotal--
398- #else
399- #define _Py_INC_REFTOTAL
400- #define _Py_DEC_REFTOTAL
401387#endif /* Py_REF_DEBUG */
402388
403389/* Update the Python traceback of an object. This function must be called
@@ -406,33 +392,33 @@ PyAPI_FUNC(int) _PyTraceMalloc_NewReference(PyObject *op);
406392
407393#ifdef Py_TRACE_REFS
408394/* Py_TRACE_REFS is such major surgery that we call external routines. */
409- PyAPI_FUNC (void ) _Py_NewReference (PyObject * );
410395PyAPI_FUNC (void ) _Py_ForgetReference (PyObject * );
411396PyAPI_FUNC (void ) _Py_AddToAllObjects (PyObject * , int force );
412- #else
413- /* Without Py_TRACE_REFS, there's little enough to do that we expand code
414- inline. */
397+ #endif
398+
399+
415400static inline void _Py_NewReference (PyObject * op )
416401{
417402 if (_Py_tracemalloc_config .tracing ) {
418403 _PyTraceMalloc_NewReference (op );
419404 }
420- _Py_INC_REFTOTAL ;
405+ #ifdef Py_REF_DEBUG
406+ _Py_RefTotal ++ ;
407+ #endif
421408 Py_REFCNT (op ) = 1 ;
409+ #ifdef Py_TRACE_REFS
410+ _Py_AddToAllObjects (op , 1 );
411+ #endif
422412}
423413
424- static inline void _Py_ForgetReference (PyObject * Py_UNUSED (op ))
425- {
426- /* nothing to do */
427- }
428- #endif /* !Py_TRACE_REFS */
429-
430414
431415PyAPI_FUNC (void ) _Py_Dealloc (PyObject * );
432416
433417static inline void _Py_INCREF (PyObject * op )
434418{
435- _Py_INC_REFTOTAL ;
419+ #ifdef Py_REF_DEBUG
420+ _Py_RefTotal ++ ;
421+ #endif
436422 op -> ob_refcnt ++ ;
437423}
438424
@@ -444,7 +430,9 @@ static inline void _Py_DECREF(
444430#endif
445431 PyObject * op )
446432{
447- _Py_DEC_REFTOTAL ;
433+ #ifdef Py_REF_DEBUG
434+ _Py_RefTotal -- ;
435+ #endif
448436 if (-- op -> ob_refcnt != 0 ) {
449437#ifdef Py_REF_DEBUG
450438 if (op -> ob_refcnt < 0 ) {
0 commit comments