diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-04-10 15:12:01 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-04-10 15:12:01 (GMT) |
commit | f01e408c1688a207eba18444da8c151c872fba59 (patch) | |
tree | 3330812d856579add4526f10d5284164a15b6037 /Include | |
parent | 47c5474aa0cbe8dc3cf2c370b19769edd3f2e8d8 (diff) | |
parent | 57a01d3a0ee20ee9eea69b658c6bac0f39541625 (diff) | |
download | cpython-f01e408c1688a207eba18444da8c151c872fba59.zip cpython-f01e408c1688a207eba18444da8c151c872fba59.tar.gz cpython-f01e408c1688a207eba18444da8c151c872fba59.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')
-rw-r--r-- | Include/object.h | 14 |
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); \ |