summaryrefslogtreecommitdiffstats
path: root/Include/object.h
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-04-10 15:05:40 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-04-10 15:05:40 (GMT)
commit57a01d3a0ee20ee9eea69b658c6bac0f39541625 (patch)
treecdeb89c231bbf902b59832b1b1f6dbe9a775292e /Include/object.h
parente0805cf10ea84b44a13ad5649267edba7cb83ee9 (diff)
downloadcpython-57a01d3a0ee20ee9eea69b658c6bac0f39541625.zip
cpython-57a01d3a0ee20ee9eea69b658c6bac0f39541625.tar.gz
cpython-57a01d3a0ee20ee9eea69b658c6bac0f39541625.tar.bz2
Issue #26200: Added Py_SETREF and replaced Py_XSETREF with Py_SETREF
in places where Py_DECREF was used.
Diffstat (limited to 'Include/object.h')
-rw-r--r--Include/object.h14
1 files changed, 12 insertions, 2 deletions
diff --git a/Include/object.h b/Include/object.h
index 4179651..50d9747 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); \