Index: Python/pythonrun.c =================================================================== --- Python/pythonrun.c (revision 85803) +++ Python/pythonrun.c (working copy) @@ -70,7 +70,8 @@ static void call_py_exitfuncs(void); static void wait_for_thread_shutdown(void); static void call_ll_exitfuncs(void); -extern void _PyUnicode_Init(void); +extern void _PyUnicode_InitGlobals(void); +extern void _PyUnicode_InitTypes(void); extern void _PyUnicode_Fini(void); extern int _PyLong_Init(void); extern void PyLong_Fini(void); @@ -192,6 +193,9 @@ return; initialized = 1; + /* The Unicode API is used before _PyUnicode_InitTypes(). */ + _PyUnicode_InitGlobals(); + #if defined(HAVE_LANGINFO_H) && defined(HAVE_SETLOCALE) /* Set up the LC_CTYPE locale, so we can obtain the locale's charset without having to switch @@ -249,8 +253,8 @@ if (interp->modules_reloading == NULL) Py_FatalError("Py_Initialize: can't make modules_reloading dictionary"); - /* Init Unicode implementation; relies on the codec registry */ - _PyUnicode_Init(); + /* Init Unicode type; relies on the codec registry */ + _PyUnicode_InitTypes(); bimod = _PyBuiltin_Init(); if (bimod == NULL) Index: Include/unicodeobject.h =================================================================== --- Include/unicodeobject.h (revision 85803) +++ Include/unicodeobject.h (working copy) @@ -220,7 +220,8 @@ # define PyUnicode_TranslateCharmap PyUnicodeUCS2_TranslateCharmap # define _PyUnicode_AsDefaultEncodedString _PyUnicodeUCS2_AsDefaultEncodedString # define _PyUnicode_Fini _PyUnicodeUCS2_Fini -# define _PyUnicode_Init _PyUnicodeUCS2_Init +# define _PyUnicode_InitGlobals _PyUnicodeUCS2_InitGlobals +# define _PyUnicode_InitTypes _PyUnicodeUCS2_InitTypes # define PyUnicode_strdup PyUnicodeUCS2_strdup #else @@ -304,7 +305,8 @@ # define PyUnicode_TranslateCharmap PyUnicodeUCS4_TranslateCharmap # define _PyUnicode_AsDefaultEncodedString _PyUnicodeUCS4_AsDefaultEncodedString # define _PyUnicode_Fini _PyUnicodeUCS4_Fini -# define _PyUnicode_Init _PyUnicodeUCS4_Init +# define _PyUnicode_InitGlobals _PyUnicodeUCS4_InitGlobals +# define _PyUnicode_InitTypes _PyUnicodeUCS4_InitTypes # define PyUnicode_strdup PyUnicodeUCS4_strdup #endif Index: Objects/unicodeobject.c =================================================================== --- Objects/unicodeobject.c (revision 85803) +++ Objects/unicodeobject.c (working copy) @@ -83,8 +83,8 @@ /* --- Globals ------------------------------------------------------------ - The globals are initialized by the _PyUnicode_Init() API and should - not be used before calling that API. + The globals are initialized by the _PyUnicode_InitGlobals() API and + should not be used before calling that API. */ @@ -9881,12 +9881,16 @@ PyObject_Del, /* tp_free */ }; -/* Initialize the Unicode implementation */ - -void _PyUnicode_Init(void) +/* Initialize global variables */ +void _PyUnicode_InitGlobals(void) { + static int initialized = 0; int i; + if (initialized) + return; + initialized = 1; + /* XXX - move this array to unicodectype.c ? */ Py_UNICODE linebreak[] = { 0x000A, /* LINE FEED */ @@ -9908,14 +9912,18 @@ for (i = 0; i < 256; i++) unicode_latin1[i] = NULL; - if (PyType_Ready(&PyUnicode_Type) < 0) - Py_FatalError("Can't initialize 'unicode'"); /* initialize the linebreak bloom filter */ bloom_linebreak = make_bloom_mask( linebreak, sizeof(linebreak) / sizeof(linebreak[0]) ); +} +/* Initialize types */ +void _PyUnicode_InitTypes(void) +{ + if (PyType_Ready(&PyUnicode_Type) < 0) + Py_FatalError("Can't initialize 'unicode'"); PyType_Ready(&EncodingMapType); } Index: Modules/main.c =================================================================== --- Modules/main.c (revision 85803) +++ Modules/main.c (working copy) @@ -42,6 +42,8 @@ extern "C" { #endif +extern void _PyUnicode_InitGlobals(void); + /* For Py_GetArgcArgv(); set by main() */ static wchar_t **orig_argv; static int orig_argc; @@ -327,6 +329,8 @@ orig_argc = argc; /* For Py_GetArgcArgv() */ orig_argv = argv; + /* The Unicode API is used before Py_Initialize(). */ + _PyUnicode_InitGlobals(); PySys_ResetWarnOptions(); while ((c = _PyOS_GetOpt(argc, argv, PROGRAM_OPTS)) != EOF) {