@@ -1658,7 +1658,7 @@ _PyCoreConfig_AsDict(const _PyCoreConfig *config)
16581658/* --- _PyCmdline ------------------------------------------------- */
16591659
16601660typedef struct {
1661- _PyWstrList argv ;
1661+ _PyPreCmdline precmdline ;
16621662 _PyWstrList warnoptions ; /* Command line -W options */
16631663 _PyWstrList env_warnoptions ; /* PYTHONWARNINGS environment variables */
16641664 int print_help ; /* -h, -? options */
@@ -1669,9 +1669,9 @@ typedef struct {
16691669static void
16701670cmdline_clear (_PyCmdline * cmdline )
16711671{
1672+ _PyPreCmdline_Clear (& cmdline -> precmdline );
16721673 _PyWstrList_Clear (& cmdline -> warnoptions );
16731674 _PyWstrList_Clear (& cmdline -> env_warnoptions );
1674- _PyWstrList_Clear (& cmdline -> argv );
16751675}
16761676
16771677
@@ -1682,10 +1682,12 @@ static _PyInitError
16821682config_parse_cmdline (_PyCoreConfig * config , _PyCmdline * cmdline ,
16831683 int * need_usage )
16841684{
1685+ const _PyWstrList * argv = & cmdline -> precmdline .argv ;
1686+
16851687 _PyOS_ResetGetOpt ();
16861688 do {
16871689 int longindex = -1 ;
1688- int c = _PyOS_GetOpt (cmdline -> argv . length , cmdline -> argv . items , & longindex );
1690+ int c = _PyOS_GetOpt (argv -> length , argv -> items , & longindex );
16891691 if (c == EOF ) {
16901692 break ;
16911693 }
@@ -1754,6 +1756,7 @@ config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline,
17541756
17551757 case 'E' :
17561758 case 'I' :
1759+ case 'X' :
17571760 /* option handled by _PyPreConfig_ReadFromArgv() */
17581761 break ;
17591762
@@ -1806,12 +1809,6 @@ config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline,
18061809 }
18071810 break ;
18081811
1809- case 'X' :
1810- if (_PyWstrList_Append (& config -> xoptions , _PyOS_optarg ) < 0 ) {
1811- return _Py_INIT_NO_MEMORY ();
1812- }
1813- break ;
1814-
18151812 case 'q' :
18161813 config -> quiet ++ ;
18171814 break ;
@@ -1830,11 +1827,11 @@ config_parse_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline,
18301827 } while (1 );
18311828
18321829 if (config -> run_command == NULL && config -> run_module == NULL
1833- && _PyOS_optind < cmdline -> argv . length
1834- && wcscmp (cmdline -> argv . items [_PyOS_optind ], L"-" ) != 0
1830+ && _PyOS_optind < argv -> length
1831+ && wcscmp (argv -> items [_PyOS_optind ], L"-" ) != 0
18351832 && config -> run_filename == NULL )
18361833 {
1837- config -> run_filename = _PyMem_RawWcsdup (cmdline -> argv . items [_PyOS_optind ]);
1834+ config -> run_filename = _PyMem_RawWcsdup (argv -> items [_PyOS_optind ]);
18381835 if (config -> run_filename == NULL ) {
18391836 return _Py_INIT_NO_MEMORY ();
18401837 }
@@ -1892,9 +1889,10 @@ cmdline_init_env_warnoptions(_PyCmdline *cmdline, const _PyCoreConfig *config)
18921889static _PyInitError
18931890config_init_program (_PyCoreConfig * config , const _PyCmdline * cmdline )
18941891{
1892+ const _PyWstrList * argv = & cmdline -> precmdline .argv ;
18951893 wchar_t * program ;
1896- if (cmdline -> argv . length >= 1 ) {
1897- program = cmdline -> argv . items [0 ];
1894+ if (argv -> length >= 1 ) {
1895+ program = argv -> items [0 ];
18981896 }
18991897 else {
19001898 program = L"" ;
@@ -1965,24 +1963,25 @@ config_init_warnoptions(_PyCoreConfig *config, const _PyCmdline *cmdline)
19651963static _PyInitError
19661964config_init_argv (_PyCoreConfig * config , const _PyCmdline * cmdline )
19671965{
1968- _PyWstrList wargv = _PyWstrList_INIT ;
1966+ const _PyWstrList * cmdline_argv = & cmdline -> precmdline .argv ;
1967+ _PyWstrList config_argv = _PyWstrList_INIT ;
19691968
19701969 /* Copy argv to be able to modify it (to force -c/-m) */
1971- if (cmdline -> argv . length <= _PyOS_optind ) {
1970+ if (cmdline_argv -> length <= _PyOS_optind ) {
19721971 /* Ensure at least one (empty) argument is seen */
1973- if (_PyWstrList_Append (& wargv , L"" ) < 0 ) {
1972+ if (_PyWstrList_Append (& config_argv , L"" ) < 0 ) {
19741973 return _Py_INIT_NO_MEMORY ();
19751974 }
19761975 }
19771976 else {
19781977 _PyWstrList slice ;
1979- slice .length = cmdline -> argv . length - _PyOS_optind ;
1980- slice .items = & cmdline -> argv . items [_PyOS_optind ];
1981- if (_PyWstrList_Copy (& wargv , & slice ) < 0 ) {
1978+ slice .length = cmdline_argv -> length - _PyOS_optind ;
1979+ slice .items = & cmdline_argv -> items [_PyOS_optind ];
1980+ if (_PyWstrList_Copy (& config_argv , & slice ) < 0 ) {
19821981 return _Py_INIT_NO_MEMORY ();
19831982 }
19841983 }
1985- assert (wargv .length >= 1 );
1984+ assert (config_argv .length >= 1 );
19861985
19871986 wchar_t * arg0 = NULL ;
19881987 if (config -> run_command != NULL ) {
@@ -1996,16 +1995,16 @@ config_init_argv(_PyCoreConfig *config, const _PyCmdline *cmdline)
19961995 if (arg0 != NULL ) {
19971996 arg0 = _PyMem_RawWcsdup (arg0 );
19981997 if (arg0 == NULL ) {
1999- _PyWstrList_Clear (& wargv );
1998+ _PyWstrList_Clear (& config_argv );
20001999 return _Py_INIT_NO_MEMORY ();
20012000 }
20022001
2003- PyMem_RawFree (wargv .items [0 ]);
2004- wargv .items [0 ] = arg0 ;
2002+ PyMem_RawFree (config_argv .items [0 ]);
2003+ config_argv .items [0 ] = arg0 ;
20052004 }
20062005
20072006 _PyWstrList_Clear (& config -> argv );
2008- config -> argv = wargv ;
2007+ config -> argv = config_argv ;
20092008 return _Py_INIT_OK ();
20102009}
20112010
@@ -2046,6 +2045,16 @@ config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline,
20462045 }
20472046 }
20482047
2048+ err = _PyPreCmdline_Read (& cmdline -> precmdline );
2049+ if (_Py_INIT_FAILED (err )) {
2050+ return err ;
2051+ }
2052+
2053+ _PyPreCmdline_SetPreConfig (& cmdline -> precmdline , & config -> preconfig );
2054+ if (_PyWstrList_Extend (& config -> xoptions , & cmdline -> precmdline .xoptions ) < 0 ) {
2055+ return _Py_INIT_NO_MEMORY ();
2056+ }
2057+
20492058 err = config_parse_cmdline (config , cmdline , & need_usage );
20502059 if (_Py_INIT_FAILED (err )) {
20512060 return err ;
@@ -2089,7 +2098,8 @@ config_from_cmdline(_PyCoreConfig *config, _PyCmdline *cmdline,
20892098 return err ;
20902099 }
20912100
2092- if (_Py_SetArgcArgv (cmdline -> argv .length , cmdline -> argv .items ) < 0 ) {
2101+ const _PyWstrList * argv = & cmdline -> precmdline .argv ;
2102+ if (_Py_SetArgcArgv (argv -> length , argv -> items ) < 0 ) {
20932103 return _Py_INIT_NO_MEMORY ();
20942104 }
20952105 return _Py_INIT_OK ();
@@ -2107,10 +2117,9 @@ _PyCoreConfig_ReadFromArgv(_PyCoreConfig *config, const _PyArgv *args,
21072117{
21082118 _PyInitError err ;
21092119
2110- _PyCmdline cmdline ;
2111- memset (& cmdline , 0 , sizeof (cmdline ));
2120+ _PyCmdline cmdline = {.precmdline = _PyPreCmdline_INIT };
21122121
2113- err = _PyArgv_AsWstrList ( args , & cmdline .argv );
2122+ err = _PyPreCmdline_Init ( & cmdline .precmdline , args );
21142123 if (_Py_INIT_FAILED (err )) {
21152124 goto done ;
21162125 }
0 commit comments