summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2005-12-19 04:27:42 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2005-12-19 04:27:42 (GMT)
commit5d0ad50f5acf84f2e8a1ca5c6951f333aef0e25a (patch)
tree970fad78e5e4f95fb438773c18cbd77f39cf5e06
parenta3bdc2c2a5dbb6fd7f7f655f6970f7559dca0497 (diff)
downloadcpython-5d0ad50f5acf84f2e8a1ca5c6951f333aef0e25a.zip
cpython-5d0ad50f5acf84f2e8a1ca5c6951f333aef0e25a.tar.gz
cpython-5d0ad50f5acf84f2e8a1ca5c6951f333aef0e25a.tar.bz2
Bug #889500, fix line number on SyntaxWarning for global declarations.
-rw-r--r--Misc/NEWS2
-rw-r--r--Python/symtable.c17
2 files changed, 12 insertions, 7 deletions
diff --git a/Misc/NEWS b/Misc/NEWS
index 7b27e49..222f93d 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 2.5 alpha 1?
Core and builtins
-----------------
+- Bug #889500, fix line number on SyntaxWarning for global declarations.
+
- Bug #1378022, UTF-8 files with a leading BOM crashed the interpreter.
- Support for converting hex strings to floats no longer works.
diff --git a/Python/symtable.c b/Python/symtable.c
index 016251c..6229b9e 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -4,13 +4,16 @@
#include "symtable.h"
#include "structmember.h"
-/* two error strings used for warnings */
+/* error strings used for warnings */
#define GLOBAL_AFTER_ASSIGN \
"name '%.400s' is assigned to before global declaration"
#define GLOBAL_AFTER_USE \
"name '%.400s' is used prior to global declaration"
+#define IMPORT_STAR_WARNING "import * only allowed at module level"
+
+
PySTEntryObject *
PySTEntry_New(struct symtable *st, identifier name, _Py_block_ty block,
void *key, int lineno)
@@ -152,7 +155,7 @@ PyTypeObject PySTEntry_Type = {
};
static int symtable_analyze(struct symtable *st);
-static int symtable_warn(struct symtable *st, char *msg);
+static int symtable_warn(struct symtable *st, char *msg, int lineno);
static int symtable_enter_block(struct symtable *st, identifier name,
_Py_block_ty block, void *ast, int lineno);
static int symtable_exit_block(struct symtable *st, void *ast);
@@ -686,10 +689,10 @@ symtable_analyze(struct symtable *st)
static int
-symtable_warn(struct symtable *st, char *msg)
+symtable_warn(struct symtable *st, char *msg, int lineno)
{
if (PyErr_WarnExplicit(PyExc_SyntaxWarning, msg, st->st_filename,
- st->st_cur->ste_lineno, NULL, NULL) < 0) {
+ lineno, NULL, NULL) < 0) {
if (PyErr_ExceptionMatches(PyExc_SyntaxWarning)) {
PyErr_SetString(PyExc_SyntaxError, msg);
PyErr_SyntaxLocation(st->st_filename,
@@ -1028,7 +1031,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
PyOS_snprintf(buf, sizeof(buf),
GLOBAL_AFTER_USE,
c_name);
- if (!symtable_warn(st, buf))
+ if (!symtable_warn(st, buf, s->lineno))
return 0;
}
if (!symtable_add_def(st, name, DEF_GLOBAL))
@@ -1277,8 +1280,8 @@ symtable_visit_alias(struct symtable *st, alias_ty a)
}
else {
if (st->st_cur->ste_type != ModuleBlock) {
- if (!symtable_warn(st,
- "import * only allowed at module level")) {
+ int lineno = st->st_cur->ste_lineno;
+ if (!symtable_warn(st, IMPORT_STAR_WARNING, lineno)) {
Py_DECREF(store_name);
return 0;
}