mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Issue #26200: Added Py_SETREF and replaced Py_XSETREF with Py_SETREF
in places where Py_DECREF was used.
This commit is contained in:
commit
f01e408c16
23 changed files with 58 additions and 48 deletions
|
@ -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); \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue