Skip to content

gh-99300: Use Py_NewRef() in Parser/ directory #99330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 10, 2022
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
6 changes: 2 additions & 4 deletions Parser/pegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions Parser/string_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions Parser/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>");
Expand Down
3 changes: 1 addition & 2 deletions Tools/peg_generator/peg_extension/peg_extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down