[Python-checkins] CVS: python/dist/src/Python compile.c,2.197,2.198
Jeremy Hylton
jhylton@users.sourceforge.net
Thu, 26 Apr 2001 19:29:43 -0700
Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv14809
Modified Files:
compile.c
Log Message:
Fix 2.1 nested scopes crash reported by Evan Simpson
The new test case demonstrates the bug. Be more careful in
symtable_resolve_free() to add a var to cells or frees only if it
won't be added under some other rule.
XXX Add new assertion that will catch this bug.
Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.197
retrieving revision 2.198
diff -C2 -r2.197 -r2.198
*** compile.c 2001/04/20 19:13:02 2.197
--- compile.c 2001/04/27 02:29:40 2.198
***************
*** 4058,4062 ****
static int
! symtable_resolve_free(struct compiling *c, PyObject *name,
struct symbol_info *si)
{
--- 4058,4062 ----
static int
! symtable_resolve_free(struct compiling *c, PyObject *name, int flags,
struct symbol_info *si)
{
***************
*** 4068,4076 ****
method and a free variable with the same name.
*/
-
if (c->c_symtable->st_cur->ste_type == TYPE_FUNCTION) {
v = PyInt_FromLong(si->si_ncells++);
dict = c->c_cellvars;
} else {
v = PyInt_FromLong(si->si_nfrees++);
dict = c->c_freevars;
--- 4068,4084 ----
method and a free variable with the same name.
*/
if (c->c_symtable->st_cur->ste_type == TYPE_FUNCTION) {
+ /* If it isn't declared locally, it can't be a cell. */
+ if (!(flags & (DEF_LOCAL | DEF_PARAM)))
+ return 0;
v = PyInt_FromLong(si->si_ncells++);
dict = c->c_cellvars;
} else {
+ /* If it is free anyway, then there is no need to do
+ anything here.
+ */
+ if (is_free(flags ^ DEF_FREE_CLASS)
+ || flags == DEF_FREE_CLASS)
+ return 0;
v = PyInt_FromLong(si->si_nfrees++);
dict = c->c_freevars;
***************
*** 4358,4365 ****
*/
if (flags & (DEF_FREE | DEF_FREE_CLASS)) {
! if ((ste->ste_type == TYPE_CLASS
! && flags != DEF_FREE_CLASS)
! || (flags & (DEF_LOCAL | DEF_PARAM)))
! symtable_resolve_free(c, name, &si);
}
--- 4366,4370 ----
*/
if (flags & (DEF_FREE | DEF_FREE_CLASS)) {
! symtable_resolve_free(c, name, flags, &si);
}
***************
*** 4420,4423 ****
--- 4425,4437 ----
}
}
+
+ /*
+ fprintf(stderr,
+ "cells %d: %s\n"
+ "frees %d: %s\n",
+ si.si_ncells, PyObject_REPR(c->c_cellvars),
+ si.si_nfrees, PyObject_REPR(c->c_freevars));
+ */
+ assert(PyDict_Size(c->c_freevars) == si.si_nfrees);
if (si.si_ncells > 1) { /* one cell is always in order */