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.
This commit is contained in:
Fred Drake 2001-02-28 21:52:10 +00:00
parent 9c98a428ef
commit 9da7f3b4f4

View file

@ -702,29 +702,35 @@ SyntaxError__init__(PyObject *self, PyObject *args)
} }
if (lenargs == 2) { if (lenargs == 2) {
PyObject *info = PySequence_GetItem(args, 1); PyObject *info = PySequence_GetItem(args, 1);
PyObject *filename, *lineno, *offset, *text; PyObject *filename = NULL, *lineno = NULL;
PyObject *offset = NULL, *text = NULL;
int status = 1; int status = 1;
if (!info) if (!info)
goto finally; goto finally;
filename = PySequence_GetItem(info, 0); filename = PySequence_GetItem(info, 0);
if (filename != NULL) {
lineno = PySequence_GetItem(info, 1); lineno = PySequence_GetItem(info, 1);
if (lineno != NULL) {
offset = PySequence_GetItem(info, 2); offset = PySequence_GetItem(info, 2);
if (offset != NULL) {
text = PySequence_GetItem(info, 3); text = PySequence_GetItem(info, 3);
if (text != NULL) {
Py_DECREF(info); status =
PyObject_SetAttrString(self, "filename", filename)
if (filename && lineno && offset && text) { || PyObject_SetAttrString(self, "lineno", lineno)
status = PyObject_SetAttrString(self, "filename", filename) || || PyObject_SetAttrString(self, "offset", offset)
PyObject_SetAttrString(self, "lineno", lineno) || || PyObject_SetAttrString(self, "text", text);
PyObject_SetAttrString(self, "offset", offset) || Py_DECREF(text);
PyObject_SetAttrString(self, "text", text);
} }
Py_XDECREF(filename); Py_DECREF(offset);
Py_XDECREF(lineno); }
Py_XDECREF(offset); Py_DECREF(lineno);
Py_XDECREF(text); }
Py_DECREF(filename);
}
Py_DECREF(info);
if (status) if (status)
goto finally; goto finally;