mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +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
|
@ -824,8 +824,7 @@ PyWeakref_NewRef(PyObject *ob, PyObject *callback)
|
|||
during GC. Return that one instead of this one
|
||||
to avoid violating the invariants of the list
|
||||
of weakrefs for ob. */
|
||||
Py_DECREF(result);
|
||||
result = (PyWeakReference*)Py_NewRef(ref);
|
||||
Py_SETREF(result, (PyWeakReference*)Py_NewRef(ref));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -888,8 +887,7 @@ PyWeakref_NewProxy(PyObject *ob, PyObject *callback)
|
|||
during GC. Return that one instead of this one
|
||||
to avoid violating the invariants of the list
|
||||
of weakrefs for ob. */
|
||||
Py_DECREF(result);
|
||||
result = (PyWeakReference*)Py_NewRef(proxy);
|
||||
Py_SETREF(result, (PyWeakReference*)Py_NewRef(proxy));
|
||||
goto skip_insert;
|
||||
}
|
||||
prev = ref;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue