Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1)

Unified Diff: Python/symtable.c

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Python/pythonrun.c ('k') | Python/thread.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Python/symtable.c Tue Jul 26 09:37:46 2011 +0300
+++ b/Python/symtable.c Mon Jul 25 09:47:18 2011 -0400
@@ -899,15 +899,18 @@
static int
symtable_exit_block(struct symtable *st, void *ast)
{
- Py_ssize_t size;
+ Py_ssize_t end;
- st->st_cur = NULL;
- size = PyList_GET_SIZE(st->st_stack);
- if (size) {
- if (PyList_SetSlice(st->st_stack, size - 1, size, NULL) < 0)
+ Py_CLEAR(st->st_cur);
+ end = PyList_GET_SIZE(st->st_stack) - 1;
+ if (end >= 0) {
+ st->st_cur = (PySTEntryObject *)PyList_GET_ITEM(st->st_stack,
+ end);
+ if (st->st_cur == NULL)
return 0;
- if (--size)
- st->st_cur = (PySTEntryObject *)PyList_GET_ITEM(st->st_stack, size - 1);
+ Py_INCREF(st->st_cur);
+ if (PySequence_DelItem(st->st_stack, end) < 0)
+ return 0;
}
return 1;
}
@@ -916,23 +919,23 @@
symtable_enter_block(struct symtable *st, identifier name, _Py_block_ty block,
void *ast, int lineno, int col_offset)
{
- PySTEntryObject *prev = NULL, *ste;
+ PySTEntryObject *prev = NULL;
- ste = ste_new(st, name, block, ast, lineno, col_offset);
- if (ste == NULL)
+ if (st->st_cur) {
+ prev = st->st_cur;
+ if (PyList_Append(st->st_stack, (PyObject *)st->st_cur) < 0) {
+ return 0;
+ }
+ Py_DECREF(st->st_cur);
+ }
+ st->st_cur = ste_new(st, name, block, ast, lineno, col_offset);
+ if (st->st_cur == NULL)
return 0;
- if (PyList_Append(st->st_stack, (PyObject *)ste) < 0) {
- Py_DECREF(ste);
- return 0;
- }
- prev = st->st_cur;
- /* The entry is owned by the stack. Borrow it for st_cur. */
- Py_DECREF(ste);
- st->st_cur = ste;
if (block == ModuleBlock)
st->st_global = st->st_cur->ste_symbols;
if (prev) {
- if (PyList_Append(prev->ste_children, (PyObject *)ste) < 0) {
+ if (PyList_Append(prev->ste_children,
+ (PyObject *)st->st_cur) < 0) {
return 0;
}
}
@@ -1026,6 +1029,12 @@
if (!symtable_visit_ ## TYPE((ST), (V))) \
return 0;
+#define VISIT_IN_BLOCK(ST, TYPE, V, S) \
+ if (!symtable_visit_ ## TYPE((ST), (V))) { \
+ symtable_exit_block((ST), (S)); \
+ return 0; \
+ }
+
#define VISIT_SEQ(ST, TYPE, SEQ) { \
int i; \
asdl_seq *seq = (SEQ); /* avoid variable capture */ \
@@ -1036,6 +1045,18 @@
} \
}
+#define VISIT_SEQ_IN_BLOCK(ST, TYPE, SEQ, S) { \
+ int i; \
+ asdl_seq *seq = (SEQ); /* avoid variable capture */ \
+ for (i = 0; i < asdl_seq_LEN(seq); i++) { \
+ TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \
+ if (!symtable_visit_ ## TYPE((ST), elt)) { \
+ symtable_exit_block((ST), (S)); \
+ return 0; \
+ } \
+ } \
+}
+
#define VISIT_SEQ_TAIL(ST, TYPE, SEQ, START) { \
int i; \
asdl_seq *seq = (SEQ); /* avoid variable capture */ \
@@ -1046,6 +1067,18 @@
} \
}
+#define VISIT_SEQ_TAIL_IN_BLOCK(ST, TYPE, SEQ, START, S) { \
+ int i; \
+ asdl_seq *seq = (SEQ); /* avoid variable capture */ \
+ for (i = (START); i < asdl_seq_LEN(seq); i++) { \
+ TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \
+ if (!symtable_visit_ ## TYPE((ST), elt)) { \
+ symtable_exit_block((ST), (S)); \
+ return 0; \
+ } \
+ } \
+}
+
#define VISIT_KWONLYDEFAULTS(ST, KW_DEFAULTS) { \
int i = 0; \
asdl_seq *seq = (KW_DEFAULTS); /* avoid variable capture */ \
@@ -1095,8 +1128,8 @@
FunctionBlock, (void *)s, s->lineno,
s->col_offset))
return 0;
- VISIT(st, arguments, s->v.FunctionDef.args);
- VISIT_SEQ(st, stmt, s->v.FunctionDef.body);
+ VISIT_IN_BLOCK(st, arguments, s->v.FunctionDef.args, s);
+ VISIT_SEQ_IN_BLOCK(st, stmt, s->v.FunctionDef.body, s);
if (!symtable_exit_block(st, s))
return 0;
break;
@@ -1123,7 +1156,7 @@
}
tmp = st->st_private;
st->st_private = s->v.ClassDef.name;
- VISIT_SEQ(st, stmt, s->v.ClassDef.body);
+ VISIT_SEQ_IN_BLOCK(st, stmt, s->v.ClassDef.body, s);
st->st_private = tmp;
if (!symtable_exit_block(st, s))
return 0;
@@ -1304,8 +1337,8 @@
FunctionBlock, (void *)e, e->lineno,
e->col_offset))
return 0;
- VISIT(st, arguments, e->v.Lambda.args);
- VISIT(st, expr, e->v.Lambda.body);
+ VISIT_IN_BLOCK(st, arguments, e->v.Lambda.args, (void*)e);
+ VISIT_IN_BLOCK(st, expr, e->v.Lambda.body, (void*)e);
if (!symtable_exit_block(st, (void *)e))
return 0;
break;
@@ -1625,12 +1658,13 @@
symtable_exit_block(st, (void *)e);
return 0;
}
- VISIT(st, expr, outermost->target);
- VISIT_SEQ(st, expr, outermost->ifs);
- VISIT_SEQ_TAIL(st, comprehension, generators, 1);
+ VISIT_IN_BLOCK(st, expr, outermost->target, (void*)e);
+ VISIT_SEQ_IN_BLOCK(st, expr, outermost->ifs, (void*)e);
+ VISIT_SEQ_TAIL_IN_BLOCK(st, comprehension,
+ generators, 1, (void*)e);
if (value)
- VISIT(st, expr, value);
- VISIT(st, expr, elt);
+ VISIT_IN_BLOCK(st, expr, value, (void*)e);
+ VISIT_IN_BLOCK(st, expr, elt, (void*)e);
return symtable_exit_block(st, (void *)e);
}
« no previous file with comments | « Python/pythonrun.c ('k') | Python/thread.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+