summaryrefslogtreecommitdiff
path: root/Include/cpython/object.h
diff options
context:
space:
mode:
Diffstat (limited to 'Include/cpython/object.h')
-rw-r--r--Include/cpython/object.h44
1 files changed, 20 insertions, 24 deletions
diff --git a/Include/cpython/object.h b/Include/cpython/object.h
index f4755a7b2f..3abfcb7d44 100644
--- a/Include/cpython/object.h
+++ b/Include/cpython/object.h
@@ -305,41 +305,37 @@ _PyObject_GenericSetAttrWithDict(PyObject *, PyObject *,
PyAPI_FUNC(PyObject *) _PyObject_FunctionStr(PyObject *);
-/* Safely decref `dst` and set `dst` to `src`.
+/* Safely decref `op` and set `op` to `op2`.
*
* As in case of Py_CLEAR "the obvious" code can be deadly:
*
- * Py_DECREF(dst);
- * dst = src;
+ * Py_DECREF(op);
+ * op = op2;
*
* The safe way is:
*
- * Py_SETREF(dst, src);
+ * Py_SETREF(op, op2);
*
- * That arranges to set `dst` to `src` _before_ decref'ing, so that any code
- * triggered as a side-effect of `dst` getting torn down no longer believes
- * `dst` points to a valid object.
+ * 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.
*
- * gh-98724: Use the _tmp_dst_ptr variable to evaluate the 'dst' macro argument
- * exactly once, to prevent the duplication of side effects in this macro.
+ * Py_XSETREF is a variant of Py_SETREF that uses Py_XDECREF instead of
+ * Py_DECREF.
*/
-#define Py_SETREF(dst, src) \
- do { \
- PyObject **_tmp_dst_ptr = _Py_CAST(PyObject**, &(dst)); \
- PyObject *_tmp_dst = (*_tmp_dst_ptr); \
- *_tmp_dst_ptr = _PyObject_CAST(src); \
- Py_DECREF(_tmp_dst); \
+
+#define Py_SETREF(op, op2) \
+ do { \
+ PyObject *_py_tmp = _PyObject_CAST(op); \
+ (op) = (op2); \
+ Py_DECREF(_py_tmp); \
} while (0)
-/* Py_XSETREF() is a variant of Py_SETREF() that uses Py_XDECREF() instead of
- * Py_DECREF().
- */
-#define Py_XSETREF(dst, src) \
- do { \
- PyObject **_tmp_dst_ptr = _Py_CAST(PyObject**, &(dst)); \
- PyObject *_tmp_dst = (*_tmp_dst_ptr); \
- *_tmp_dst_ptr = _PyObject_CAST(src); \
- Py_XDECREF(_tmp_dst); \
+#define Py_XSETREF(op, op2) \
+ do { \
+ PyObject *_py_tmp = _PyObject_CAST(op); \
+ (op) = (op2); \
+ Py_XDECREF(_py_tmp); \
} while (0)