@@ -136,13 +136,6 @@ int Py_LegacyWindowsFSEncodingFlag = 0; /* Uses mbcs instead of utf-8 */
136136int Py_LegacyWindowsStdioFlag = 0 ; /* Uses FileIO instead of WindowsConsoleIO */
137137#endif
138138
139- /* The filesystem encoding is chosen by config_init_fs_encoding(),
140- see also initfsencoding(). */
141- const char * Py_FileSystemDefaultEncoding = NULL ;
142- int Py_HasFileSystemDefaultEncoding = 0 ;
143- const char * Py_FileSystemDefaultEncodeErrors = NULL ;
144- static int _Py_HasFileSystemDefaultEncodeErrors = 0 ;
145-
146139
147140PyObject *
148141_Py_GetGlobalVariablesAsDict (void )
@@ -296,49 +289,6 @@ _Py_wstrlist_as_pylist(int len, wchar_t **list)
296289}
297290
298291
299- void
300- _Py_ClearFileSystemEncoding (void )
301- {
302- if (!Py_HasFileSystemDefaultEncoding && Py_FileSystemDefaultEncoding ) {
303- PyMem_RawFree ((char * )Py_FileSystemDefaultEncoding );
304- Py_FileSystemDefaultEncoding = NULL ;
305- }
306- if (!_Py_HasFileSystemDefaultEncodeErrors && Py_FileSystemDefaultEncodeErrors ) {
307- PyMem_RawFree ((char * )Py_FileSystemDefaultEncodeErrors );
308- Py_FileSystemDefaultEncodeErrors = NULL ;
309- }
310- }
311-
312-
313- /* --- File system encoding/errors -------------------------------- */
314-
315- /* Set Py_FileSystemDefaultEncoding and Py_FileSystemDefaultEncodeErrors
316- global configuration variables. */
317- int
318- _Py_SetFileSystemEncoding (const char * encoding , const char * errors )
319- {
320- char * encoding2 = _PyMem_RawStrdup (encoding );
321- if (encoding2 == NULL ) {
322- return -1 ;
323- }
324-
325- char * errors2 = _PyMem_RawStrdup (errors );
326- if (errors2 == NULL ) {
327- PyMem_RawFree (encoding2 );
328- return -1 ;
329- }
330-
331- _Py_ClearFileSystemEncoding ();
332-
333- Py_FileSystemDefaultEncoding = encoding2 ;
334- Py_HasFileSystemDefaultEncoding = 0 ;
335-
336- Py_FileSystemDefaultEncodeErrors = errors2 ;
337- _Py_HasFileSystemDefaultEncodeErrors = 0 ;
338- return 0 ;
339- }
340-
341-
342292/* --- Py_SetStandardStreamEncoding() ----------------------------- */
343293
344294/* Helper to allow an embedding application to override the normal
@@ -1849,6 +1799,7 @@ _PyCoreConfig_AsDict(const _PyCoreConfig *config)
18491799
18501800typedef struct {
18511801 const _PyArgv * args ;
1802+ int argc ;
18521803 wchar_t * * argv ;
18531804 int nwarnoption ; /* Number of -W command line options */
18541805 wchar_t * * warnoptions ; /* Command line -W options */
@@ -1881,35 +1832,7 @@ static _PyInitError
18811832cmdline_decode_argv (_PyCmdline * cmdline )
18821833{
18831834 assert (cmdline -> argv == NULL );
1884-
1885- const _PyArgv * args = cmdline -> args ;
1886-
1887- if (args -> use_bytes_argv ) {
1888- /* +1 for a the NULL terminator */
1889- size_t size = sizeof (wchar_t * ) * (args -> argc + 1 );
1890- wchar_t * * argv = (wchar_t * * )PyMem_RawMalloc (size );
1891- if (argv == NULL ) {
1892- return _Py_INIT_NO_MEMORY ();
1893- }
1894-
1895- for (int i = 0 ; i < args -> argc ; i ++ ) {
1896- size_t len ;
1897- wchar_t * arg = Py_DecodeLocale (args -> bytes_argv [i ], & len );
1898- if (arg == NULL ) {
1899- _Py_wstrlist_clear (i , argv );
1900- return DECODE_LOCALE_ERR ("command line arguments" ,
1901- (Py_ssize_t )len );
1902- }
1903- argv [i ] = arg ;
1904- }
1905- argv [args -> argc ] = NULL ;
1906-
1907- cmdline -> argv = argv ;
1908- }
1909- else {
1910- cmdline -> argv = args -> wchar_argv ;
1911- }
1912- return _Py_INIT_OK ();
1835+ return _PyArgv_Decode (cmdline -> args , & cmdline -> argv );
19131836}
19141837
19151838
@@ -2377,7 +2300,7 @@ config_read_from_argv_impl(_PyCoreConfig *config, const _PyArgv *args)
23772300 memset (& cmdline , 0 , sizeof (cmdline ));
23782301 cmdline .args = args ;
23792302
2380- err = cmdline_decode_argv ( & cmdline );
2303+ err = _PyArgv_Decode ( cmdline . args , & cmdline . argv );
23812304 if (_Py_INIT_FAILED (err )) {
23822305 goto done ;
23832306 }
0 commit comments