mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
gh-99537: Use Py_SETREF() function in C code (#99656)
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
135ec7cefb
commit
7e3f09cad9
20 changed files with 37 additions and 89 deletions
|
@ -6247,13 +6247,10 @@ datetime_astimezone(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
|
|||
}
|
||||
else {
|
||||
/* Result is already aware - just replace tzinfo. */
|
||||
temp = result->tzinfo;
|
||||
result->tzinfo = Py_NewRef(PyDateTime_TimeZone_UTC);
|
||||
Py_DECREF(temp);
|
||||
Py_SETREF(result->tzinfo, Py_NewRef(PyDateTime_TimeZone_UTC));
|
||||
}
|
||||
|
||||
/* Attach new tzinfo and let fromutc() do the rest. */
|
||||
temp = result->tzinfo;
|
||||
if (tzinfo == Py_None) {
|
||||
tzinfo = local_timezone(result);
|
||||
if (tzinfo == NULL) {
|
||||
|
@ -6263,8 +6260,7 @@ datetime_astimezone(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
|
|||
}
|
||||
else
|
||||
Py_INCREF(tzinfo);
|
||||
result->tzinfo = tzinfo;
|
||||
Py_DECREF(temp);
|
||||
Py_SETREF(result->tzinfo, tzinfo);
|
||||
|
||||
temp = (PyObject *)result;
|
||||
result = (PyDateTime_DateTime *)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue