diff Python/errors.c @ 84794:9b77b3ee6fb8

Issue #18520: PyErr_NoMemory() now fails with a fatal error if it is called before PyExc_MemoryError has been initialized by _PyExc_Init()
author Victor Stinner <victor.stinner@gmail.com>
date Mon, 22 Jul 2013 22:28:37 +0200
parents 48a869a39e2d
children e63f19d0a651
line wrap: on
line diff
--- a/Python/errors.c	Mon Jul 22 22:24:54 2013 +0200
+++ b/Python/errors.c	Mon Jul 22 22:28:37 2013 +0200
@@ -380,6 +380,12 @@
 PyObject *
 PyErr_NoMemory(void)
 {
+    if (Py_TYPE(PyExc_MemoryError) == NULL) {
+        /* PyErr_NoMemory() has been called before PyExc_MemoryError has been
+           initialized by _PyExc_Init() */
+        Py_FatalError("Out of memory and PyExc_MemoryError is not "
+                      "initialized yet");
+    }
     PyErr_SetNone(PyExc_MemoryError);
     return NULL;
 }