[Python-checkins] CVS: python/dist/src/Python compile.c,2.158,2.159
Jeremy Hylton
jhylton@users.sourceforge.net
Fri, 02 Feb 2001 12:01:12 -0800
Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv13654/Python
Modified Files:
compile.c
Log Message:
Fix symbol table pass to generation SyntaxError exceptions that
include the filename and line number.
Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.158
retrieving revision 2.159
diff -C2 -r2.158 -r2.159
*** compile.c 2001/02/02 18:19:15 2.158
--- compile.c 2001/02/02 20:01:10 2.159
***************
*** 372,400 ****
static void
! com_error(struct compiling *c, PyObject *exc, char *msg)
{
! PyObject *v, *tb, *tmp;
! if (c == NULL) {
! /* Error occurred via symtable call to
! is_constant_false */
! PyErr_SetString(exc, msg);
! return;
! }
! c->c_errors++;
! if (c->c_lineno <= 1) {
! /* Unknown line number or single interactive command */
! PyErr_SetString(exc, msg);
! return;
! }
! v = PyString_FromString(msg);
! if (v == NULL)
! return; /* MemoryError, too bad */
! PyErr_SetObject(exc, v);
! Py_DECREF(v);
/* add attributes for the line number and filename for the error */
PyErr_Fetch(&exc, &v, &tb);
PyErr_NormalizeException(&exc, &v, &tb);
! tmp = PyInt_FromLong(c->c_lineno);
if (tmp == NULL)
PyErr_Clear();
--- 372,383 ----
static void
! set_error_location(char *filename, int lineno)
{
! PyObject *exc, *v, *tb, *tmp;
/* add attributes for the line number and filename for the error */
PyErr_Fetch(&exc, &v, &tb);
PyErr_NormalizeException(&exc, &v, &tb);
! tmp = PyInt_FromLong(lineno);
if (tmp == NULL)
PyErr_Clear();
***************
*** 404,409 ****
Py_DECREF(tmp);
}
! if (c->c_filename != NULL) {
! tmp = PyString_FromString(c->c_filename);
if (tmp == NULL)
PyErr_Clear();
--- 387,392 ----
Py_DECREF(tmp);
}
! if (filename != NULL) {
! tmp = PyString_FromString(filename);
if (tmp == NULL)
PyErr_Clear();
***************
*** 417,421 ****
--- 400,429 ----
}
+ static void
+ com_error(struct compiling *c, PyObject *exc, char *msg)
+ {
+ PyObject *v;
+ if (c == NULL) {
+ /* Error occurred via symtable call to
+ is_constant_false */
+ PyErr_SetString(exc, msg);
+ return;
+ }
+ c->c_errors++;
+ if (c->c_lineno <= 1) {
+ /* Unknown line number or single interactive command */
+ PyErr_SetString(exc, msg);
+ return;
+ }
+ v = PyString_FromString(msg);
+ if (v == NULL)
+ return; /* MemoryError, too bad */
+ PyErr_SetObject(exc, v);
+ Py_DECREF(v);
+
+ set_error_location(c->c_filename, c->c_lineno);
+ }
+
/* Interface to the block stack */
***************
*** 3805,3808 ****
--- 3813,3817 ----
if (st == NULL)
return NULL;
+ assert(st->st_symbols != NULL);
symtable_enter_scope(st, TOP, TYPE(n), n->n_lineno);
if (st->st_errors > 0) {
***************
*** 3953,3956 ****
--- 3962,3966 ----
if ((c->c_symtable = symtable_init(0)) == NULL)
return -1;
+ c->c_symtable->st_filename = c->c_filename;
symtable_enter_scope(c->c_symtable, TOP, TYPE(n), n->n_lineno);
if (c->c_symtable->st_errors > 0)
***************
*** 4058,4066 ****
if ((info & DEF_PARAM)
&& (PyString_AS_STRING(name)[0] != '.')){
! char buf[500];
! sprintf(buf,
! "name '%.400s' is local and global",
! PyString_AS_STRING(name));
! com_error(c, PyExc_SyntaxError, buf);
goto fail;
}
--- 4068,4076 ----
if ((info & DEF_PARAM)
&& (PyString_AS_STRING(name)[0] != '.')){
! PyErr_Format(PyExc_SyntaxError,
! "name '%.400s' is local and global",
! PyString_AS_STRING(name));
! set_error_location(st->st_filename,
! st->st_cur_lineno);
goto fail;
}
***************
*** 4120,4130 ****
c->c_flags |= CO_OPTIMIZED;
else if (ncells || nfrees) {
! char buf[256];
! /* XXX need better error message */
! sprintf(buf,
"function %.100s: may not use lexical scoping"
" and 'import *' or exec in same function",
PyString_AS_STRING(st->st_cur_name));
! com_error(c, PyExc_SyntaxError, buf);
return -1;
}
--- 4130,4139 ----
c->c_flags |= CO_OPTIMIZED;
else if (ncells || nfrees) {
! PyErr_Format(PyExc_SyntaxError,
"function %.100s: may not use lexical scoping"
" and 'import *' or exec in same function",
PyString_AS_STRING(st->st_cur_name));
! set_error_location(st->st_filename,
! st->st_cur_lineno);
return -1;
}
***************
*** 4149,4152 ****
--- 4158,4162 ----
st->st_pass = 1;
st->st_keep = keep;
+ st->st_filename = NULL;
if ((st->st_stack = PyList_New(0)) == NULL)
goto fail;
***************
*** 4161,4164 ****
--- 4171,4175 ----
if (PyDict_SetItemString(st->st_symbols, TOP, d) < 0)
goto fail;
+ st->st_global = d;
Py_DECREF(d);
if (keep) {
***************
*** 4168,4172 ****
} else
st->st_scopes = NULL;
- st->st_global = d; /* use ref borrowed from st->st_symbols */
st->st_cur = NULL;
st->st_cur_id = NULL;
--- 4179,4182 ----
***************
*** 4506,4509 ****
--- 4516,4521 ----
PyErr_Format(PyExc_SyntaxError, DUPLICATE_ARGUMENT,
PyString_AsString(name));
+ set_error_location(st->st_filename,
+ st->st_cur_lineno);
return -1;
}
***************
*** 4845,4848 ****
--- 4857,4862 ----
PyErr_SetString(PyExc_SyntaxError,
ILLEGAL_IMPORT_STAR);
+ set_error_location(st->st_filename,
+ n->n_lineno);
st->st_errors++;
return;