[Python-checkins] cpython: Issue #18408: type_new() and PyType_FromSpecWithBases() now raise MemoryError

victor.stinner python-checkins at python.org
Tue Jul 16 00:12:51 CEST 2013


http://hg.python.org/cpython/rev/c676fc74d779
changeset:   84643:c676fc74d779
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Mon Jul 15 19:34:20 2013 +0200
summary:
  Issue #18408: type_new() and PyType_FromSpecWithBases() now raise MemoryError
on memory allocation failure

files:
  Objects/typeobject.c |  8 ++++++--
  1 files changed, 6 insertions(+), 2 deletions(-)


diff --git a/Objects/typeobject.c b/Objects/typeobject.c
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -2292,8 +2292,10 @@
             /* Silently truncate the docstring if it contains null bytes. */
             len = strlen(doc_str);
             tp_doc = (char *)PyObject_MALLOC(len + 1);
-            if (tp_doc == NULL)
+            if (tp_doc == NULL) {
+                PyErr_NoMemory();
                 goto error;
+            }
             memcpy(tp_doc, doc_str, len + 1);
             type->tp_doc = tp_doc;
         }
@@ -2496,8 +2498,10 @@
         if (slot->slot == Py_tp_doc) {
             size_t len = strlen(slot->pfunc)+1;
             char *tp_doc = PyObject_MALLOC(len);
-            if (tp_doc == NULL)
+            if (tp_doc == NULL) {
+                PyErr_NoMemory();
                 goto fail;
+            }
             memcpy(tp_doc, slot->pfunc, len);
             type->tp_doc = tp_doc;
         }

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list