From 4ce2a202c7b573edaa0ee4a2315d5578f66737c5 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 10 Nov 2022 15:30:05 +0100 Subject: gh-99300: Use Py_NewRef() in Parser/ directory (#99330) Replace Py_INCREF() with Py_NewRef() in C files of the Parser/ directory and in the PEG generator. --- Parser/pegen.c | 6 ++---- Parser/string_parser.c | 4 +--- Parser/tokenizer.c | 3 +-- Tools/peg_generator/peg_extension/peg_extension.c | 3 +-- 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/Parser/pegen.c b/Parser/pegen.c index 1317606..d34a86e 100644 --- a/Parser/pegen.c +++ b/Parser/pegen.c @@ -885,8 +885,7 @@ _PyPegen_run_parser_from_file_pointer(FILE *fp, int start_rule, PyObject *filena tok->fp_interactive = 1; } // This transfers the ownership to the tokenizer - tok->filename = filename_ob; - Py_INCREF(filename_ob); + tok->filename = Py_NewRef(filename_ob); // From here on we need to clean up even if there's an error mod_ty result = NULL; @@ -925,8 +924,7 @@ _PyPegen_run_parser_from_string(const char *str, int start_rule, PyObject *filen return NULL; } // This transfers the ownership to the tokenizer - tok->filename = filename_ob; - Py_INCREF(filename_ob); + tok->filename = Py_NewRef(filename_ob); // We need to clear up from here on mod_ty result = NULL; diff --git a/Parser/string_parser.c b/Parser/string_parser.c index e13272c..c096bea 100644 --- a/Parser/string_parser.c +++ b/Parser/string_parser.c @@ -417,9 +417,7 @@ fstring_compile_expr(Parser *p, const char *expr_start, const char *expr_end, PyMem_Free(str); return NULL; } - Py_INCREF(p->tok->filename); - - tok->filename = p->tok->filename; + tok->filename = Py_NewRef(p->tok->filename); tok->lineno = t->lineno + lines - 1; Parser *p2 = _PyPegen_Parser_New(tok, Py_fstring_input, p->flags, p->feature_version, diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 1c356d3..f2131cf 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -2223,8 +2223,7 @@ _PyTokenizer_FindEncodingFilename(int fd, PyObject *filename) return NULL; } if (filename != NULL) { - Py_INCREF(filename); - tok->filename = filename; + tok->filename = Py_NewRef(filename); } else { tok->filename = PyUnicode_FromString(""); diff --git a/Tools/peg_generator/peg_extension/peg_extension.c b/Tools/peg_generator/peg_extension/peg_extension.c index 3ebb7bd..7df134b 100644 --- a/Tools/peg_generator/peg_extension/peg_extension.c +++ b/Tools/peg_generator/peg_extension/peg_extension.c @@ -12,8 +12,7 @@ _build_return_object(mod_ty module, int mode, PyObject *filename_ob, PyArena *ar } else if (mode == 1) { result = PyAST_mod2obj(module); } else { - result = Py_None; - Py_INCREF(result); + result = Py_NewRef(Py_None); } return result; -- cgit v0.12