@@ -59,10 +59,9 @@ extern grammar _PyParser_Grammar; /* From graminit.c */
59
59
60
60
/* Forward */
61
61
static _PyInitError add_main_module (PyInterpreterState * interp );
62
- static _PyInitError initfsencoding (PyInterpreterState * interp );
63
- static _PyInitError initsite (void );
62
+ static _PyInitError init_import_size (void );
64
63
static _PyInitError init_sys_streams (PyInterpreterState * interp );
65
- static _PyInitError initsigs (void );
64
+ static _PyInitError init_signals (void );
66
65
static void call_py_exitfuncs (PyInterpreterState * );
67
66
static void wait_for_thread_shutdown (void );
68
67
static void call_ll_exitfuncs (_PyRuntimeState * runtime );
@@ -144,42 +143,8 @@ Py_IsInitialized(void)
144
143
145
144
*/
146
145
147
- static char *
148
- get_codec_name (const char * encoding )
149
- {
150
- const char * name_utf8 ;
151
- char * name_str ;
152
- PyObject * codec , * name = NULL ;
153
-
154
- codec = _PyCodec_Lookup (encoding );
155
- if (!codec )
156
- goto error ;
157
-
158
- name = _PyObject_GetAttrId (codec , & PyId_name );
159
- Py_CLEAR (codec );
160
- if (!name )
161
- goto error ;
162
-
163
- name_utf8 = PyUnicode_AsUTF8 (name );
164
- if (name_utf8 == NULL )
165
- goto error ;
166
- name_str = _PyMem_RawStrdup (name_utf8 );
167
- Py_DECREF (name );
168
- if (name_str == NULL ) {
169
- PyErr_NoMemory ();
170
- return NULL ;
171
- }
172
- return name_str ;
173
-
174
- error :
175
- Py_XDECREF (codec );
176
- Py_XDECREF (name );
177
- return NULL ;
178
- }
179
-
180
-
181
146
static _PyInitError
182
- initimport (PyInterpreterState * interp , PyObject * sysmod )
147
+ init_importlib (PyInterpreterState * interp , PyObject * sysmod )
183
148
{
184
149
PyObject * importlib ;
185
150
PyObject * impmod ;
@@ -229,7 +194,7 @@ initimport(PyInterpreterState *interp, PyObject *sysmod)
229
194
}
230
195
231
196
static _PyInitError
232
- initexternalimport (PyInterpreterState * interp )
197
+ init_importlib_external (PyInterpreterState * interp )
233
198
{
234
199
PyObject * value ;
235
200
value = PyObject_CallMethod (interp -> importlib ,
@@ -661,7 +626,7 @@ pycore_init_import_warnings(PyInterpreterState *interp, PyObject *sysmod)
661
626
662
627
/* This call sets up builtin and frozen import support */
663
628
if (interp -> core_config ._install_importlib ) {
664
- err = initimport (interp , sysmod );
629
+ err = init_importlib (interp , sysmod );
665
630
if (_Py_INIT_FAILED (err )) {
666
631
return err ;
667
632
}
@@ -940,7 +905,7 @@ _Py_InitializeMainInterpreter(_PyRuntimeState *runtime,
940
905
return _Py_INIT_ERR ("can't finish initializing sys" );
941
906
}
942
907
943
- _PyInitError err = initexternalimport (interp );
908
+ _PyInitError err = init_importlib_external (interp );
944
909
if (_Py_INIT_FAILED (err )) {
945
910
return err ;
946
911
}
@@ -951,13 +916,13 @@ _Py_InitializeMainInterpreter(_PyRuntimeState *runtime,
951
916
return err ;
952
917
}
953
918
954
- err = initfsencoding (interp );
919
+ err = _PyUnicode_InitEncodings (interp );
955
920
if (_Py_INIT_FAILED (err )) {
956
921
return err ;
957
922
}
958
923
959
924
if (core_config -> install_signal_handlers ) {
960
- err = initsigs (); /* Signal handling stuff, including initintr() */
925
+ err = init_signals ();
961
926
if (_Py_INIT_FAILED (err )) {
962
927
return err ;
963
928
}
@@ -992,7 +957,7 @@ _Py_InitializeMainInterpreter(_PyRuntimeState *runtime,
992
957
runtime -> initialized = 1 ;
993
958
994
959
if (core_config -> site_import ) {
995
- err = initsite (); /* Module site */
960
+ err = init_import_size (); /* Module site */
996
961
if (_Py_INIT_FAILED (err )) {
997
962
return err ;
998
963
}
@@ -1497,17 +1462,17 @@ new_interpreter(PyThreadState **tstate_p)
1497
1462
return err ;
1498
1463
}
1499
1464
1500
- err = initimport (interp , sysmod );
1465
+ err = init_importlib (interp , sysmod );
1501
1466
if (_Py_INIT_FAILED (err )) {
1502
1467
return err ;
1503
1468
}
1504
1469
1505
- err = initexternalimport (interp );
1470
+ err = init_importlib_external (interp );
1506
1471
if (_Py_INIT_FAILED (err )) {
1507
1472
return err ;
1508
1473
}
1509
1474
1510
- err = initfsencoding (interp );
1475
+ err = _PyUnicode_InitEncodings (interp );
1511
1476
if (_Py_INIT_FAILED (err )) {
1512
1477
return err ;
1513
1478
}
@@ -1523,7 +1488,7 @@ new_interpreter(PyThreadState **tstate_p)
1523
1488
}
1524
1489
1525
1490
if (core_config -> site_import ) {
1526
- err = initsite ();
1491
+ err = init_import_size ();
1527
1492
if (_Py_INIT_FAILED (err )) {
1528
1493
return err ;
1529
1494
}
@@ -1649,42 +1614,10 @@ add_main_module(PyInterpreterState *interp)
1649
1614
return _Py_INIT_OK ();
1650
1615
}
1651
1616
1652
- static _PyInitError
1653
- initfsencoding (PyInterpreterState * interp )
1654
- {
1655
- _PyCoreConfig * config = & interp -> core_config ;
1656
-
1657
- char * encoding = get_codec_name (config -> filesystem_encoding );
1658
- if (encoding == NULL ) {
1659
- /* Such error can only occurs in critical situations: no more
1660
- memory, import a module of the standard library failed, etc. */
1661
- return _Py_INIT_ERR ("failed to get the Python codec "
1662
- "of the filesystem encoding" );
1663
- }
1664
-
1665
- /* Update the filesystem encoding to the normalized Python codec name.
1666
- For example, replace "ANSI_X3.4-1968" (locale encoding) with "ascii"
1667
- (Python codec name). */
1668
- PyMem_RawFree (config -> filesystem_encoding );
1669
- config -> filesystem_encoding = encoding ;
1670
-
1671
- /* Set Py_FileSystemDefaultEncoding and Py_FileSystemDefaultEncodeErrors
1672
- global configuration variables. */
1673
- if (_Py_SetFileSystemEncoding (config -> filesystem_encoding ,
1674
- config -> filesystem_errors ) < 0 ) {
1675
- return _Py_INIT_NO_MEMORY ();
1676
- }
1677
-
1678
- /* PyUnicode can now use the Python codec rather than C implementation
1679
- for the filesystem encoding */
1680
- interp -> fscodec_initialized = 1 ;
1681
- return _Py_INIT_OK ();
1682
- }
1683
-
1684
1617
/* Import the site module (not into __main__ though) */
1685
1618
1686
1619
static _PyInitError
1687
- initsite (void )
1620
+ init_import_size (void )
1688
1621
{
1689
1622
PyObject * m ;
1690
1623
m = PyImport_ImportModule ("site" );
@@ -1880,14 +1813,6 @@ init_sys_streams(PyInterpreterState *interp)
1880
1813
}
1881
1814
#endif
1882
1815
1883
- char * codec_name = get_codec_name (config -> stdio_encoding );
1884
- if (codec_name == NULL ) {
1885
- return _Py_INIT_ERR ("failed to get the Python codec name "
1886
- "of the stdio encoding" );
1887
- }
1888
- PyMem_RawFree (config -> stdio_encoding );
1889
- config -> stdio_encoding = codec_name ;
1890
-
1891
1816
/* Hack to avoid a nasty recursion issue when Python is invoked
1892
1817
in verbose mode: pre-import the Latin-1 and UTF-8 codecs */
1893
1818
if ((m = PyImport_ImportModule ("encodings.utf_8" )) == NULL ) {
@@ -2287,7 +2212,7 @@ Py_Exit(int sts)
2287
2212
}
2288
2213
2289
2214
static _PyInitError
2290
- initsigs (void )
2215
+ init_signals (void )
2291
2216
{
2292
2217
#ifdef SIGPIPE
2293
2218
PyOS_setsig (SIGPIPE , SIG_IGN );
0 commit comments