summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
Diffstat (limited to 'Include')
-rw-r--r--Include/object.h14
1 files changed, 12 insertions, 2 deletions
diff --git a/Include/object.h b/Include/object.h
index da8befa..0c88603 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -851,18 +851,28 @@ PyAPI_FUNC(void) _Py_Dealloc(PyObject *);
*
* As in case of Py_CLEAR "the obvious" code can be deadly:
*
- * Py_XDECREF(op);
+ * Py_DECREF(op);
* op = op2;
*
* The safe way is:
*
- * Py_XSETREF(op, op2);
+ * Py_SETREF(op, op2);
*
* That arranges to set `op` to `op2` _before_ decref'ing, so that any code
* triggered as a side-effect of `op` getting torn down no longer believes
* `op` points to a valid object.
+ *
+ * Py_XSETREF is a variant of Py_SETREF that uses Py_XDECREF instead of
+ * Py_DECREF.
*/
+#define Py_SETREF(op, op2) \
+ do { \
+ PyObject *_py_tmp = (PyObject *)(op); \
+ (op) = (op2); \
+ Py_DECREF(_py_tmp); \
+ } while (0)
+
#define Py_XSETREF(op, op2) \
do { \
PyObject *_py_tmp = (PyObject *)(op); \