mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
* Revert "bpo-32197: Try to fix a compiler error on OS X introduced in bpo-32030. (#4681)" This reverts commit13badcbc60
. Re-apply commits: * "bpo-32030: _PyPathConfig_Init() sets home and program_name (#4673)" commitaf5a895073
. * "bpo-32030: Fix config_get_program_name() on macOS (#4669)" commite23c06e2b0
. * "bpo-32030: Add Python/pathconfig.c (#4668)" commit0ea395ae96
. * "bpo-32030: Don't call _PyPathConfig_Fini() in Py_FinalizeEx() (#4667)" commitebac19dad6
. * "bpo-32030: Fix Py_GetPath(): init program_name (#4665)" commit9ac3d88827
. * Fix compilation error on macOS
This commit is contained in:
parent
70d56fb525
commit
31a8393cf6
12 changed files with 455 additions and 424 deletions
|
@ -804,7 +804,12 @@ _PyMainInterpreterConfig_Read(_PyMainInterpreterConfig *config)
|
|||
}
|
||||
|
||||
if (config->program_name == NULL) {
|
||||
config->program_name = _PyMem_RawWcsdup(Py_GetProgramName());
|
||||
#ifdef MS_WINDOWS
|
||||
const wchar_t *program_name = L"python";
|
||||
#else
|
||||
const wchar_t *program_name = L"python3";
|
||||
#endif
|
||||
config->program_name = _PyMem_RawWcsdup(program_name);
|
||||
if (config->program_name == NULL) {
|
||||
return _Py_INIT_NO_MEMORY();
|
||||
}
|
||||
|
@ -1273,8 +1278,6 @@ Py_FinalizeEx(void)
|
|||
|
||||
call_ll_exitfuncs();
|
||||
|
||||
_PyPathConfig_Fini();
|
||||
|
||||
_PyRuntime_Finalize();
|
||||
return status;
|
||||
}
|
||||
|
@ -1491,61 +1494,6 @@ Py_EndInterpreter(PyThreadState *tstate)
|
|||
PyInterpreterState_Delete(interp);
|
||||
}
|
||||
|
||||
#ifdef MS_WINDOWS
|
||||
static wchar_t *progname = L"python";
|
||||
#else
|
||||
static wchar_t *progname = L"python3";
|
||||
#endif
|
||||
|
||||
void
|
||||
Py_SetProgramName(wchar_t *pn)
|
||||
{
|
||||
if (pn && *pn)
|
||||
progname = pn;
|
||||
}
|
||||
|
||||
wchar_t *
|
||||
Py_GetProgramName(void)
|
||||
{
|
||||
return progname;
|
||||
}
|
||||
|
||||
static wchar_t *default_home = NULL;
|
||||
|
||||
void
|
||||
Py_SetPythonHome(wchar_t *home)
|
||||
{
|
||||
default_home = home;
|
||||
}
|
||||
|
||||
|
||||
wchar_t*
|
||||
Py_GetPythonHome(void)
|
||||
{
|
||||
/* Use a static buffer to avoid heap memory allocation failure.
|
||||
Py_GetPythonHome() doesn't allow to report error, and the caller
|
||||
doesn't release memory. */
|
||||
static wchar_t buffer[MAXPATHLEN+1];
|
||||
|
||||
if (default_home) {
|
||||
return default_home;
|
||||
}
|
||||
|
||||
char *home = Py_GETENV("PYTHONHOME");
|
||||
if (!home) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t size = Py_ARRAY_LENGTH(buffer);
|
||||
size_t r = mbstowcs(buffer, home, size);
|
||||
if (r == (size_t)-1 || r >= size) {
|
||||
/* conversion failed or the static buffer is too small */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/* Add the __main__ module */
|
||||
|
||||
static _PyInitError
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue