summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-03-02 03:30:41 (GMT)
committerGuido van Rossum <guido@python.org>2001-03-02 03:30:41 (GMT)
commit207fda61a5ee3d4ab0bac3e9d0415c73a9d6e4d0 (patch)
treed542de14e1e394b3715a273647b0a171376bef82 /Python
parent677898a3918470d718550aee9969cebcd4b1a61b (diff)
downloadcpython-207fda61a5ee3d4ab0bac3e9d0415c73a9d6e4d0.zip
cpython-207fda61a5ee3d4ab0bac3e9d0415c73a9d6e4d0.tar.gz
cpython-207fda61a5ee3d4ab0bac3e9d0415c73a9d6e4d0.tar.bz2
Refactored the warning-issuing code more.
Made sure that the warnings issued by symtable_check_unoptimized() (about import * and exec) contain the proper filename and line number, and are transformed into SyntaxError exceptions with -Werror.
Diffstat (limited to 'Python')
-rw-r--r--Python/compile.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/Python/compile.c b/Python/compile.c
index fe4d05e..f553262 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -4015,18 +4015,26 @@ get_ref_type(struct compiling *c, char *name)
return -1; /* can't get here */
}
-/* Helper function to issue symbol table warnings */
+/* Helper functions to issue warnings */
static int
-symtable_warn(struct symtable *st, char *msg)
+issue_warning(char *msg, char *filename, int lineno)
{
- if (PyErr_WarnExplicit(PyExc_SyntaxWarning, msg, st->st_filename,
- st->st_cur->ste_lineno, NULL, NULL) < 0) {
+ if (PyErr_WarnExplicit(PyExc_SyntaxWarning, msg, filename,
+ lineno, NULL, NULL) < 0) {
if (PyErr_ExceptionMatches(PyExc_SyntaxWarning)) {
PyErr_SetString(PyExc_SyntaxError, msg);
- PyErr_SyntaxLocation(st->st_filename,
- st->st_cur->ste_lineno);
+ PyErr_SyntaxLocation(filename, lineno);
}
+ return -1;
+ }
+ return 0;
+}
+
+static int
+symtable_warn(struct symtable *st, char *msg)
+{
+ if (issue_warning(msg, st->st_filename, st->st_cur->ste_lineno) < 0) {
st->st_errors++;
return -1;
}
@@ -4195,11 +4203,9 @@ symtable_check_unoptimized(struct compiling *c,
PyErr_SyntaxLocation(c->c_symtable->st_filename,
ste->ste_lineno);
return -1;
- } else {
- /* XXX if the warning becomes an exception, we should
- attached more info to it. */
- if (PyErr_Warn(PyExc_SyntaxWarning, buf) < 0)
- return -1;
+ }
+ else {
+ return issue_warning(buf, c->c_filename, ste->ste_lineno);
}
return 0;
}