diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2024-03-22 00:20:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-22 00:20:20 (GMT) |
commit | b3d25df8d38b79310587da54dbd88b06a16d4904 (patch) | |
tree | 1daf220306410c2485f0bcfee557ddb0fce5022d /Python/frozenmain.c | |
parent | c4bf58a14f162557038a1535ca22c52b49d81d7b (diff) | |
download | cpython-b3d25df8d38b79310587da54dbd88b06a16d4904.zip cpython-b3d25df8d38b79310587da54dbd88b06a16d4904.tar.gz cpython-b3d25df8d38b79310587da54dbd88b06a16d4904.tar.bz2 |
gh-105716: Fix _PyInterpreterState_IsRunningMain() For Embedders (gh-117140)
When I added _PyInterpreterState_IsRunningMain() and friends last year, I tried to accommodate applications that embed Python but don't call _PyInterpreterState_SetRunningMain() (not that they're expected to). That mostly worked fine until my recent changes in gh-117049, where the subtleties with the fallback code led to failures; the change ended up breaking test_tools.test_freeze, which exercises a basic embedding situation.
The simplest fix is to drop the fallback code I originally added to _PyInterpreterState_IsRunningMain() (and later to _PyThreadState_IsRunningMain()). I've kept the fallback in the _xxsubinterpreters module though. I've also updated Py_FrozenMain() to call _PyInterpreterState_SetRunningMain().
Diffstat (limited to 'Python/frozenmain.c')
-rw-r--r-- | Python/frozenmain.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Python/frozenmain.c b/Python/frozenmain.c index 3ce9476..ec4566b 100644 --- a/Python/frozenmain.c +++ b/Python/frozenmain.c @@ -54,6 +54,12 @@ Py_FrozenMain(int argc, char **argv) Py_ExitStatusException(status); } + PyInterpreterState *interp = PyInterpreterState_Get(); + if (_PyInterpreterState_SetRunningMain(interp) < 0) { + PyErr_Print(); + exit(1); + } + #ifdef MS_WINDOWS PyWinFreeze_ExeInit(); #endif @@ -83,6 +89,9 @@ Py_FrozenMain(int argc, char **argv) #ifdef MS_WINDOWS PyWinFreeze_ExeTerm(); #endif + + _PyInterpreterState_SetNotRunningMain(interp); + if (Py_FinalizeEx() < 0) { sts = 120; } |