summaryrefslogtreecommitdiffstats
path: root/Objects/fileobject.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-11-23 13:57:50 (GMT)
committerGitHub <noreply@github.com>2022-11-23 13:57:50 (GMT)
commit81f7359f67a7166d57a10a3d5366406d9c85f1de (patch)
treef72a35747fa77ab9c63ba70ef9e1620daddf0cc3 /Objects/fileobject.c
parent5d9183c7ad68eb9ddb53d54a3f9a27e29dbabf31 (diff)
downloadcpython-81f7359f67a7166d57a10a3d5366406d9c85f1de.zip
cpython-81f7359f67a7166d57a10a3d5366406d9c85f1de.tar.gz
cpython-81f7359f67a7166d57a10a3d5366406d9c85f1de.tar.bz2
gh-99537: Use Py_SETREF(var, NULL) in C code (#99687)
Replace "Py_DECREF(var); var = NULL;" with "Py_SETREF(var, NULL);".
Diffstat (limited to 'Objects/fileobject.c')
-rw-r--r--Objects/fileobject.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index bf56be5..e99e155 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -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");
}