File tree Expand file tree Collapse file tree 4 files changed +50
-0
lines changed Expand file tree Collapse file tree 4 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,8 @@ PyAPI_FUNC(void) Py_SetPythonHome(const wchar_t *);
44
44
PyAPI_FUNC (wchar_t * ) Py_GetPythonHome (void );
45
45
46
46
#ifndef Py_LIMITED_API
47
+ PyAPI_FUNC (void ) _Py_SetProgramFullPath (const wchar_t * );
48
+
47
49
/* Only used by applications that embed the interpreter and need to
48
50
* override the standard encoding determination mechanism
49
51
*/
Original file line number Diff line number Diff line change
1
+ Adds _Py_SetProgramFullPath so embedders may override sys.executable
Original file line number Diff line number Diff line change @@ -1206,6 +1206,25 @@ config_init_program_name(_PyCoreConfig *config)
1206
1206
}
1207
1207
1208
1208
1209
+ static _PyInitError
1210
+ config_init_executable (_PyCoreConfig * config )
1211
+ {
1212
+ assert (config -> executable == NULL );
1213
+
1214
+ /* If Py_SetProgramFullPath() was called, use its value */
1215
+ const wchar_t * program_full_path = _Py_path_config .program_full_path ;
1216
+ if (program_full_path != NULL ) {
1217
+ config -> executable = _PyMem_RawWcsdup (program_full_path );
1218
+ if (config -> executable == NULL ) {
1219
+ return _Py_INIT_NO_MEMORY ();
1220
+ }
1221
+ return _Py_INIT_OK ();
1222
+ }
1223
+
1224
+ return _Py_INIT_OK ();
1225
+ }
1226
+
1227
+
1209
1228
static void
1210
1229
pymain_header (_PyMain * pymain )
1211
1230
{
@@ -2350,6 +2369,13 @@ _PyCoreConfig_Read(_PyCoreConfig *config)
2350
2369
}
2351
2370
}
2352
2371
2372
+ if (config -> executable == NULL ) {
2373
+ err = config_init_executable (config );
2374
+ if (_Py_INIT_FAILED (err )) {
2375
+ return err ;
2376
+ }
2377
+ }
2378
+
2353
2379
if (config -> utf8_mode < 0 || config -> coerce_c_locale < 0 ) {
2354
2380
config_init_locale (config );
2355
2381
}
Original file line number Diff line number Diff line change @@ -205,6 +205,27 @@ Py_SetProgramName(const wchar_t *program_name)
205
205
}
206
206
207
207
208
+ void
209
+ _Py_SetProgramFullPath (const wchar_t * program_full_path )
210
+ {
211
+ if (program_full_path == NULL || program_full_path [0 ] == L'\0' ) {
212
+ return ;
213
+ }
214
+
215
+ PyMemAllocatorEx old_alloc ;
216
+ _PyMem_SetDefaultAllocator (PYMEM_DOMAIN_RAW , & old_alloc );
217
+
218
+ PyMem_RawFree (_Py_path_config .program_full_path );
219
+ _Py_path_config .program_full_path = _PyMem_RawWcsdup (program_full_path );
220
+
221
+ PyMem_SetAllocator (PYMEM_DOMAIN_RAW , & old_alloc );
222
+
223
+ if (_Py_path_config .program_full_path == NULL ) {
224
+ Py_FatalError ("Py_SetProgramFullPath() failed: out of memory" );
225
+ }
226
+ }
227
+
228
+
208
229
wchar_t *
209
230
Py_GetPath (void )
210
231
{
You can’t perform that action at this time.
0 commit comments