◐ Shell
clean mode source ↗

WIP: bpo-35059: Replace inline with macros by vstinner · Pull Request #10669 · python/cpython

Expand Up @@ -740,14 +740,21 @@ PyAPI_FUNC(void) _Py_NegativeRefcount(const char *filename, int lineno, PyAPI_FUNC(Py_ssize_t) _Py_GetRefTotal(void); #define _Py_INC_REFTOTAL _Py_RefTotal++ #define _Py_DEC_REFTOTAL _Py_RefTotal--
#define _Py_REF_DEBUG_COMMA , #define _Py_CHECK_REFCNT(OP) \ { if (((PyObject*)OP)->ob_refcnt < 0) \ _Py_NegativeRefcount(__FILE__, __LINE__, \ (PyObject *)(OP)); \ } /* Py_REF_DEBUG also controls the display of refcounts and memory block * allocations at the interactive prompt and at interpreter shutdown */ PyAPI_FUNC(void) _PyDebug_PrintTotalRefs(void); #else #define _Py_INC_REFTOTAL #define _Py_DEC_REFTOTAL #define _Py_REF_DEBUG_COMMA #define _Py_CHECK_REFCNT(OP) /* a semicolon */; #endif /* Py_REF_DEBUG */
#ifdef COUNT_ALLOCS Expand All @@ -772,73 +779,47 @@ PyAPI_FUNC(int) _PyTraceMalloc_NewReference(PyObject *op); /* Py_TRACE_REFS is such major surgery that we call external routines. */ PyAPI_FUNC(void) _Py_NewReference(PyObject *); PyAPI_FUNC(void) _Py_ForgetReference(PyObject *); PyAPI_FUNC(void) _Py_Dealloc(PyObject *); PyAPI_FUNC(void) _Py_PrintReferences(FILE *); PyAPI_FUNC(void) _Py_PrintReferenceAddresses(FILE *); PyAPI_FUNC(void) _Py_AddToAllObjects(PyObject *, int force);
#else /* Without Py_TRACE_REFS, there's little enough to do that we expand code inline. */ static inline void _Py_NewReference(PyObject *op) { if (_Py_tracemalloc_config.tracing) { _PyTraceMalloc_NewReference(op); } _Py_INC_TPALLOCS(op); _Py_INC_REFTOTAL; Py_REFCNT(op) = 1; }
static inline void _Py_ForgetReference(PyObject *op) { _Py_INC_TPFREES(op); } #endif /* !Py_TRACE_REFS */ #define _Py_NewReference(op) ( \ (_Py_tracemalloc_config.tracing \ ? _PyTraceMalloc_NewReference(op) \ : 0), \ _Py_INC_TPALLOCS(op) _Py_COUNT_ALLOCS_COMMA \ _Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA \ Py_REFCNT(op) = 1)
#define _Py_ForgetReference(op) _Py_INC_TPFREES(op)
#ifdef Py_LIMITED_API PyAPI_FUNC(void) _Py_Dealloc(PyObject *);
#ifndef Py_LIMITED_API static inline void _Py_Dealloc_inline(PyObject *op) { destructor dealloc = Py_TYPE(op)->tp_dealloc; #ifdef Py_TRACE_REFS _Py_ForgetReference(op); #else _Py_INC_TPFREES(op); #endif (*dealloc)(op); }
# define _Py_Dealloc(op) _Py_Dealloc_inline(op) #define _Py_Dealloc(op) ( \ _Py_INC_TPFREES(op) _Py_COUNT_ALLOCS_COMMA \ (*Py_TYPE(op)->tp_dealloc)((PyObject *)(op))) #endif /* !Py_TRACE_REFS */ #endif /* !defined(Py_LIMITED_API) */

static inline void _Py_INCREF(PyObject *op) { _Py_INC_REFTOTAL; op->ob_refcnt++; }
#define Py_INCREF(op) _Py_INCREF(_PyObject_CAST(op)) #define Py_INCREF(op) ( \ _Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA \ ((PyObject *)(op))->ob_refcnt++)
static inline void _Py_DECREF(const char *filename, int lineno, PyObject *op) { _Py_DEC_REFTOTAL; if (--op->ob_refcnt != 0) { #ifdef Py_REF_DEBUG if (op->ob_refcnt < 0) { _Py_NegativeRefcount(filename, lineno, op); } #endif } else { _Py_Dealloc(op); } }
#define Py_DECREF(op) _Py_DECREF(__FILE__, __LINE__, _PyObject_CAST(op)) #define Py_DECREF(op) \ do { \ PyObject *_py_decref_tmp = (PyObject *)(op); \ if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \ --(_py_decref_tmp)->ob_refcnt != 0) \ _Py_CHECK_REFCNT(_py_decref_tmp) \ else \ _Py_Dealloc(_py_decref_tmp); \ } while (0)

/* Safely decref `op` and set `op` to NULL, especially useful in tp_clear Expand Down Expand Up @@ -885,23 +866,19 @@ static inline void _Py_DECREF(const char *filename, int lineno, } while (0)
/* Function to use in case the object pointer can be NULL: */ static inline void _Py_XINCREF(PyObject *op) { if (op != NULL) { Py_INCREF(op); } }
#define Py_XINCREF(op) _Py_XINCREF(_PyObject_CAST(op))
static inline void _Py_XDECREF(PyObject *op) { if (op != NULL) { Py_DECREF(op); } } #define Py_XINCREF(op) \ do { \ PyObject *_py_xincref_tmp = (PyObject *)(op); \ if (_py_xincref_tmp != NULL) \ Py_INCREF(_py_xincref_tmp); \ } while (0)
#define Py_XDECREF(op) _Py_XDECREF(_PyObject_CAST(op)) #define Py_XDECREF(op) \ do { \ PyObject *_py_xdecref_tmp = (PyObject *)(op); \ if (_py_xdecref_tmp != NULL) \ Py_DECREF(_py_xdecref_tmp); \ } while (0)
#ifndef Py_LIMITED_API /* Safely decref `op` and set `op` to `op2`. Expand Down