mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
gh-99537: Use Py_SETREF() function in C code (#99657)
Fix potential race condition in code patterns: * Replace "Py_DECREF(var); var = new;" with "Py_SETREF(var, new);" * Replace "Py_XDECREF(var); var = new;" with "Py_XSETREF(var, new);" * Replace "Py_CLEAR(var); var = new;" with "Py_XSETREF(var, new);" Other changes: * Replace "old = var; var = new; Py_DECREF(var)" with "Py_SETREF(var, new);" * Replace "old = var; var = new; Py_XDECREF(var)" with "Py_XSETREF(var, new);" * And remove the "old" variable.
This commit is contained in:
parent
3db0a21f73
commit
135ec7cefb
19 changed files with 34 additions and 76 deletions
|
@ -136,9 +136,7 @@ tb_next_set(PyTracebackObject *self, PyObject *new_next, void *Py_UNUSED(_))
|
|||
cursor = cursor->tb_next;
|
||||
}
|
||||
|
||||
PyObject *old_next = (PyObject*)self->tb_next;
|
||||
self->tb_next = (PyTracebackObject *)Py_XNewRef(new_next);
|
||||
Py_XDECREF(old_next);
|
||||
Py_XSETREF(self->tb_next, (PyTracebackObject *)Py_XNewRef(new_next));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -533,8 +531,7 @@ display_source_line_with_margin(PyObject *f, PyObject *filename, int lineno, int
|
|||
PyObject *truncated;
|
||||
truncated = PyUnicode_Substring(lineobj, i, PyUnicode_GET_LENGTH(lineobj));
|
||||
if (truncated) {
|
||||
Py_DECREF(lineobj);
|
||||
lineobj = truncated;
|
||||
Py_SETREF(lineobj, truncated);
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue