Skip to content

Commit 541497e

Browse files
authored
bpo-35059: Convert Py_XINCREF() to static inline function (GH-10224)
Convert Py_XINCREF() and Py_XDECREF() macros into static inline functions.
1 parent 0200928 commit 541497e

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

Include/object.h

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -871,20 +871,24 @@ static inline void _Py_DECREF(const char *filename, int lineno,
871871
} \
872872
} while (0)
873873

874-
/* Macros to use in case the object pointer may be NULL: */
875-
#define Py_XINCREF(op) \
876-
do { \
877-
PyObject *_py_xincref_tmp = (PyObject *)(op); \
878-
if (_py_xincref_tmp != NULL) \
879-
Py_INCREF(_py_xincref_tmp); \
880-
} while (0)
874+
/* Function to use in case the object pointer can be NULL: */
875+
static inline void _Py_XINCREF(PyObject *op)
876+
{
877+
if (op != NULL) {
878+
Py_INCREF(op);
879+
}
880+
}
881881

882-
#define Py_XDECREF(op) \
883-
do { \
884-
PyObject *_py_xdecref_tmp = (PyObject *)(op); \
885-
if (_py_xdecref_tmp != NULL) \
886-
Py_DECREF(_py_xdecref_tmp); \
887-
} while (0)
882+
#define Py_XINCREF(op) _Py_XINCREF((PyObject *)(op))
883+
884+
static inline void _Py_XDECREF(PyObject *op)
885+
{
886+
if (op != NULL) {
887+
Py_DECREF(op);
888+
}
889+
}
890+
891+
#define Py_XDECREF(op) _Py_XDECREF((PyObject *)(op))
888892

889893
#ifndef Py_LIMITED_API
890894
/* Safely decref `op` and set `op` to `op2`.

0 commit comments

Comments
 (0)