@@ -2158,9 +2158,6 @@ static int
21582158com_make_closure (struct compiling * c , PyCodeObject * co )
21592159{
21602160 int i , free = PyTuple_GET_SIZE (co -> co_freevars );
2161- /* If the code is compiled with st->st_nested_scopes == 0,
2162- then no variable will ever be added to co_freevars.
2163- */
21642161 if (free == 0 )
21652162 return 0 ;
21662163 for (i = 0 ; i < free ; ++ i ) {
@@ -3928,7 +3925,7 @@ PyNode_CompileSymtable(node *n, char *filename)
39283925 symtable_node (st , n );
39293926 if (st -> st_errors > 0 )
39303927 goto fail ;
3931-
3928+
39323929 return st ;
39333930 fail :
39343931 PyMem_Free ((void * )ff );
@@ -4056,50 +4053,36 @@ PyCode_Addr2Line(PyCodeObject *co, int addrq)
40564053static int
40574054get_ref_type (struct compiling * c , char * name )
40584055{
4056+ char buf [350 ];
40594057 PyObject * v ;
4060- if (c -> c_symtable -> st_nested_scopes ) {
4061- if (PyDict_GetItemString (c -> c_cellvars , name ) != NULL )
4062- return CELL ;
4063- if (PyDict_GetItemString (c -> c_locals , name ) != NULL )
4064- return LOCAL ;
4065- if (PyDict_GetItemString (c -> c_freevars , name ) != NULL )
4066- return FREE ;
4067- v = PyDict_GetItemString (c -> c_globals , name );
4068- if (v ) {
4069- if (v == Py_None )
4070- return GLOBAL_EXPLICIT ;
4071- else {
4072- return GLOBAL_IMPLICIT ;
4073- }
4074- }
4075- } else {
4076- if (PyDict_GetItemString (c -> c_locals , name ) != NULL )
4077- return LOCAL ;
4078- v = PyDict_GetItemString (c -> c_globals , name );
4079- if (v ) {
4080- if (v == Py_None )
4081- return GLOBAL_EXPLICIT ;
4082- else {
4083- return GLOBAL_IMPLICIT ;
4084- }
4085- }
4086- }
4087- {
4088- char buf [350 ];
4089- sprintf (buf ,
4090- "unknown scope for %.100s in %.100s(%s) "
4091- "in %s\nsymbols: %s\nlocals: %s\nglobals: %s\n" ,
4092- name , c -> c_name ,
4093- PyObject_REPR (c -> c_symtable -> st_cur -> ste_id ),
4094- c -> c_filename ,
4095- PyObject_REPR (c -> c_symtable -> st_cur -> ste_symbols ),
4096- PyObject_REPR (c -> c_locals ),
4097- PyObject_REPR (c -> c_globals )
4098- );
40994058
4100- Py_FatalError (buf );
4101- }
4102- return -1 ; /* can't get here */
4059+ if (PyDict_GetItemString (c -> c_cellvars , name ) != NULL )
4060+ return CELL ;
4061+ if (PyDict_GetItemString (c -> c_locals , name ) != NULL )
4062+ return LOCAL ;
4063+ if (PyDict_GetItemString (c -> c_freevars , name ) != NULL )
4064+ return FREE ;
4065+ v = PyDict_GetItemString (c -> c_globals , name );
4066+ if (v ) {
4067+ if (v == Py_None )
4068+ return GLOBAL_EXPLICIT ;
4069+ else {
4070+ return GLOBAL_IMPLICIT ;
4071+ }
4072+ }
4073+ sprintf (buf ,
4074+ "unknown scope for %.100s in %.100s(%s) "
4075+ "in %s\nsymbols: %s\nlocals: %s\nglobals: %s\n" ,
4076+ name , c -> c_name ,
4077+ PyObject_REPR (c -> c_symtable -> st_cur -> ste_id ),
4078+ c -> c_filename ,
4079+ PyObject_REPR (c -> c_symtable -> st_cur -> ste_symbols ),
4080+ PyObject_REPR (c -> c_locals ),
4081+ PyObject_REPR (c -> c_globals )
4082+ );
4083+
4084+ Py_FatalError (buf );
4085+ return -1 ;
41034086}
41044087
41054088/* Helper functions to issue warnings */
@@ -4375,60 +4358,10 @@ symtable_check_unoptimized(struct compiling *c,
43754358 }
43764359 }
43774360
4378- if (c -> c_symtable -> st_nested_scopes ) {
4379- PyErr_SetString (PyExc_SyntaxError , buf );
4380- PyErr_SyntaxLocation (c -> c_symtable -> st_filename ,
4381- ste -> ste_opt_lineno );
4382- return -1 ;
4383- }
4384- else {
4385- return issue_warning (buf , c -> c_filename , ste -> ste_lineno );
4386- }
4387- return 0 ;
4388- }
4389-
4390- static int
4391- symtable_check_shadow (struct symtable * st , PyObject * name , int flags )
4392- {
4393- char buf [500 ];
4394- PyObject * children , * v ;
4395- PySymtableEntryObject * child = NULL ;
4396- int i ;
4397-
4398- if (!(flags & DEF_BOUND ))
4399- return 0 ;
4400-
4401- /* The semantics of this code will change with nested scopes.
4402- It is defined in the current scope and referenced in a
4403- child scope. Under the old rules, the child will see a
4404- global. Under the new rules, the child will see the
4405- binding in the current scope.
4406- */
4407-
4408- /* Find name of child function that has free variable */
4409- children = st -> st_cur -> ste_children ;
4410- for (i = 0 ; i < PyList_GET_SIZE (children ); i ++ ) {
4411- int cflags ;
4412- child = (PySymtableEntryObject * )PyList_GET_ITEM (children , i );
4413- v = PyDict_GetItem (child -> ste_symbols , name );
4414- if (v == NULL )
4415- continue ;
4416- cflags = PyInt_AS_LONG (v );
4417- if (!(cflags & DEF_BOUND ))
4418- break ;
4419- }
4420-
4421- assert (child != NULL );
4422-
4423- sprintf (buf , "local name '%.100s' in '%.100s' shadows "
4424- "use of '%.100s' as global in nested scope '%.100s'" ,
4425- PyString_AS_STRING (name ),
4426- PyString_AS_STRING (st -> st_cur -> ste_name ),
4427- PyString_AS_STRING (name ),
4428- PyString_AS_STRING (child -> ste_name )
4429- );
4430-
4431- return symtable_warn (st , buf );
4361+ PyErr_SetString (PyExc_SyntaxError , buf );
4362+ PyErr_SyntaxLocation (c -> c_symtable -> st_filename ,
4363+ ste -> ste_opt_lineno );
4364+ return -1 ;
44324365}
44334366
44344367static int
@@ -4489,26 +4422,17 @@ symtable_load_symbols(struct compiling *c)
44894422 while (PyDict_Next (ste -> ste_symbols , & pos , & name , & v )) {
44904423 flags = PyInt_AS_LONG (v );
44914424
4492- if (st -> st_nested_scopes == 0
4493- && (flags & (DEF_FREE | DEF_FREE_CLASS ))) {
4494- if (symtable_check_shadow (st , name , flags ) < 0 )
4495- goto fail ;
4496- }
4497-
44984425 if (flags & DEF_FREE_GLOBAL )
44994426 /* undo the original DEF_FREE */
45004427 flags &= ~(DEF_FREE | DEF_FREE_CLASS );
45014428
45024429 /* Deal with names that need two actions:
4503- 1. Cell variables, which are also locals.
4430+ 1. Cell variables that are also locals.
45044431 2. Free variables in methods that are also class
45054432 variables or declared global.
45064433 */
4507- if (st -> st_nested_scopes ) {
4508- if (flags & (DEF_FREE | DEF_FREE_CLASS )) {
4434+ if (flags & (DEF_FREE | DEF_FREE_CLASS ))
45094435 symtable_resolve_free (c , name , flags , & si );
4510- }
4511- }
45124436
45134437 if (flags & DEF_STAR ) {
45144438 c -> c_argcount -- ;
@@ -4544,7 +4468,7 @@ symtable_load_symbols(struct compiling *c)
45444468 if (PyList_Append (c -> c_varnames , name ) < 0 )
45454469 goto fail ;
45464470 } else if (is_free (flags )) {
4547- if (ste -> ste_nested && st -> st_nested_scopes ) {
4471+ if (ste -> ste_nested ) {
45484472 v = PyInt_FromLong (si .si_nfrees ++ );
45494473 if (v == NULL )
45504474 goto fail ;
@@ -4553,25 +4477,22 @@ symtable_load_symbols(struct compiling *c)
45534477 Py_DECREF (v );
45544478 } else {
45554479 si .si_nimplicit ++ ;
4556- if (PyDict_SetItem (c -> c_globals , name ,
4557- implicit ) < 0 )
4558- goto fail ;
4559- if (st -> st_nscopes != 1 ) {
4560- v = PyInt_FromLong (flags );
4561- if (PyDict_SetItem (st -> st_global ,
4562- name , v ))
4563- goto fail ;
4564- Py_DECREF (v );
4565- }
4480+ if (PyDict_SetItem (c -> c_globals , name ,
4481+ implicit ) < 0 )
4482+ goto fail ;
4483+ if (st -> st_nscopes != 1 ) {
4484+ v = PyInt_FromLong (flags );
4485+ if (PyDict_SetItem (st -> st_global ,
4486+ name , v ))
4487+ goto fail ;
4488+ Py_DECREF (v );
4489+ }
45664490 }
45674491 }
45684492 }
45694493
45704494 assert (PyDict_Size (c -> c_freevars ) == si .si_nfrees );
45714495
4572- if (st -> st_nested_scopes == 0 )
4573- assert (si .si_nfrees == 0 );
4574-
45754496 if (si .si_ncells > 1 ) { /* one cell is always in order */
45764497 if (symtable_cellvar_offsets (& c -> c_cellvars , c -> c_argcount ,
45774498 c -> c_varnames , c -> c_flags ) < 0 )
@@ -4596,11 +4517,6 @@ symtable_init()
45964517 return NULL ;
45974518 st -> st_pass = 1 ;
45984519
4599- /* XXX Tim: Jeremy deleted the next line and everything went to hell.
4600- XXX It should probably get fixed by getting rid of st_nested_scopes
4601- XXX entirely. */
4602- st -> st_nested_scopes = 1 ;
4603-
46044520 st -> st_filename = NULL ;
46054521 if ((st -> st_stack = PyList_New (0 )) == NULL )
46064522 goto fail ;
0 commit comments