mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +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
|
@ -13572,8 +13572,7 @@ _PyUnicode_FormatLong(PyObject *val, int alt, int prec, int type)
|
|||
for (i = 0; i < numdigits; i++)
|
||||
*b1++ = *buf++;
|
||||
*b1 = '\0';
|
||||
Py_DECREF(result);
|
||||
result = r1;
|
||||
Py_SETREF(result, r1);
|
||||
buf = PyBytes_AS_STRING(result);
|
||||
len = numnondigits + prec;
|
||||
}
|
||||
|
@ -13590,8 +13589,7 @@ _PyUnicode_FormatLong(PyObject *val, int alt, int prec, int type)
|
|||
|| buf != PyUnicode_DATA(result)) {
|
||||
PyObject *unicode;
|
||||
unicode = _PyUnicode_FromASCII(buf, len);
|
||||
Py_DECREF(result);
|
||||
result = unicode;
|
||||
Py_SETREF(result, unicode);
|
||||
}
|
||||
else if (len != PyUnicode_GET_LENGTH(result)) {
|
||||
if (PyUnicode_Resize(&result, len) < 0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue