8000 gh-90928: Statically Initialize the Keywords Tuple in Clinic-Generated Code by ericsnowcurrently · Pull Request #95860 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-90928: Statically Initialize the Keywords Tuple in Clinic-Generated Code #95860

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
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add an explicit "initialized" field.
  • Loading branch information
ericsnowcurrently committed Aug 10, 2022
commit 698c35a38a6cbe1efd46a696851760be9da8a0ad
1 change: 1 addition & 0 deletions Include/cpython/modsupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ PyAPI_FUNC(PyObject **) _Py_VaBuildStack(
Py_ssize_t *p_nargs);

typedef struct _PyArg_Parser {
int initialized;
const char *format;
const char * const *keywords;
const char *fname;
Expand Down
10 changes: 9 additions & 1 deletion Python/getargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1983,9 +1983,16 @@ parser_init(struct _PyArg_Parser *parser)

keywords = parser->keywords;
assert(keywords != NULL);
if (parser->kwtuple != NULL) {

if (parser->initialized) {
return 1;
}
assert(parser->pos == 0 &&
(parser->format == NULL || parser->fname == NULL) &&
parser->custom_msg == NULL &&
parser->min == 0 &&
parser->max == 0 &&
parser->kwtuple == NULL);

if (scan_keywords(keywords, &len, &pos) < 0) {
return 0;
Expand All @@ -2005,6 +2012,7 @@ parser_init(struct _PyArg_Parser *parser)
parser->min = min;
parser->max = max;
parser->kwtuple = kwtuple;
parser->initialized = 1;

assert(parser->next == NULL);
parser->next = static_arg_parsers;
Expand Down
0