gh-99300: Use Py_NewRef() in Python/ directory (#99302)

Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and
Py_XNewRef() in C files of the Python/ directory.
This commit is contained in:
Victor Stinner 2022-11-10 09:03:39 +01:00 committed by GitHub
parent f883b7f8ee
commit d8f239d86e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 41 additions and 80 deletions

View file

@ -382,8 +382,7 @@ get_filter(PyInterpreterState *interp, PyObject *category,
action = get_default_action(interp);
if (action != NULL) {
Py_INCREF(Py_None);
*item = Py_None;
*item = Py_NewRef(Py_None);
return action;
}
@ -468,8 +467,7 @@ normalize_module(PyObject *filename)
module = PyUnicode_Substring(filename, 0, len-3);
}
else {
module = filename;
Py_INCREF(module);
module = Py_NewRef(filename);
}
return module;
}
@ -751,8 +749,7 @@ warn_explicit(PyThreadState *tstate, PyObject *category, PyObject *message,
goto cleanup;
return_none:
result = Py_None;
Py_INCREF(result);
result = Py_NewRef(Py_None);
cleanup:
Py_XDECREF(item);
@ -848,8 +845,7 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
}
else {
globals = f->f_frame->f_globals;
*filename = f->f_frame->f_code->co_filename;
Py_INCREF(*filename);
*filename = Py_NewRef(f->f_frame->f_code->co_filename);
*lineno = PyFrame_GetLineNumber(f);
Py_DECREF(f);
}