Index: Python/codecs.c =================================================================== --- Python/codecs.c (Revision 67029) +++ Python/codecs.c (Arbeitskopie) @@ -869,5 +869,6 @@ return -1; } Py_DECREF(mod); + interp->codecs_initialized = 1; return 0; } Index: Python/pystate.c =================================================================== --- Python/pystate.c (Revision 67029) +++ Python/pystate.c (Arbeitskopie) @@ -76,6 +76,7 @@ interp->codec_search_path = NULL; interp->codec_search_cache = NULL; interp->codec_error_registry = NULL; + interp->codecs_initialized = 0; #ifdef HAVE_DLOPEN #ifdef RTLD_NOW interp->dlopenflags = RTLD_NOW; Index: Python/pythonrun.c =================================================================== --- Python/pythonrun.c (Revision 67029) +++ Python/pythonrun.c (Arbeitskopie) @@ -539,8 +539,13 @@ goto handle_error; Py_INCREF(interp->builtins); } + + /* initialize builtin exceptions */ + _PyExc_Init(); + sysmod = _PyImport_FindExtension("sys", "sys"); if (bimod != NULL && sysmod != NULL) { + PyObject *pstderr; interp->sysdict = PyModule_GetDict(sysmod); if (interp->sysdict == NULL) goto handle_error; @@ -548,7 +553,18 @@ PySys_SetPath(Py_GetPath()); PyDict_SetItemString(interp->sysdict, "modules", interp->modules); + /* Set up a preliminary stderr printer until we have enough + infrastructure for the io module in place. */ + pstderr = PyFile_NewStdPrinter(fileno(stderr)); + if (pstderr == NULL) + Py_FatalError("Py_Initialize: can't set preliminary stderr"); + PySys_SetObject("stderr", pstderr); + PySys_SetObject("__stderr__", pstderr); + _PyImportHooks_Init(); + if (initstdio() < 0) + Py_FatalError( + "Py_Initialize: can't initialize sys standard streams"); initmain(); if (!Py_NoSiteFlag) initsite(); Index: Python/bltinmodule.c =================================================================== --- Python/bltinmodule.c (Revision 67029) +++ Python/bltinmodule.c (Arbeitskopie) @@ -2282,7 +2282,7 @@ PyModuleDef_HEAD_INIT, "builtins", builtin_doc, - 0, + -1, /* multiple "initialization" just copies the module dict. */ builtin_methods, NULL, NULL, Index: Python/sysmodule.c =================================================================== --- Python/sysmodule.c (Revision 67029) +++ Python/sysmodule.c (Arbeitskopie) @@ -1231,7 +1231,7 @@ PyModuleDef_HEAD_INIT, "sys", sys_doc, - 0, + -1, /* multiple "initialization" just copies the module dict. */ sys_methods, NULL, NULL, Index: Include/pystate.h =================================================================== --- Include/pystate.h (Revision 67029) +++ Include/pystate.h (Arbeitskopie) @@ -27,6 +27,7 @@ PyObject *codec_search_path; PyObject *codec_search_cache; PyObject *codec_error_registry; + int codecs_initialized; #ifdef HAVE_DLOPEN int dlopenflags; Index: Demo/embed/importexc.c =================================================================== --- Demo/embed/importexc.c (Revision 67029) +++ Demo/embed/importexc.c (Arbeitskopie) @@ -1,14 +1,20 @@ #include -char* cmd = "import exceptions"; +#if 0 +char* cmd = "import codecs, encodings.utf_8, types; print(types)"; +#else +char* cmd = "import types; print(types)"; +#endif int main() { + printf("Initialize interpreter\n"); Py_Initialize(); PyEval_InitThreads(); PyRun_SimpleString(cmd); Py_EndInterpreter(PyThreadState_Get()); + printf("\nInitialize subinterpreter\n"); Py_NewInterpreter(); PyRun_SimpleString(cmd); Py_Finalize(); Index: Objects/unicodeobject.c =================================================================== --- Objects/unicodeobject.c (Revision 67029) +++ Objects/unicodeobject.c (Arbeitskopie) @@ -1346,6 +1346,19 @@ #endif else if (strcmp(encoding, "ascii") == 0) return PyUnicode_AsASCIIString(unicode); + /* During bootstrap, we may need to find the encodings + package, to load the file system encoding, and require the + file system encoding in order to load the encodings + package. + + Break out of this dependency by assuming that the path to + the encodings module is ASCII-only. XXX could try wcstombs + instead, if the file system encoding is the locale's + encoding. */ + else if (Py_FileSystemDefaultEncoding && + strcmp(encoding, Py_FileSystemDefaultEncoding) == 0 && + !PyThreadState_GET()->interp->codecs_initialized) + return PyUnicode_AsASCIIString(unicode); } /* Encode via the codec registry */