]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-99300: Use Py_NewRef() in Parser/ directory (#99330)
authorVictor Stinner <vstinner@python.org>
Thu, 10 Nov 2022 14:30:05 +0000 (15:30 +0100)
committerGitHub <noreply@github.com>
Thu, 10 Nov 2022 14:30:05 +0000 (15:30 +0100)
Replace Py_INCREF() with Py_NewRef() in C files of the Parser/
directory and in the PEG generator.

Parser/pegen.c
Parser/string_parser.c
Parser/tokenizer.c
Tools/peg_generator/peg_extension/peg_extension.c

index 1317606749b8c0d1e8d477afdf026d94e351dc68..d34a86e9c883de9a053189fda3e73cd02a7370b7 100644 (file)
@@ -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;
index e13272c17ca301755b7c289edc315306a4eef011..c096bea7426e5c5680284778648885610e8793ff 100644 (file)
@@ -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,
index 1c356d3d47c94598e60de8b012f63292c1fa594a..f2131cf39b38da323768ac37c1d36a3509b8deac 100644 (file)
@@ -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("<string>");
index 3ebb7bdd9b38c9628608a4c2c2e76e482dc1e602..7df134b5ade8bbeb62927fca0d6a3126caa3ef23 100644 (file)
@@ -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;