diff -r 1f94fec31265 Lib/warnings.py --- a/Lib/warnings.py Wed Aug 26 14:10:32 2015 -0400 +++ b/Lib/warnings.py Wed Aug 26 12:48:23 2015 -0700 @@ -369,12 +369,13 @@ # If either if the compiled regexs are None, match anything. _warnings_defaults = False try: - from _warnings import (filters, _defaultaction, _onceregistry, + if __name__ == '_frozen_warnings': + raise ImportError + from _frozen_warnings import (filters, _defaultaction, _onceregistry, warn, warn_explicit, _filters_mutated) defaultaction = _defaultaction onceregistry = _onceregistry _warnings_defaults = True - except ImportError: filters = [] defaultaction = "default" diff -r 1f94fec31265 Makefile.pre.in --- a/Makefile.pre.in Wed Aug 26 14:10:32 2015 -0400 +++ b/Makefile.pre.in Wed Aug 26 12:48:23 2015 -0700 @@ -704,6 +704,10 @@ ./Programs/_freeze_importlib \ $(srcdir)/Lib/importlib/_bootstrap.py Python/importlib.h +Python/warnings.h: $(srcdir)/Lib/warnings.py Programs/_freeze_importlib + ./Programs/_freeze_importlib \ + $(srcdir)/Lib/warnings.py Python/warnings.h + ############################################################################ # Special rules for object files @@ -847,7 +851,7 @@ Python/ceval.o: $(OPCODETARGETS_H) $(srcdir)/Python/ceval_gil.h -Python/frozen.o: Python/importlib.h Python/importlib_external.h +Python/frozen.o: Python/importlib.h Python/importlib_external.h Python/warnings.h Objects/typeobject.o: Objects/typeslots.inc Objects/typeslots.inc: $(srcdir)/Include/typeslots.h $(srcdir)/Objects/typeslots.py diff -r 1f94fec31265 Programs/_freeze_importlib.c --- a/Programs/_freeze_importlib.c Wed Aug 26 14:10:32 2015 -0400 +++ b/Programs/_freeze_importlib.c Wed Aug 26 12:48:23 2015 -0700 @@ -40,6 +40,7 @@ unsigned char *data; PyObject *code = NULL, *marshalled = NULL; int is_bootstrap = 1; + int is_importlib = 0; PyImport_FrozenModules = _PyImport_FrozenModules; @@ -82,13 +83,21 @@ /* Don't install importlib, since it could execute outdated bytecode. */ _Py_InitializeEx_Private(1, 0); - if (strstr(inpath, "_external") != NULL) { - is_bootstrap = 0; + if (strstr(inpath, "importlib") != NULL) { + is_importlib = 1; + if (strstr(inpath, "_external") != NULL) { + is_bootstrap = 0; + } } - code_name = is_bootstrap ? - "" : - ""; + if (!is_importlib) { + code_name = ""; + } + else { + code_name = is_bootstrap ? + "" : + ""; + } code = Py_CompileStringExFlags(text, code_name, Py_file_input, NULL, 0); if (code == NULL) goto error; @@ -112,7 +121,10 @@ goto error; } fprintf(outfile, "%s\n", header); - if (is_bootstrap) + if (!is_importlib) { + fprintf(outfile, "const unsigned char _Py_M__warnings[] = {\n"); + } + else if (is_bootstrap) fprintf(outfile, "const unsigned char _Py_M__importlib[] = {\n"); else fprintf(outfile, diff -r 1f94fec31265 Python/_warnings.c --- a/Python/_warnings.c Wed Aug 26 14:10:32 2015 -0400 +++ b/Python/_warnings.c Wed Aug 26 12:48:23 2015 -0700 @@ -1083,6 +1083,10 @@ { PyObject *m; + if (PyImport_ImportFrozenModule("_frozen_warnings") <= 0) { + Py_FatalError("Py_Initialize: can't import _frozen_warnings"); + } + m = PyModule_Create(&warningsmodule); if (m == NULL) return NULL; diff -r 1f94fec31265 Python/frozen.c --- a/Python/frozen.c Wed Aug 26 14:10:32 2015 -0400 +++ b/Python/frozen.c Wed Aug 26 12:48:23 2015 -0700 @@ -4,6 +4,7 @@ #include "Python.h" #include "importlib.h" #include "importlib_external.h" +#include "warnings.h" /* In order to test the support for frozen modules, by default we define a single frozen module, __hello__. Loading it will print @@ -34,6 +35,7 @@ {"_frozen_importlib", _Py_M__importlib, (int)sizeof(_Py_M__importlib)}, {"_frozen_importlib_external", _Py_M__importlib_external, (int)sizeof(_Py_M__importlib_external)}, + {"_frozen_warnings", _Py_M__warnings, (int)sizeof(_Py_M__warnings)}, /* Test module */ {"__hello__", M___hello__, SIZE}, /* Test package (negative size indicates package-ness) */ diff -r 1f94fec31265 Python/pylifecycle.c --- a/Python/pylifecycle.c Wed Aug 26 14:10:32 2015 -0400 +++ b/Python/pylifecycle.c Wed Aug 26 12:48:23 2015 -0700 @@ -399,9 +399,6 @@ _PyImportHooks_Init(); - /* Initialize _warnings. */ - _PyWarnings_Init(); - if (!install_importlib) return; @@ -410,6 +407,9 @@ import_init(interp, sysmod); + /* Initialize _warnings. */ + _PyWarnings_Init(); + /* initialize the faulthandler module */ if (_PyFaulthandler_Init()) Py_FatalError("Py_Initialize: can't initialize faulthandler");