diff Python/exceptions.c @ 16852:847844248c6f legacy-trunk

SyntaxError__init__(): Be a little more robust when picking apart the location information for the SyntaxError -- do not do more than we need to, stopping as soon as an exception has been raised.
author Fred Drake <fdrake@acm.org>
date Wed, 28 Feb 2001 21:52:10 +0000
parents 0e6a3da4f956
children f939ce52a734
line wrap: on
line diff
--- a/Python/exceptions.c	Wed Feb 28 21:46:37 2001 +0000
+++ b/Python/exceptions.c	Wed Feb 28 21:52:10 2001 +0000
@@ -702,30 +702,36 @@
     }
     if (lenargs == 2) {
 	PyObject *info = PySequence_GetItem(args, 1);
-	PyObject *filename, *lineno, *offset, *text;
+	PyObject *filename = NULL, *lineno = NULL;
+	PyObject *offset = NULL, *text = NULL;
 	int status = 1;
 
 	if (!info)
 	    goto finally;
 
 	filename = PySequence_GetItem(info, 0);
-	lineno = PySequence_GetItem(info, 1);
-	offset = PySequence_GetItem(info, 2);
-	text = PySequence_GetItem(info, 3);
-
+	if (filename != NULL) {
+	    lineno = PySequence_GetItem(info, 1);
+	    if (lineno != NULL) {
+		offset = PySequence_GetItem(info, 2);
+		if (offset != NULL) {
+		    text = PySequence_GetItem(info, 3);
+		    if (text != NULL) {
+			status =
+			    PyObject_SetAttrString(self, "filename", filename)
+			    || PyObject_SetAttrString(self, "lineno", lineno)
+			    || PyObject_SetAttrString(self, "offset", offset)
+			    || PyObject_SetAttrString(self, "text", text);
+			Py_DECREF(text);
+		    }
+		    Py_DECREF(offset);
+		}
+		Py_DECREF(lineno);
+	    }
+	    Py_DECREF(filename);
+	}
 	Py_DECREF(info);
 
-	if (filename && lineno && offset && text) {
-	    status = PyObject_SetAttrString(self, "filename", filename) ||
-		PyObject_SetAttrString(self, "lineno", lineno) ||
-		PyObject_SetAttrString(self, "offset", offset) ||
-		PyObject_SetAttrString(self, "text", text);
-	}
-	Py_XDECREF(filename);
-	Py_XDECREF(lineno);
-	Py_XDECREF(offset);
-	Py_XDECREF(text);
-
 	if (status)
 	    goto finally;
     }