@@ -54,6 +54,7 @@ pathconfig_clear(_PyPathConfig *config)
5454 CLEAR (config -> program_full_path );
5555 CLEAR (config -> prefix );
5656 CLEAR (config -> exec_prefix );
57+ CLEAR (config -> stdlib_dir );
5758 CLEAR (config -> module_search_path );
5859 CLEAR (config -> program_name );
5960 CLEAR (config -> home );
@@ -83,6 +84,7 @@ pathconfig_copy(_PyPathConfig *config, const _PyPathConfig *config2)
8384 COPY_ATTR (prefix );
8485 COPY_ATTR (exec_prefix );
8586 COPY_ATTR (module_search_path );
87+ COPY_ATTR (stdlib_dir );
8688 COPY_ATTR (program_name );
8789 COPY_ATTR (home );
8890#ifdef MS_WINDOWS
@@ -167,6 +169,7 @@ pathconfig_set_from_config(_PyPathConfig *pathconfig, const PyConfig *config)
167169 COPY_CONFIG (program_full_path , executable );
168170 COPY_CONFIG (prefix , prefix );
169171 COPY_CONFIG (exec_prefix , exec_prefix );
172+ COPY_CONFIG (stdlib_dir , stdlib_dir );
170173 COPY_CONFIG (program_name , program_name );
171174 COPY_CONFIG (home , home );
172175#ifdef MS_WINDOWS
@@ -218,6 +221,7 @@ _PyPathConfig_AsDict(void)
218221 SET_ITEM_STR (prefix );
219222 SET_ITEM_STR (exec_prefix );
220223 SET_ITEM_STR (module_search_path );
224+ SET_ITEM_STR (stdlib_dir );
221225 SET_ITEM_STR (program_name );
222226 SET_ITEM_STR (home );
223227#ifdef MS_WINDOWS
@@ -311,6 +315,7 @@ config_init_module_search_paths(PyConfig *config, _PyPathConfig *pathconfig)
311315
312316 - exec_prefix
313317 - module_search_path
318+ - stdlib_dir
314319 - prefix
315320 - program_full_path
316321
@@ -401,6 +406,7 @@ config_init_pathconfig(PyConfig *config, int compute_path_config)
401406 COPY_ATTR (program_full_path , executable );
402407 COPY_ATTR (prefix , prefix );
403408 COPY_ATTR (exec_prefix , exec_prefix );
409+ COPY_ATTR (stdlib_dir , stdlib_dir );
404410
405411#undef COPY_ATTR
406412
@@ -486,16 +492,25 @@ Py_SetPath(const wchar_t *path)
486492
487493 PyMem_RawFree (_Py_path_config .prefix );
488494 PyMem_RawFree (_Py_path_config .exec_prefix );
495+ PyMem_RawFree (_Py_path_config .stdlib_dir );
489496 PyMem_RawFree (_Py_path_config .module_search_path );
490497
491498 _Py_path_config .prefix = _PyMem_RawWcsdup (L"" );
492499 _Py_path_config .exec_prefix = _PyMem_RawWcsdup (L"" );
500+ // XXX Copy this from the new module_search_path?
501+ if (_Py_path_config .home != NULL ) {
502+ _Py_path_config .stdlib_dir = _PyMem_RawWcsdup (_Py_path_config .home );
503+ }
504+ else {
505+ _Py_path_config .stdlib_dir = _PyMem_RawWcsdup (L"" );
506+ }
493507 _Py_path_config .module_search_path = _PyMem_RawWcsdup (path );
494508
495509 PyMem_SetAllocator (PYMEM_DOMAIN_RAW , & old_alloc );
496510
497511 if (_Py_path_config .prefix == NULL
498512 || _Py_path_config .exec_prefix == NULL
513+ || _Py_path_config .stdlib_dir == NULL
499514 || _Py_path_config .module_search_path == NULL )
500515 {
501516 path_out_of_memory (__func__ );
@@ -515,10 +530,13 @@ Py_SetPythonHome(const wchar_t *home)
515530
516531 PyMem_RawFree (_Py_path_config .home );
517532 _Py_path_config .home = _PyMem_RawWcsdup (home );
533+ if (_Py_path_config .home != NULL ) {
534+ _Py_path_config .stdlib_dir = _PyMem_RawWcsdup (home );
535+ }
518536
519537 PyMem_SetAllocator (PYMEM_DOMAIN_RAW , & old_alloc );
520538
521- if (_Py_path_config .home == NULL ) {
539+ if (_Py_path_config .home == NULL || _Py_path_config . stdlib_dir == NULL ) {
522540 path_out_of_memory (__func__ );
523541 }
524542}
@@ -572,6 +590,17 @@ Py_GetPath(void)
572590}
573591
574592
593+ wchar_t *
594+ _Py_GetStdlibDir (void )
595+ {
596+ wchar_t * stdlib_dir = _Py_path_config .stdlib_dir ;
597+ if (stdlib_dir != NULL && stdlib_dir [0 ] != L'\0' ) {
598+ return stdlib_dir ;
599+ }
600+ return NULL ;
601+ }
602+
603+
575604wchar_t *
576605Py_GetPrefix (void )
577606{
0 commit comments