[Python-checkins] python/dist/src/Python compile.c,2.336,2.337

jhylton at users.sourceforge.net jhylton at users.sourceforge.net
Sun Nov 7 15:04:04 CET 2004


Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30545/dist/src/Python

Modified Files:
	compile.c 
Log Message:
SF patch 1025636: Check for NULL returns in compile.c:com_import_stmt

There is no test for this change, because there is no way to provoke memory errors on demand.  Test suite passes, though.

Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.336
retrieving revision 2.337
diff -u -d -r2.336 -r2.337
--- compile.c	2 Nov 2004 04:20:09 -0000	2.336
+++ compile.c	7 Nov 2004 14:04:00 -0000	2.337
@@ -3606,10 +3606,20 @@
 			}
 			REQ(nn, import_as_names);
 			tup = PyTuple_New((NCH(nn) + 1) / 2);
-			for (i = 0; i < NCH(nn); i += 2)
-				PyTuple_SET_ITEM(tup, i / 2,
-					PyString_FromString(STR(
-						CHILD(CHILD(nn, i), 0))));
+            for (i = 0; i < NCH(nn); i += 2) {
+                PyObject *s = PyString_FromString(
+                    STR(CHILD(CHILD(nn, i), 0)));
+                if (s == NULL) {
+                    Py_CLEAR(tup);
+                    break;
+                } else
+                    PyTuple_SET_ITEM(tup, i / 2, s);
+            }
+            if (tup == NULL) {
+                /* Assume that failue above was MemoryError */
+                com_error(c, PyExc_MemoryError, "");
+                return;
+            }
 		}
 		com_addoparg(c, LOAD_CONST, com_addconst(c, tup));
 		Py_DECREF(tup);



More information about the Python-checkins mailing list