gh-99300: Use Py_NewRef() in Modules/ directory (#99468)

Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and
Py_XNewRef() in test C files of the Modules/ directory.
This commit is contained in:
Victor Stinner 2022-11-14 13:44:56 +01:00 committed by GitHub
parent 9a7e9f9921
commit c340cbb7f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 92 additions and 173 deletions

View file

@ -347,8 +347,8 @@ tracemalloc_get_frame(_PyInterpreterFrame *pyframe, frame_t *frame)
else {
/* tracemalloc_filenames is responsible to keep a reference
to the filename */
Py_INCREF(filename);
if (_Py_hashtable_set(tracemalloc_filenames, filename, NULL) < 0) {
if (_Py_hashtable_set(tracemalloc_filenames, Py_NewRef(filename),
NULL) < 0) {
Py_DECREF(filename);
#ifdef TRACE_DEBUG
tracemalloc_error("failed to intern the filename");
@ -1085,8 +1085,7 @@ frame_to_pyobject(frame_t *frame)
if (frame_obj == NULL)
return NULL;
Py_INCREF(frame->filename);
PyTuple_SET_ITEM(frame_obj, 0, frame->filename);
PyTuple_SET_ITEM(frame_obj, 0, Py_NewRef(frame->filename));
lineno_obj = PyLong_FromUnsignedLong(frame->lineno);
if (lineno_obj == NULL) {
@ -1107,8 +1106,7 @@ traceback_to_pyobject(traceback_t *traceback, _Py_hashtable_t *intern_table)
if (intern_table != NULL) {
frames = _Py_hashtable_get(intern_table, (const void *)traceback);
if (frames) {
Py_INCREF(frames);
return frames;
return Py_NewRef(frames);
}
}