((PyObject*)(op))->ob_refcnt++)
#define Py_DECREF(op) \
- if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \
- --((PyObject*)(op))->ob_refcnt != 0) \
- _Py_CHECK_REFCNT(op) \
- else \
- _Py_Dealloc((PyObject *)(op))
+ do { \
+ if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \
+ --((PyObject*)(op))->ob_refcnt != 0) \
+ _Py_CHECK_REFCNT(op) \
+ else \
+ _Py_Dealloc((PyObject *)(op)); \
+ } while (0)
/* Safely decref `op` and set `op` to NULL, especially useful in tp_clear
* and tp_dealloc implementatons.
} while (0)
/* Macros to use in case the object pointer may be NULL: */
-#define Py_XINCREF(op) if ((op) == NULL) ; else Py_INCREF(op)
-#define Py_XDECREF(op) if ((op) == NULL) ; else Py_DECREF(op)
+#define Py_XINCREF(op) do { if ((op) == NULL) ; else Py_INCREF(op); } while (0)
+#define Py_XDECREF(op) do { if ((op) == NULL) ; else Py_DECREF(op); } while (0)
/*
These are provided as conveniences to Python runtime embedders, so that
Core and Builtins
-----------------
+- Issue #1113244: Py_XINCREF, Py_DECREF, Py_XDECREF: Add `do { ... } while (0)'
+ to avoid compiler warnings.
+
Library
-------
- Issue #3845: In PyRun_SimpleFileExFlags avoid invalid memory access with
short file names.
-- Py_DECREF: Add `do { ... } while (0)' to avoid compiler warnings.
-
Library
-------
r = PyObject_CallFunction(completion_display_matches_hook,
"sOi", matches[0], m, max_length);
- Py_DECREF(m), m=NULL;
+ Py_DECREF(m); m=NULL;
if (r == NULL ||
(r != Py_None && PyLong_AsLong(r) == -1 && PyErr_Occurred())) {
goto error;
}
- Py_XDECREF(r), r=NULL;
+ Py_XDECREF(r); r=NULL;
if (0) {
error: