@@ -654,6 +654,7 @@ _PyCoreConfig_Copy(_PyCoreConfig *config, const _PyCoreConfig *config2)
654654 COPY_ATTR (verbose );
655655 COPY_ATTR (quiet );
656656 COPY_ATTR (user_site_directory );
657+ COPY_ATTR (configure_c_stdio );
657658 COPY_ATTR (buffered_stdio );
658659 COPY_WSTR_ATTR (filesystem_encoding );
659660 COPY_WSTR_ATTR (filesystem_errors );
@@ -755,6 +756,7 @@ _PyCoreConfig_AsDict(const _PyCoreConfig *config)
755756 SET_ITEM_INT (verbose );
756757 SET_ITEM_INT (quiet );
757758 SET_ITEM_INT (user_site_directory );
759+ SET_ITEM_INT (configure_c_stdio );
758760 SET_ITEM_INT (buffered_stdio );
759761 SET_ITEM_WSTR (stdio_encoding );
760762 SET_ITEM_WSTR (stdio_errors );
@@ -1582,7 +1584,6 @@ config_read(_PyCoreConfig *config, _PyPreCmdline *cmdline)
15821584 return _Py_INIT_NO_MEMORY ();
15831585 }
15841586 }
1585-
15861587 return _Py_INIT_OK ();
15871588}
15881589
@@ -1632,7 +1633,10 @@ void
16321633_PyCoreConfig_Write (const _PyCoreConfig * config , _PyRuntimeState * runtime )
16331634{
16341635 _PyCoreConfig_SetGlobalConfig (config );
1635- config_init_stdio (config );
1636+
1637+ if (config -> configure_c_stdio ) {
1638+ config_init_stdio (config );
1639+ }
16361640
16371641 /* Write the new pre-configuration into _PyRuntime */
16381642 _PyPreConfig * preconfig = & runtime -> preconfig ;
@@ -2067,6 +2071,9 @@ config_read_cmdline(_PyCoreConfig *config, _PyPreCmdline *precmdline)
20672071 if (config -> parse_argv < 0 ) {
20682072 config -> parse_argv = 1 ;
20692073 }
2074+ if (config -> configure_c_stdio < 0 ) {
2075+ config -> configure_c_stdio = 1 ;
2076+ }
20702077
20712078 if (config -> parse_argv ) {
20722079 int opt_index ;
@@ -2171,7 +2178,9 @@ _PyCoreConfig_SetWideArgv(_PyCoreConfig *config, int argc, wchar_t **argv)
21712178
21722179 * Command line arguments
21732180 * Environment variables
2174- * Py_xxx global configuration variables */
2181+ * Py_xxx global configuration variables
2182+
2183+ The only side effects are to modify config and to call _Py_SetArgcArgv(). */
21752184_PyInitError
21762185_PyCoreConfig_Read (_PyCoreConfig * config )
21772186{
@@ -2227,14 +2236,19 @@ _PyCoreConfig_Read(_PyCoreConfig *config)
22272236 assert (config -> quiet >= 0 );
22282237 assert (config -> user_site_directory >= 0 );
22292238 assert (config -> parse_argv >= 0 );
2239+ assert (config -> configure_c_stdio >= 0 );
22302240 assert (config -> buffered_stdio >= 0 );
22312241 assert (config -> program_name != NULL );
22322242 assert (config -> program != NULL );
22332243 assert (_PyWstrList_CheckConsistency (& config -> argv ));
2244+ /* sys.argv must be non-empty: empty argv is replaced with [''] */
2245+ assert (config -> argv .length >= 1 );
22342246 assert (_PyWstrList_CheckConsistency (& config -> xoptions ));
22352247 assert (_PyWstrList_CheckConsistency (& config -> warnoptions ));
22362248 assert (_PyWstrList_CheckConsistency (& config -> module_search_paths ));
22372249 if (config -> _install_importlib ) {
2250+ assert (config -> use_module_search_paths != 0 );
2251+ /* don't check config->module_search_paths */
22382252 assert (config -> executable != NULL );
22392253 assert (config -> prefix != NULL );
22402254 assert (config -> base_prefix != NULL );
0 commit comments