Skip to content

Commit 3144130

Browse files
committed
ANSI-C-ify the placement of local var declarations.
1 parent b2308bb commit 3144130

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

Python/ast.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -512,14 +512,14 @@ static asdl_seq *
512512
seq_for_testlist(struct compiling *c, const node *n)
513513
{
514514
/* testlist: test (',' test)* [','] */
515+
asdl_seq *seq;
516+
expr_ty expression;
517+
int i;
515518
assert(TYPE(n) == testlist
516519
|| TYPE(n) == listmaker
517520
|| TYPE(n) == testlist_gexp
518521
|| TYPE(n) == testlist_safe
519522
);
520-
asdl_seq *seq;
521-
expr_ty expression;
522-
int i;
523523

524524
seq = asdl_seq_new((NCH(n) + 1) / 2);
525525
if (!seq)
@@ -641,12 +641,13 @@ ast_for_arguments(struct compiling *c, const node *n)
641641
compiler_complex_args(CHILD(ch, 1)));
642642
}
643643
else if (TYPE(CHILD(ch, 0)) == NAME) {
644+
expr_ty name;
644645
if (!strcmp(STR(CHILD(ch, 0)), "None")) {
645646
ast_error(CHILD(ch, 0), "assignment to None");
646647
goto error;
647648
}
648-
expr_ty name = Name(NEW_IDENTIFIER(CHILD(ch, 0)),
649-
Param, LINENO(ch));
649+
name = Name(NEW_IDENTIFIER(CHILD(ch, 0)),
650+
Param, LINENO(ch));
650651
if (!name)
651652
goto error;
652653
asdl_seq_APPEND(args, name);
@@ -1897,12 +1898,13 @@ ast_for_expr_stmt(struct compiling *c, const node *n)
18971898
if (!targets)
18981899
return NULL;
18991900
for (i = 0; i < NCH(n) - 2; i += 2) {
1901+
expr_ty e;
19001902
node *ch = CHILD(n, i);
19011903
if (TYPE(ch) == yield_expr) {
19021904
ast_error(ch, "assignment to yield expression not possible");
19031905
goto error;
19041906
}
1905-
expr_ty e = ast_for_testlist(c, ch, 0);
1907+
e = ast_for_testlist(c, ch, 0);
19061908

19071909
/* set context to assign */
19081910
if (!e)

Python/compile.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2329,8 +2329,9 @@ compiler_import_as(struct compiler *c, identifier name, identifier asname)
23292329
src = dot + 1;
23302330
while (dot) {
23312331
/* NB src is only defined when dot != NULL */
2332+
PyObject *attr;
23322333
dot = strchr(src, '.');
2333-
PyObject *attr = PyString_FromStringAndSize(src,
2334+
attr = PyString_FromStringAndSize(src,
23342335
dot ? dot - src : strlen(src));
23352336
ADDOP_O(c, LOAD_ATTR, attr, names);
23362337
src = dot + 1;

Python/symtable.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,13 @@ analyze_cells(PyObject *scope, PyObject *free)
444444
static int
445445
check_unoptimized(const PySTEntryObject* ste) {
446446
char buf[300];
447+
const char* trailer;
447448

448449
if (ste->ste_type == ModuleBlock || !ste->ste_unoptimized
449450
|| !(ste->ste_free || ste->ste_child_free))
450451
return 1;
451452

452-
const char* trailer = (ste->ste_child_free ?
453+
trailer = (ste->ste_child_free ?
453454
"contains a nested function with free variables" :
454455
"is a nested function");
455456

@@ -621,8 +622,9 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
621622
/* Recursively call analyze_block() on each child block */
622623
for (i = 0; i < PyList_GET_SIZE(ste->ste_children); ++i) {
623624
PyObject *c = PyList_GET_ITEM(ste->ste_children, i);
625+
PySTEntryObject* entry;
624626
assert(c && PySTEntry_Check(c));
625-
PySTEntryObject* entry = (PySTEntryObject*)c;
627+
entry = (PySTEntryObject*)c;
626628
if (!analyze_block(entry, newbound, newfree, newglobal))
627629
goto error;
628630
if (entry->ste_free || entry->ste_child_free)

0 commit comments

Comments
 (0)