Index: Python/codecs.c =================================================================== --- Python/codecs.c (revision 66960) +++ Python/codecs.c (working copy) @@ -869,5 +869,6 @@ return -1; } Py_DECREF(mod); + interp->codecs_initialized = 1; return 0; } Index: Python/pystate.c =================================================================== --- Python/pystate.c (revision 66960) +++ Python/pystate.c (working copy) @@ -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 66960) +++ Python/pythonrun.c (working copy) @@ -539,6 +539,10 @@ goto handle_error; Py_INCREF(interp->builtins); } + + /* initialize builtin exceptions */ + _PyExc_Init(); + sysmod = _PyImport_FindExtension("sys", "sys"); if (bimod != NULL && sysmod != NULL) { interp->sysdict = PyModule_GetDict(sysmod); Index: Python/bltinmodule.c =================================================================== --- Python/bltinmodule.c (revision 66960) +++ Python/bltinmodule.c (working copy) @@ -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 66960) +++ Python/sysmodule.c (working copy) @@ -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 66960) +++ Include/pystate.h (working copy) @@ -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 66960) +++ Demo/embed/importexc.c (working copy) @@ -1,6 +1,6 @@ #include -char* cmd = "import exceptions"; +char* cmd = "import types"; int main() { Index: Objects/unicodeobject.c =================================================================== --- Objects/unicodeobject.c (revision 66960) +++ Objects/unicodeobject.c (working copy) @@ -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 */