diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2012-07-17 16:33:46 (GMT) |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2012-07-17 16:33:46 (GMT) |
commit | 90db661b4335eaf7a3cb5e9a4524ae9707eeaf76 (patch) | |
tree | b73b67deb7feab489b2f43d8cc43778e8ac8cb23 /Modules | |
parent | 11718620ef87268fae07ba0809fec63b9c6d15e3 (diff) | |
download | cpython-90db661b4335eaf7a3cb5e9a4524ae9707eeaf76.zip cpython-90db661b4335eaf7a3cb5e9a4524ae9707eeaf76.tar.gz cpython-90db661b4335eaf7a3cb5e9a4524ae9707eeaf76.tar.bz2 |
Closes #15307: symlinks now work on OS X with framework Python builds. Patch by Ronald Oussoren.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/getpath.c | 16 | ||||
-rw-r--r-- | Modules/main.c | 22 |
2 files changed, 34 insertions, 4 deletions
diff --git a/Modules/getpath.c b/Modules/getpath.c index b153197..b98c520 100644 --- a/Modules/getpath.c +++ b/Modules/getpath.c @@ -474,6 +474,7 @@ calculate_path(void) wchar_t *defpath; #ifdef WITH_NEXT_FRAMEWORK NSModule pythonModule; + const char* modPath; #endif #ifdef __APPLE__ #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 @@ -568,8 +569,8 @@ calculate_path(void) */ pythonModule = NSModuleForSymbol(NSLookupAndBindSymbol("_Py_Initialize")); /* Use dylib functions to find out where the framework was loaded from */ - buf = (wchar_t *)NSLibraryNameForModule(pythonModule); - if (buf != NULL) { + modPath = NSLibraryNameForModule(pythonModule); + if (modPath != NULL) { /* We're in a framework. */ /* See if we might be in the build directory. The framework in the ** build directory is incomplete, it only has the .dylib and a few @@ -578,7 +579,12 @@ calculate_path(void) ** be running the interpreter in the build directory, so we use the ** build-directory-specific logic to find Lib and such. */ - wcsncpy(argv0_path, buf, MAXPATHLEN); + wchar_t* wbuf = _Py_char2wchar(modPath, NULL); + if (wbuf == NULL) { + Py_FatalError("Cannot decode framework location"); + } + + wcsncpy(argv0_path, wbuf, MAXPATHLEN); reduce(argv0_path); joinpath(argv0_path, lib_python); joinpath(argv0_path, LANDMARK); @@ -589,8 +595,9 @@ calculate_path(void) } else { /* Use the location of the library as the progpath */ - wcsncpy(argv0_path, buf, MAXPATHLEN); + wcsncpy(argv0_path, wbuf, MAXPATHLEN); } + PyMem_Free(wbuf); } #endif @@ -629,6 +636,7 @@ calculate_path(void) FILE * env_file = NULL; wcscpy(tmpbuffer, argv0_path); + joinpath(tmpbuffer, env_cfg); env_file = _Py_wfopen(tmpbuffer, L"r"); if (env_file == NULL) { diff --git a/Modules/main.c b/Modules/main.c index 64bac6e..e86aa77 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -616,7 +616,29 @@ Py_Main(int argc, wchar_t **argv) Py_SetProgramName(buffer); /* buffer is now handed off - do not free */ } else { +#ifdef WITH_NEXT_FRAMEWORK + char* pyvenv_launcher = getenv("__PYVENV_LAUNCHER__"); + + if (pyvenv_launcher && *pyvenv_launcher) { + /* Used by Mac/Tools/pythonw.c to forward + * the argv0 of the stub executable + */ + wchar_t* wbuf = _Py_char2wchar(pyvenv_launcher, NULL); + + if (wbuf == NULL) { + Py_FatalError("Cannot decode __PYVENV_LAUNCHER__"); + } + Py_SetProgramName(wbuf); + + /* Don't free wbuf, the argument to Py_SetProgramName + * must remain valid until the Py_Finalize is called. + */ + } else { + Py_SetProgramName(argv[0]); + } +#else Py_SetProgramName(argv[0]); +#endif } #else Py_SetProgramName(argv[0]); |