summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2001-02-28 21:52:10 (GMT)
committerFred Drake <fdrake@acm.org>2001-02-28 21:52:10 (GMT)
commit9da7f3b4f44eb4e2c9782f9f73da5e46dc1b9f96 (patch)
tree2b89adffd1c9744afefb578f6d3f2ec08eb6bbee
parent9c98a428ef2d4ec0084d2cbc327ed2b94e9afe66 (diff)
downloadcpython-9da7f3b4f44eb4e2c9782f9f73da5e46dc1b9f96.zip
cpython-9da7f3b4f44eb4e2c9782f9f73da5e46dc1b9f96.tar.gz
cpython-9da7f3b4f44eb4e2c9782f9f73da5e46dc1b9f96.tar.bz2
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.
-rw-r--r--Python/exceptions.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/Python/exceptions.c b/Python/exceptions.c
index 0c61c5d..f262ef2 100644
--- a/Python/exceptions.c
+++ b/Python/exceptions.c
@@ -702,29 +702,35 @@ SyntaxError__init__(PyObject *self, PyObject *args)
}
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);
-
- 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);
+ 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_XDECREF(filename);
- Py_XDECREF(lineno);
- Py_XDECREF(offset);
- Py_XDECREF(text);
+ Py_DECREF(info);
if (status)
goto finally;