@@ -54,6 +54,7 @@ pathconfig_clear(_PyPathConfig *config)
54
54
CLEAR (config -> program_full_path );
55
55
CLEAR (config -> prefix );
56
56
CLEAR (config -> exec_prefix );
57
+ CLEAR (config -> stdlib_dir );
57
58
CLEAR (config -> module_search_path );
58
59
CLEAR (config -> program_name );
59
60
CLEAR (config -> home );
@@ -83,6 +84,7 @@ pathconfig_copy(_PyPathConfig *config, const _PyPathConfig *config2)
83
84
COPY_ATTR (prefix );
84
85
COPY_ATTR (exec_prefix );
85
86
COPY_ATTR (module_search_path );
87
+ COPY_ATTR (stdlib_dir );
86
88
COPY_ATTR (program_name );
87
89
COPY_ATTR (home );
88
90
#ifdef MS_WINDOWS
@@ -167,6 +169,7 @@ pathconfig_set_from_config(_PyPathConfig *pathconfig, const PyConfig *config)
167
169
COPY_CONFIG (program_full_path , executable );
168
170
COPY_CONFIG (prefix , prefix );
169
171
COPY_CONFIG (exec_prefix , exec_prefix );
172
+ COPY_CONFIG (stdlib_dir , stdlib_dir );
170
173
COPY_CONFIG (program_name , program_name );
171
174
COPY_CONFIG (home , home );
172
175
#ifdef MS_WINDOWS
@@ -218,6 +221,7 @@ _PyPathConfig_AsDict(void)
218
221
SET_ITEM_STR (prefix );
219
222
SET_ITEM_STR (exec_prefix );
220
223
SET_ITEM_STR (module_search_path );
224
+ SET_ITEM_STR (stdlib_dir );
221
225
SET_ITEM_STR (program_name );
222
226
SET_ITEM_STR (home );
223
227
#ifdef MS_WINDOWS
@@ -311,6 +315,7 @@ config_init_module_search_paths(PyConfig *config, _PyPathConfig *pathconfig)
311
315
312
316
- exec_prefix
313
317
- module_search_path
318
+ - stdlib_dir
314
319
- prefix
315
320
- program_full_path
316
321
@@ -401,6 +406,7 @@ config_init_pathconfig(PyConfig *config, int compute_path_config)
401
406
COPY_ATTR (program_full_path , executable );
402
407
COPY_ATTR (prefix , prefix );
403
408
COPY_ATTR (exec_prefix , exec_prefix );
409
+ COPY_ATTR (stdlib_dir , stdlib_dir );
404
410
405
411
#undef COPY_ATTR
406
412
@@ -486,16 +492,25 @@ Py_SetPath(const wchar_t *path)
486
492
487
493
PyMem_RawFree (_Py_path_config .prefix );
488
494
PyMem_RawFree (_Py_path_config .exec_prefix );
495
+ PyMem_RawFree (_Py_path_config .stdlib_dir );
489
496
PyMem_RawFree (_Py_path_config .module_search_path );
490
497
491
498
_Py_path_config .prefix = _PyMem_RawWcsdup (L"" );
492
499
_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
+ }
493
507
_Py_path_config .module_search_path = _PyMem_RawWcsdup (path );
494
508
495
509
PyMem_SetAllocator (PYMEM_DOMAIN_RAW , & old_alloc );
496
510
497
511
if (_Py_path_config .prefix == NULL
498
512
|| _Py_path_config .exec_prefix == NULL
513
+ || _Py_path_config .stdlib_dir == NULL
499
514
|| _Py_path_config .module_search_path == NULL )
500
515
{
501
516
path_out_of_memory (__func__ );
@@ -515,10 +530,13 @@ Py_SetPythonHome(const wchar_t *home)
515
530
516
531
PyMem_RawFree (_Py_path_config .home );
517
532
_Py_path_config .home = _PyMem_RawWcsdup (home );
533
+ if (_Py_path_config .home != NULL ) {
534
+ _Py_path_config .stdlib_dir = _PyMem_RawWcsdup (home );
535
+ }
518
536
519
537
PyMem_SetAllocator (PYMEM_DOMAIN_RAW , & old_alloc );
520
538
521
- if (_Py_path_config .home == NULL ) {
539
+ if (_Py_path_config .home == NULL || _Py_path_config . stdlib_dir == NULL ) {
522
540
path_out_of_memory (__func__ );
523
541
}
524
542
}
@@ -572,6 +590,17 @@ Py_GetPath(void)
572
590
}
573
591
574
592
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
+
575
604
wchar_t *
576
605
Py_GetPrefix (void )
577
606
{
0 commit comments