summaryrefslogtreecommitdiffstats
path: root/Include/object.h
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-10-29 19:52:41 (GMT)
committerGitHub <noreply@github.com>2018-10-29 19:52:41 (GMT)
commit541497e6197268517b0d492856027774c43e0949 (patch)
tree78e1f8d8002c31ce323527a2956278c969be6b0c /Include/object.h
parent0200928e8df012d408530b06a98119024bc82511 (diff)
downloadcpython-541497e6197268517b0d492856027774c43e0949.zip
cpython-541497e6197268517b0d492856027774c43e0949.tar.gz
cpython-541497e6197268517b0d492856027774c43e0949.tar.bz2
bpo-35059: Convert Py_XINCREF() to static inline function (GH-10224)
Convert Py_XINCREF() and Py_XDECREF() macros into static inline functions.
Diffstat (limited to 'Include/object.h')
-rw-r--r--Include/object.h30
1 files changed, 17 insertions, 13 deletions
diff --git a/Include/object.h b/Include/object.h
index f9c07f7..799c40b 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -871,20 +871,24 @@ static inline void _Py_DECREF(const char *filename, int lineno,
} \
} while (0)
-/* Macros to use in case the object pointer may be NULL: */
-#define Py_XINCREF(op) \
- do { \
- PyObject *_py_xincref_tmp = (PyObject *)(op); \
- if (_py_xincref_tmp != NULL) \
- Py_INCREF(_py_xincref_tmp); \
- } 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_XDECREF(op) \
- do { \
- PyObject *_py_xdecref_tmp = (PyObject *)(op); \
- if (_py_xdecref_tmp != NULL) \
- Py_DECREF(_py_xdecref_tmp); \
- } while (0)
+#define Py_XINCREF(op) _Py_XINCREF((PyObject *)(op))
+
+static inline void _Py_XDECREF(PyObject *op)
+{
+ if (op != NULL) {
+ Py_DECREF(op);
+ }
+}
+
+#define Py_XDECREF(op) _Py_XDECREF((PyObject *)(op))
#ifndef Py_LIMITED_API
/* Safely decref `op` and set `op` to `op2`.