diff options
author | Christian Heimes <christian@python.org> | 2021-12-07 18:09:53 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-07 18:09:53 (GMT) |
commit | 06c4ae8b1380eec1c5f3cd8faa21102d1c940bab (patch) | |
tree | 7de8b45b260c0651dd2f6157af938bda4dde9809 /Modules | |
parent | 064e53d19aea6d6906fa8f7706a2556a2c293ccd (diff) | |
download | cpython-06c4ae8b1380eec1c5f3cd8faa21102d1c940bab.zip cpython-06c4ae8b1380eec1c5f3cd8faa21102d1c940bab.tar.gz cpython-06c4ae8b1380eec1c5f3cd8faa21102d1c940bab.tar.bz2 |
bpo-45582: Fix framework path and bootstrap build (GH-29954)
* Check NS API return values for NULL to prevent segfault in
``_bootstrap_python``.
* Set modPathInitialized to 1 so the ``decode_to_dict`` path is used.
Signed-off-by: Christian Heimes <christian@python.org>
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/getpath.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/Modules/getpath.c b/Modules/getpath.c index 9ce7260..0b982f1 100644 --- a/Modules/getpath.c +++ b/Modules/getpath.c @@ -754,12 +754,10 @@ library_to_dict(PyObject *dict, const char *key) if (PyWin_DLLhModule) { return winmodule_to_dict(dict, key, PyWin_DLLhModule); } -#elif defined(WITH_NEXT_FRAMEWORK) && !defined(PY_BOOTSTRAP_PYTHON) - // _bootstrap_python does not use framework and crashes +#elif defined(WITH_NEXT_FRAMEWORK) static char modPath[MAXPATHLEN + 1]; static int modPathInitialized = -1; if (modPathInitialized < 0) { - NSModule pythonModule; modPathInitialized = 0; /* On Mac OS X we have a special case if we're running from a framework. @@ -767,12 +765,17 @@ library_to_dict(PyObject *dict, const char *key) which is in the framework, not relative to the executable, which may be outside of the framework. Except when we're in the build directory... */ - pythonModule = NSModuleForSymbol(NSLookupAndBindSymbol("_Py_Initialize")); - - /* Use dylib functions to find out where the framework was loaded from */ - const char *path = NSLibraryNameForModule(pythonModule); - if (path) { - strncpy(modPath, path, MAXPATHLEN); + NSSymbol symbol = NSLookupAndBindSymbol("_Py_Initialize"); + if (symbol != NULL) { + NSModule pythonModule = NSModuleForSymbol(symbol); + if (pythonModule != NULL) { + /* Use dylib functions to find out where the framework was loaded from */ + const char *path = NSLibraryNameForModule(pythonModule); + if (path) { + strncpy(modPath, path, MAXPATHLEN); + modPathInitialized = 1; + } + } } } if (modPathInitialized > 0) { |