[Python-checkins] CVS: python/dist/src/Python symtable.c,2.9,2.10
Jeremy Hylton
jhylton@users.sourceforge.net
Sun, 09 Dec 2001 16:53:20 -0800
Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv12577
Modified Files:
symtable.c
Log Message:
Add a comment explaining the st_symbols cache.
Index: symtable.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/symtable.c,v
retrieving revision 2.9
retrieving revision 2.10
diff -C2 -d -r2.9 -r2.10
*** symtable.c 2001/12/08 23:40:38 2.9
--- symtable.c 2001/12/10 00:53:18 2.10
***************
*** 5,8 ****
--- 5,22 ----
#include "structmember.h"
+ /* The compiler uses this function to load a PySymtableEntry object
+ for a code block. Each block is loaded twice, once during the
+ symbol table pass and once during the code gen pass. Entries
+ created during the first pass are cached for the second pass, using
+ the st_symbols dictionary.
+
+ The cache is keyed by st_nscopes. Each code block node in a
+ module's parse tree can be assigned a unique id based on the order
+ in which the nodes are visited by the compiler. This strategy
+ works so long as the symbol table and codegen passes visit the same
+ nodes in the same order.
+ */
+
+
PyObject *
PySymtableEntry_New(struct symtable *st, char *name, int type, int lineno)
***************
*** 15,19 ****
goto fail;
v = PyDict_GetItem(st->st_symbols, k);
! if (v) /* XXX could check that name, type, lineno match */ {
Py_DECREF(k);
Py_INCREF(v);
--- 29,33 ----
goto fail;
v = PyDict_GetItem(st->st_symbols, k);
! if (v) {
Py_DECREF(k);
Py_INCREF(v);