Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 69587:d3af2a2b621b
Issue #10914: Initialize correctly the filesystem codec when creating a new
subinterpreter to fix a bootstrap issue with codecs implemented in Python, as
the ISO-8859-15 codec.
Add fscodec_initialized attribute to the PyInterpreterState structure.
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Wed, 27 Apr 2011 00:24:21 +0200 |
| parents | c8338cfa3578 |
| children | ce859b848879 |
comparison
equal
deleted
inserted
replaced
| 69586:c8338cfa3578 | 69587:d3af2a2b621b |
|---|---|
| 51 | 51 |
| 52 extern grammar _PyParser_Grammar; /* From graminit.c */ | 52 extern grammar _PyParser_Grammar; /* From graminit.c */ |
| 53 | 53 |
| 54 /* Forward */ | 54 /* Forward */ |
| 55 static void initmain(void); | 55 static void initmain(void); |
| 56 static void initfsencoding(void); | 56 static int initfsencoding(PyInterpreterState *interp); |
| 57 static void initsite(void); | 57 static void initsite(void); |
| 58 static int initstdio(void); | 58 static int initstdio(void); |
| 59 static void flush_io(void); | 59 static void flush_io(void); |
| 60 static PyObject *run_mod(mod_ty, const char *, PyObject *, PyObject *, | 60 static PyObject *run_mod(mod_ty, const char *, PyObject *, PyObject *, |
| 61 PyCompilerFlags *, PyArena *); | 61 PyCompilerFlags *, PyArena *); |
| 296 /* Initialize _warnings. */ | 296 /* Initialize _warnings. */ |
| 297 _PyWarnings_Init(); | 297 _PyWarnings_Init(); |
| 298 | 298 |
| 299 _PyTime_Init(); | 299 _PyTime_Init(); |
| 300 | 300 |
| 301 initfsencoding(); | 301 if (initfsencoding(interp) < 0) |
| 302 Py_FatalError("Py_Initialize: unable to load the file system codec"); | |
| 302 | 303 |
| 303 if (install_sigs) | 304 if (install_sigs) |
| 304 initsigs(); /* Signal handling stuff, including initintr() */ | 305 initsigs(); /* Signal handling stuff, including initintr() */ |
| 305 | 306 |
| 306 initmain(); /* Module __main__ */ | 307 initmain(); /* Module __main__ */ |
| 616 PySys_SetObject("stderr", pstderr); | 617 PySys_SetObject("stderr", pstderr); |
| 617 PySys_SetObject("__stderr__", pstderr); | 618 PySys_SetObject("__stderr__", pstderr); |
| 618 Py_DECREF(pstderr); | 619 Py_DECREF(pstderr); |
| 619 | 620 |
| 620 _PyImportHooks_Init(); | 621 _PyImportHooks_Init(); |
| 622 | |
| 623 if (initfsencoding(interp) < 0) | |
| 624 goto handle_error; | |
| 625 | |
| 621 if (initstdio() < 0) | 626 if (initstdio() < 0) |
| 622 Py_FatalError( | 627 Py_FatalError( |
| 623 "Py_Initialize: can't initialize sys standard streams"); | 628 "Py_Initialize: can't initialize sys standard streams"); |
| 624 initmain(); | 629 initmain(); |
| 625 if (!Py_NoSiteFlag) | 630 if (!Py_NoSiteFlag) |
| 728 Py_FatalError("can't add __builtins__ to __main__"); | 733 Py_FatalError("can't add __builtins__ to __main__"); |
| 729 Py_DECREF(bimod); | 734 Py_DECREF(bimod); |
| 730 } | 735 } |
| 731 } | 736 } |
| 732 | 737 |
| 733 static void | 738 static int |
| 734 initfsencoding(void) | 739 initfsencoding(PyInterpreterState *interp) |
| 735 { | 740 { |
| 736 PyObject *codec; | 741 PyObject *codec; |
| 737 #if defined(HAVE_LANGINFO_H) && defined(CODESET) | 742 #if defined(HAVE_LANGINFO_H) && defined(CODESET) |
| 738 char *codeset = NULL; | 743 char *codeset = NULL; |
| 739 | 744 |
| 746 if (codeset == NULL) | 751 if (codeset == NULL) |
| 747 Py_FatalError("Py_Initialize: Unable to get the locale encoding"); | 752 Py_FatalError("Py_Initialize: Unable to get the locale encoding"); |
| 748 | 753 |
| 749 Py_FileSystemDefaultEncoding = codeset; | 754 Py_FileSystemDefaultEncoding = codeset; |
| 750 Py_HasFileSystemDefaultEncoding = 0; | 755 Py_HasFileSystemDefaultEncoding = 0; |
| 751 return; | 756 interp->fscodec_initialized = 1; |
| 757 return 0; | |
| 752 } | 758 } |
| 753 #endif | 759 #endif |
| 754 | 760 |
| 755 /* the encoding is mbcs, utf-8 or ascii */ | 761 /* the encoding is mbcs, utf-8 or ascii */ |
| 756 codec = _PyCodec_Lookup(Py_FileSystemDefaultEncoding); | 762 codec = _PyCodec_Lookup(Py_FileSystemDefaultEncoding); |
| 757 if (!codec) { | 763 if (!codec) { |
| 758 /* Such error can only occurs in critical situations: no more | 764 /* Such error can only occurs in critical situations: no more |
| 759 * memory, import a module of the standard library failed, | 765 * memory, import a module of the standard library failed, |
| 760 * etc. */ | 766 * etc. */ |
| 761 Py_FatalError("Py_Initialize: unable to load the file system codec"); | 767 return -1; |
| 762 } else { | 768 } |
| 763 Py_DECREF(codec); | 769 Py_DECREF(codec); |
| 764 } | 770 interp->fscodec_initialized = 1; |
| 771 return 0; | |
| 765 } | 772 } |
| 766 | 773 |
| 767 /* Import the site module (not into __main__ though) */ | 774 /* Import the site module (not into __main__ though) */ |
| 768 | 775 |
| 769 static void | 776 static void |
