Skip to content

Commit

Permalink
Update Py_SETREF() to fix gh-98724
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Nov 9, 2022
1 parent dda2c76 commit afd077e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Changelog
=========

* 2022-11-09: Fix ``Py_SETREF()`` and ``Py_XSETREF()`` macros
for `gh-98724 <https://github.com/python/cpython/issues/98724>`_.
* 2022-11-04: Add ``PyFrame_GetVar()`` and ``PyFrame_GetVarString()``
functions.
* 2022-08-04: Add ``PyCode_GetVarnames()``, ``PyCode_GetFreevars()``
Expand Down
22 changes: 12 additions & 10 deletions pythoncapi_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,20 @@ _Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt)
// Py_SETREF() and Py_XSETREF() were added to Python 3.5.2.
// It is excluded from the limited C API.
#if (PY_VERSION_HEX < 0x03050200 && !defined(Py_SETREF)) && !defined(Py_LIMITED_API)
#define Py_SETREF(op, op2) \
do { \
PyObject *_py_tmp = _PyObject_CAST(op); \
(op) = (op2); \
Py_DECREF(_py_tmp); \
#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); \
} while (0)

#define Py_XSETREF(op, op2) \
do { \
PyObject *_py_tmp = _PyObject_CAST(op); \
(op) = (op2); \
Py_XDECREF(_py_tmp); \
#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); \
} while (0)
#endif

Expand Down

0 comments on commit afd077e

Please sign in to comment.