◐ Shell
clean mode source ↗

gh-119213: Fix getargs.c to store state in InterpreterState... by 1st1 · Pull Request #119195 · python/cpython

Conversation

@1st1

@1st1 1st1 commented

May 20, 2024

edited by bedevere-app Bot

Loading

...as opposed to storing it in PyRuntime. Storing it in PyRuntime
is fundametally wrong, as its state contains references to Python
objects. Those objects (tuples and strings) can (and will) be
picked by various subinterpreter clean up code, leaving PyRuntime
with broken pointers.

#119194 is a backport to 3.12

@ericsnowcurrently ericsnowcurrently changed the title Fix getargs.c to store state in InterpreterState... gh-119213: Fix getargs.c to store state in InterpreterState...

May 20, 2024

erlend-aasland

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; perhaps it would make sense to init getargs state just after _PyGC_Init, but I'm not sure it matters; I'll leave that kind of nitpicking to Eric :)

@colesbury

How does this work when the _PyArg_Parser instances are themselves declared as static variables (and are global to the process)? For example:

static _PyArg_Parser _parser = {
.keywords = _keywords,
.fname = "Struct",
.kwtuple = KWTUPLE,
};

vstinner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ericsnowcurrently

@colesbury, I'm looking into what's going on. Basically, the statically declared tuple is only for builtin modules. I have a solution that's different from Yury's but want to be sure it's correct before closing this one.

@ericsnowcurrently

Labels