-
- Notifications
You must be signed in to change notification settings - Fork 33.1k
Closed
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
The macro Py_CLEAR(op)
references the argument op
two times. If the macro is called with an expression it will be evaluated two times, for example Py_CLEAR(p++)
.
Your environment
x86_64
- CPython versions tested on:
Python 3.7m - Operating system and architecture:
Debian Stable
I suggest a fix similar to this (old version commented out with #if 0):
#if 0 #define Py_CLEAR(op) \ do { \ PyObject *_py_tmp = (PyObject *)(op); \ if (_py_tmp != NULL) { \ (op) = NULL; \ Py_DECREF(_py_tmp); \ } \ } while (0) #else #define Py_CLEAR(op) \ do { \ PyObject **_py_tmp = (PyObject **)&(op); \ if (*_py_tmp != NULL) { \ PyObject *_py_tmp2 = *_py_tmp; \ (*_py_tmp) = NULL; \ Py_DECREF(_py_tmp2); \ } \ } while (0) #endif
I am not sure if this has happened anywhere, but I see a possible problem here. I think the compiler will optimize out the additional temporary variable in most cases.
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error