From 8246a68a3e1768bf0192a15966314e820212d000 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sat, 16 Mar 2013 09:15:47 -0700 Subject: reject non-docs strings between future imports (closes #17434) --- Python/future.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'Python/future.c') diff --git a/Python/future.c b/Python/future.c index d24ae416ff..345efb2167 100644 --- a/Python/future.c +++ b/Python/future.c @@ -58,11 +58,14 @@ future_check_features(PyFutureFeatures *ff, stmt_ty s, const char *filename) static int future_parse(PyFutureFeatures *ff, mod_ty mod, const char *filename) { - int i, found_docstring = 0, done = 0, prev_line = 0; + int i, done = 0, prev_line = 0; if (!(mod->kind == Module_kind || mod->kind == Interactive_kind)) return 1; + if (asdl_seq_LEN(mod->v.Module.body) == 0) + return 1; + /* A subsequent pass will detect future imports that don't appear at the beginning of the file. There's one case, however, that is easier to handle here: A series of imports @@ -71,8 +74,13 @@ future_parse(PyFutureFeatures *ff, mod_ty mod, const char *filename) but is preceded by a regular import. */ + i = 0; + stmt_ty first = (stmt_ty)asdl_seq_GET(mod->v.Module.body, i); + if (first->kind == Expr_kind && first->v.Expr.value->kind == Str_kind) + i++; - for (i = 0; i < asdl_seq_LEN(mod->v.Module.body); i++) { + + for (; i < asdl_seq_LEN(mod->v.Module.body); i++) { stmt_ty s = (stmt_ty)asdl_seq_GET(mod->v.Module.body, i); if (done && s->lineno > prev_line) @@ -99,18 +107,13 @@ future_parse(PyFutureFeatures *ff, mod_ty mod, const char *filename) return 0; ff->ff_lineno = s->lineno; } - else + else { done = 1; + } } - else if (s->kind == Expr_kind && !found_docstring) { - expr_ty e = s->v.Expr.value; - if (e->kind != Str_kind) - done = 1; - else - found_docstring = 1; - } - else + else { done = 1; + } } return 1; } -- cgit v1.2.1 From 666546a04ab992815b3093a3c24ad140a42f81e7 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Sat, 16 Mar 2013 15:38:28 -0700 Subject: C89 compliance --- Python/future.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Python/future.c') diff --git a/Python/future.c b/Python/future.c index 345efb2167..80978147f5 100644 --- a/Python/future.c +++ b/Python/future.c @@ -59,6 +59,7 @@ static int future_parse(PyFutureFeatures *ff, mod_ty mod, const char *filename) { int i, done = 0, prev_line = 0; + stmt_ty first; if (!(mod->kind == Module_kind || mod->kind == Interactive_kind)) return 1; @@ -75,7 +76,7 @@ future_parse(PyFutureFeatures *ff, mod_ty mod, const char *filename) */ i = 0; - stmt_ty first = (stmt_ty)asdl_seq_GET(mod->v.Module.body, i); + first = (stmt_ty)asdl_seq_GET(mod->v.Module.body, i); if (first->kind == Expr_kind && first->v.Expr.value->kind == Str_kind) i++; -- cgit v1.2.1