mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +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
|
@ -168,8 +168,7 @@ builtin___build_class__(PyObject *self, PyObject *const *args, Py_ssize_t nargs,
|
|||
goto error;
|
||||
}
|
||||
if (winner != meta) {
|
||||
Py_DECREF(meta);
|
||||
meta = Py_NewRef(winner);
|
||||
Py_SETREF(meta, Py_NewRef(winner));
|
||||
}
|
||||
}
|
||||
/* else: meta is not a class, so we cannot do the metaclass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue