Skip to content

Commit 3d55aa9

Browse files
authored
bpo-42923: Fix _Py_DumpExtensionModules() for NULL sysdict (GH-25262)
Fix Py_FatalError() is called before interp->sysdict is set.
1 parent d27f8d2 commit 3d55aa9

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Python/pylifecycle.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2551,12 +2551,14 @@ _Py_DumpExtensionModules(int fd, PyInterpreterState *interp)
25512551
// memory cannot be allocated on the heap in a signal handler.
25522552
// Iterate on the dict instead.
25532553
PyObject *stdlib_module_names = NULL;
2554-
pos = 0;
2555-
while (PyDict_Next(interp->sysdict, &pos, &key, &value)) {
2556-
if (PyUnicode_Check(key)
2557-
&& PyUnicode_CompareWithASCIIString(key, "stdlib_module_names") == 0) {
2558-
stdlib_module_names = value;
2559-
break;
2554+
if (interp->sysdict != NULL) {
2555+
pos = 0;
2556+
while (PyDict_Next(interp->sysdict, &pos, &key, &value)) {
2557+
if (PyUnicode_Check(key)
2558+
&& PyUnicode_CompareWithASCIIString(key, "stdlib_module_names") == 0) {
2559+
stdlib_module_names = value;
2560+
break;
2561+
}
25602562
}
25612563
}
25622564
// If we failed to get sys.stdlib_module_names or it's not a frozenset,

0 commit comments

Comments
 (0)