Mercurial > cpython-lru_cache-weakref
comparison Python/errors.c @ 29877:72cbc41ccc2f legacy-trunk
Fix [ 771097 ] frozen programs fail due to implicit import of "warnings".
If the initial import of warnings fails, clear the error. When the module
is actually needed, if the original import failed, see if it has managed
to find its way to sys.modules yet and if so, remember it.
| author | Mark Hammond <mhammond@skippinet.com.au> |
|---|---|
| date | Tue, 15 Jul 2003 23:03:55 +0000 |
| parents | 5fbdcaef9dda |
| children | 3b59fa5d25b1 |
comparison
equal
deleted
inserted
replaced
| 29876:a0a7231c6fe0 | 29877:72cbc41ccc2f |
|---|---|
| 597 Py_XDECREF(t); | 597 Py_XDECREF(t); |
| 598 Py_XDECREF(v); | 598 Py_XDECREF(v); |
| 599 Py_XDECREF(tb); | 599 Py_XDECREF(tb); |
| 600 } | 600 } |
| 601 | 601 |
| 602 extern PyObject *PyModule_WarningsModule; | 602 extern PyObject *PyModule_GetWarningsModule(); |
| 603 | 603 |
| 604 /* Function to issue a warning message; may raise an exception. */ | 604 /* Function to issue a warning message; may raise an exception. */ |
| 605 int | 605 int |
| 606 PyErr_Warn(PyObject *category, char *message) | 606 PyErr_Warn(PyObject *category, char *message) |
| 607 { | 607 { |
| 608 PyObject *dict, *func = NULL; | 608 PyObject *dict, *func = NULL; |
| 609 | 609 PyObject *warnings_module = PyModule_GetWarningsModule(); |
| 610 if (PyModule_WarningsModule != NULL) { | 610 |
| 611 dict = PyModule_GetDict(PyModule_WarningsModule); | 611 if (warnings_module != NULL) { |
| 612 dict = PyModule_GetDict(warnings_module); | |
| 612 func = PyDict_GetItemString(dict, "warn"); | 613 func = PyDict_GetItemString(dict, "warn"); |
| 613 } | 614 } |
| 614 if (func == NULL) { | 615 if (func == NULL) { |
| 615 PySys_WriteStderr("warning: %s\n", message); | 616 PySys_WriteStderr("warning: %s\n", message); |
| 616 return 0; | 617 return 0; |
