[Python-Dev] puzzled about old checkin to pythonrun.c
Jeremy Hylton
jeremy@alum.mit.edu
Wed, 28 Feb 2001 00:28:08 -0500 (EST)
Fred,
You made a change to the syntax error generation code last August.
I don't understand what the code is doing. It appears that the code
you added is redundant, but it's hard to tell for sure because
responsbility for generating well-formed SyntaxErrors is spread
across several files.
The code you added in pythonrun.c, line 1084, in err_input(), starts
with the test (v != NULL):
w = Py_BuildValue("(sO)", msg, v);
PyErr_SetObject(errtype, w);
Py_XDECREF(w);
if (v != NULL) {
PyObject *exc, *tb;
PyErr_Fetch(&errtype, &exc, &tb);
PyErr_NormalizeException(&errtype, &exc, &tb);
if (PyObject_SetAttrString(exc, "filename",
PyTuple_GET_ITEM(v, 0)))
PyErr_Clear();
if (PyObject_SetAttrString(exc, "lineno",
PyTuple_GET_ITEM(v, 1)))
PyErr_Clear();
if (PyObject_SetAttrString(exc, "offset",
PyTuple_GET_ITEM(v, 2)))
PyErr_Clear();
Py_DECREF(v);
PyErr_Restore(errtype, exc, tb);
}
What's weird about this code is that the __init__ code for a
SyntaxError (all errors will be SyntaxErrors at this point) sets
filename, lineno, and offset. Each of the values is passed to the
constructor as the tuple v; then the new code gets the items out of
the tuple and sets the explicitly.
You also made a bunch of changes to SyntaxError__str__ at the same
time. I wonder if they were sufficient to fix the bug (which has
tracker aid 210628 incidentally).
Can you shed any light?
Jeremy