Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gh-99537: Use Py_CLEAR() function in C code
Replace "Py_XDECREF(var); var = NULL;" with "Py_CLEAR(var);".

Don't replace "Py_DECREF(var); var = NULL;" with "Py_CLEAR(var);". It
would add an useless "if (var)" test in code path where var cannot be
NULL.
  • Loading branch information
vstinner committed Nov 22, 2022
commit 93ff43791991b978c8c51be206c22eb3ed3de593
3 changes: 1 addition & 2 deletions Modules/_xxsubinterpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2383,8 +2383,7 @@ channel_list_interpreters(PyObject *self, PyObject *args, PyObject *kwds)
goto finally;

except:
Py_XDECREF(ids);
ids = NULL;
Py_CLEAR(ids);

finally:
return ids;
Expand Down
14 changes: 4 additions & 10 deletions Modules/_zoneinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ zoneinfo_new_instance(PyTypeObject *type, PyObject *key)

goto cleanup;
error:
Py_XDECREF(self);
self = NULL;
Py_CLEAR(self);
cleanup:
if (file_obj != NULL) {
PyObject *exc, *val, *tb;
Expand Down Expand Up @@ -2606,14 +2605,9 @@ static PyMethodDef module_methods[] = {{NULL, NULL}};
static void
module_free(void *m)
{
Py_XDECREF(_tzpath_find_tzfile);
_tzpath_find_tzfile = NULL;

Py_XDECREF(_common_mod);
_common_mod = NULL;

Py_XDECREF(io_open);
io_open = NULL;
Py_CLEAR(_tzpath_find_tzfile);
Py_CLEAR(_common_mod);
Py_CLEAR(io_open);

xdecref_ttinfo(&NO_TTINFO);

Expand Down