mirror of
https://github.com/python/cpython.git
synced 2025-11-01 02:38:53 +00:00
Revert "gh-98724: Fix Py_CLEAR() macro side effects" (#99737)
Revert "gh-98724: Fix Py_CLEAR() macro side effects (#99100)"
This reverts commit c03e05c2e7.
This commit is contained in:
parent
0da728387c
commit
3a803bcaac
5 changed files with 29 additions and 172 deletions
|
|
@ -598,21 +598,16 @@ static inline void Py_DECREF(PyObject *op)
|
|||
* one of those can't cause problems -- but in part that relies on that
|
||||
* Python integers aren't currently weakly referencable. Best practice is
|
||||
* to use Py_CLEAR() even if you can't think of a reason for why you need to.
|
||||
*
|
||||
* gh-98724: Use the _py_tmp_ptr variable to evaluate the macro argument
|
||||
* exactly once, to prevent the duplication of side effects in this macro.
|
||||
*/
|
||||
#define Py_CLEAR(op) \
|
||||
do { \
|
||||
PyObject **_py_tmp_ptr = _Py_CAST(PyObject**, &(op)); \
|
||||
if (*_py_tmp_ptr != NULL) { \
|
||||
PyObject* _py_tmp = (*_py_tmp_ptr); \
|
||||
*_py_tmp_ptr = NULL; \
|
||||
Py_DECREF(_py_tmp); \
|
||||
} \
|
||||
#define Py_CLEAR(op) \
|
||||
do { \
|
||||
PyObject *_py_tmp = _PyObject_CAST(op); \
|
||||
if (_py_tmp != NULL) { \
|
||||
(op) = NULL; \
|
||||
Py_DECREF(_py_tmp); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
/* Function to use in case the object pointer can be NULL: */
|
||||
static inline void Py_XINCREF(PyObject *op)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue