mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
gh-99537: Use Py_SETREF(var, NULL) in C code (#99687)
Replace "Py_DECREF(var); var = NULL;" with "Py_SETREF(var, NULL);".
This commit is contained in:
parent
5d9183c7ad
commit
81f7359f67
22 changed files with 44 additions and 87 deletions
|
@ -67,8 +67,7 @@ PyFile_GetLine(PyObject *f, int n)
|
|||
}
|
||||
if (result != NULL && !PyBytes_Check(result) &&
|
||||
!PyUnicode_Check(result)) {
|
||||
Py_DECREF(result);
|
||||
result = NULL;
|
||||
Py_SETREF(result, NULL);
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"object.readline() returned non-string");
|
||||
}
|
||||
|
@ -77,8 +76,7 @@ PyFile_GetLine(PyObject *f, int n)
|
|||
const char *s = PyBytes_AS_STRING(result);
|
||||
Py_ssize_t len = PyBytes_GET_SIZE(result);
|
||||
if (len == 0) {
|
||||
Py_DECREF(result);
|
||||
result = NULL;
|
||||
Py_SETREF(result, NULL);
|
||||
PyErr_SetString(PyExc_EOFError,
|
||||
"EOF when reading a line");
|
||||
}
|
||||
|
@ -95,8 +93,7 @@ PyFile_GetLine(PyObject *f, int n)
|
|||
if (n < 0 && result != NULL && PyUnicode_Check(result)) {
|
||||
Py_ssize_t len = PyUnicode_GET_LENGTH(result);
|
||||
if (len == 0) {
|
||||
Py_DECREF(result);
|
||||
result = NULL;
|
||||
Py_SETREF(result, NULL);
|
||||
PyErr_SetString(PyExc_EOFError,
|
||||
"EOF when reading a line");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue