@@ -380,64 +380,51 @@ static int
380380pymain_run_startup (PyConfig * config , PyCompilerFlags * cf , int * exitcode )
381381{
382382 int ret ;
383- PyObject * startup_obj = NULL ;
384383 if (!config -> use_environment ) {
385384 return 0 ;
386385 }
386+ PyObject * startup = NULL ;
387387#ifdef MS_WINDOWS
388- const wchar_t * wstartup = _wgetenv (L"PYTHONSTARTUP" );
389- if (wstartup == NULL || wstartup [0 ] == L'\0' ) {
388+ const wchar_t * env = _wgetenv (L"PYTHONSTARTUP" );
389+ if (env == NULL || env [0 ] == L'\0' ) {
390390 return 0 ;
391391 }
392- PyObject * startup_bytes = NULL ;
393- startup_obj = PyUnicode_FromWideChar (wstartup , wcslen (wstartup ));
394- if (startup_obj == NULL ) {
395- goto error ;
396- }
397- startup_bytes = PyUnicode_EncodeFSDefault (startup_obj );
398- if (startup_bytes == NULL ) {
392+ startup = PyUnicode_FromWideChar (env , wcslen (env ));
393+ if (startup == NULL ) {
399394 goto error ;
400395 }
401- const char * startup = PyBytes_AS_STRING (startup_bytes );
402396#else
403- const char * startup = _Py_GetEnv (config -> use_environment , "PYTHONSTARTUP" );
404- if (startup == NULL ) {
397+ const char * env = _Py_GetEnv (config -> use_environment , "PYTHONSTARTUP" );
398+ if (env == NULL ) {
405399 return 0 ;
406400 }
407- startup_obj = PyUnicode_DecodeFSDefault (startup );
408- if (startup_obj == NULL ) {
401+ startup = PyUnicode_DecodeFSDefault (env );
402+ if (startup == NULL ) {
409403 goto error ;
410404 }
411405#endif
412- if (PySys_Audit ("cpython.run_startup" , "O" , startup_obj ) < 0 ) {
406+ if (PySys_Audit ("cpython.run_startup" , "O" , startup ) < 0 ) {
413407 goto error ;
414408 }
415409
416- #ifdef MS_WINDOWS
417- FILE * fp = _Py_wfopen (wstartup , L"r" );
418- #else
419- FILE * fp = _Py_fopen (startup , "r" );
420- #endif
410+ FILE * fp = _Py_fopen_obj (startup , "r" );
421411 if (fp == NULL ) {
422412 int save_errno = errno ;
423413 PyErr_Clear ();
424414 PySys_WriteStderr ("Could not open PYTHONSTARTUP\n" );
425415
426416 errno = save_errno ;
427- PyErr_SetFromErrnoWithFilenameObjects (PyExc_OSError , startup_obj , NULL );
417+ PyErr_SetFromErrnoWithFilenameObjects (PyExc_OSError , startup , NULL );
428418 goto error ;
429419 }
430420
431- (void ) PyRun_SimpleFileExFlags (fp , startup , 0 , cf );
421+ (void ) _PyRun_SimpleFileObject (fp , startup , 0 , cf );
432422 PyErr_Clear ();
433423 fclose (fp );
434424 ret = 0 ;
435425
436426done :
437- #ifdef MS_WINDOWS
438- Py_XDECREF (startup_bytes );
439- #endif
440- Py_XDECREF (startup_obj );
427+ Py_XDECREF (startup );
441428 return ret ;
442429
443430error :
0 commit comments