[Python-checkins] python/dist/src/Python symtable.c, 2.10.8.22,
2.10.8.23
nnorwitz at users.sourceforge.net
nnorwitz at users.sourceforge.net
Sun Mar 21 15:49:23 EST 2004
Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21395/Python
Modified Files:
Tag: ast-branch
symtable.c
Log Message:
fix nested closures
Index: symtable.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/symtable.c,v
retrieving revision 2.10.8.22
retrieving revision 2.10.8.23
diff -C2 -d -r2.10.8.22 -r2.10.8.23
*** symtable.c 21 Mar 2004 17:14:32 -0000 2.10.8.22
--- symtable.c 21 Mar 2004 20:49:13 -0000 2.10.8.23
***************
*** 369,373 ****
analyze_cells(PyObject *scope, PyObject *free)
{
! PyObject *name, *v, *w;
int flags, pos = 0, success = 0;
--- 369,373 ----
analyze_cells(PyObject *scope, PyObject *free)
{
! PyObject *name, *v, *w;
int flags, pos = 0, success = 0;
***************
*** 399,405 ****
/* Enter the final scope information into the st_symbols dict. */
static int
! update_symbols(PyObject *symbols, PyObject *scope)
{
! PyObject *name, *v, *u, *w;
int i, flags, pos = 0;
--- 399,406 ----
/* Enter the final scope information into the st_symbols dict. */
static int
! update_symbols(PyObject *symbols, PyObject *scope,
! PyObject *bound, PyObject *free)
{
! PyObject *name, *v, *u, *w, *free_value = NULL;
int i, flags, pos = 0;
***************
*** 418,421 ****
--- 419,441 ----
Py_DECREF(u);
}
+
+ free_value = PyInt_FromLong(FREE << SCOPE_OFF);
+ if (!free_value)
+ return 0;
+
+ /* add a free variable when it's only use is for creating a closure */
+ pos = 0;
+ while (PyDict_Next(free, &pos, &name, &v)) {
+ if (PyDict_GetItem(symbols, name))
+ continue; /* it's not free, probably a cell */
+ if (!PyDict_GetItem(bound, name))
+ continue; /* it's a global */
+
+ if (PyDict_SetItem(symbols, name, free_value) < 0) {
+ Py_DECREF(free_value);
+ return 0;
+ }
+ }
+ Py_DECREF(free_value);
return 1;
}
***************
*** 447,451 ****
if (!newbound)
goto error;
! if (ste->ste_type != ClassBlock) {
if (PyDict_Update(newbound, local) < 0)
goto error;
--- 467,471 ----
if (!newbound)
goto error;
! if (ste->ste_type == FunctionBlock) {
if (PyDict_Update(newbound, local) < 0)
goto error;
***************
*** 459,463 ****
PyObject *c = PyList_GET_ITEM(ste->ste_children, i);
assert(c && PySTEntry_Check(c));
! if (!analyze_block((PySTEntryObject *)c, local, free))
goto error;
}
--- 479,483 ----
PyObject *c = PyList_GET_ITEM(ste->ste_children, i);
assert(c && PySTEntry_Check(c));
! if (!analyze_block((PySTEntryObject *)c, newbound, free))
goto error;
}
***************
*** 465,469 ****
if (!analyze_cells(scope, free))
goto error;
! if (!update_symbols(ste->ste_symbols, scope))
goto error;
success = 1;
--- 485,489 ----
if (!analyze_cells(scope, free))
goto error;
! if (!update_symbols(ste->ste_symbols, scope, bound, free))
goto error;
success = 1;
More information about the Python-checkins
mailing list