[Python-checkins] CVS: python/dist/src/Python compile.c,2.196.2.2,2.196.2.3

Anthony Baxter anthonybaxter@users.sourceforge.net
2001年11月20日 22:21:20 -0800


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv24579
Modified Files:
 Tag: release21-maint
	compile.c 
Log Message:
backport of jeremy's 2.227:
Fix for SF bug [ #471928 ] global made w/nested list comprehensions
. Initially I was going to just rip out the bits of this that fixed this
 bug, but the rest of the code looks (after a fair amount of staring at
 it) like it's ok - variable renames, that sort of thing. 
 flames and "hey, no way!" to me, or to python-dev.
 It felt safer to just go with the full patch, rather than butchering
 it.
Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.196.2.2
retrieving revision 2.196.2.3
diff -C2 -d -r2.196.2.2 -r2.196.2.3
*** compile.c	2001年06月27日 14:04:03	2.196.2.2
--- compile.c	2001年11月21日 06:21:18	2.196.2.3
***************
*** 4824,4828 ****
 symtable_node(struct symtable *st, node *n)
 {
! 	int i, start = 0;
 
 loop:
--- 4824,4828 ----
 symtable_node(struct symtable *st, node *n)
 {
! 	int i;
 
 loop:
***************
*** 4930,4939 ****
 		}
 		goto loop;
! 		/* watchout for fall-through logic below */
 	case argument:
! 		if (NCH(n) == 3) {
 			n = CHILD(n, 2);
 			goto loop;
 		}
 	case listmaker:
 		if (NCH(n) > 1 && TYPE(CHILD(n, 1)) == list_for) {
--- 4930,4965 ----
 		}
 		goto loop;
! 	case list_iter:
! 		n = CHILD(n, 0);
! 		if (TYPE(n) == list_for) {
! 			st->st_tmpname++;
! 			symtable_list_comprehension(st, n);
! 			st->st_tmpname--;
! 		} else {
! 			REQ(n, list_if);
! 			symtable_node(st, CHILD(n, 1));
! 			if (NCH(n) == 3) {
! 				n = CHILD(n, 2); 
! 				goto loop;
! 			}
! 		}
! 		break;
! 	case for_stmt:
! 		symtable_assign(st, CHILD(n, 1), 0);
! 		for (i = 3; i < NCH(n); ++i)
! 			if (TYPE(CHILD(n, i)) >= single_input)
! 				symtable_node(st, CHILD(n, i));
! 		break;
! 	/* The remaining cases fall through to default except in
! 	 special circumstances. This requires the individual cases
! 	 to be coded with great care, even though they look like
! 	 rather innocuous. Each case must double-check TYPE(n).
! 	*/
 	case argument:
! 		if (TYPE(n) == argument && NCH(n) == 3) {
 			n = CHILD(n, 2);
 			goto loop;
 		}
+ 		/* fall through */
 	case listmaker:
 		if (NCH(n) > 1 && TYPE(CHILD(n, 1)) == list_for) {
***************
*** 4942,4947 ****
 			symtable_node(st, CHILD(n, 0));
 			st->st_tmpname--;
! 			return;
 		}
 	case atom:
 		if (TYPE(n) == atom && TYPE(CHILD(n, 0)) == NAME) {
--- 4968,4974 ----
 			symtable_node(st, CHILD(n, 0));
 			st->st_tmpname--;
! 			break;
 		}
+ 		/* fall through */
 	case atom:
 		if (TYPE(n) == atom && TYPE(CHILD(n, 0)) == NAME) {
***************
*** 4949,4963 ****
 			break;
 		}
! 	case for_stmt:
! 		if (TYPE(n) == for_stmt) {
! 			symtable_assign(st, CHILD(n, 1), 0);
! 			start = 3;
! 		}
 	default:
 		if (NCH(n) == 1) {
 			n = CHILD(n, 0);
 			goto loop;
 		}
! 		for (i = start; i < NCH(n); ++i)
 			if (TYPE(CHILD(n, i)) >= single_input)
 				symtable_node(st, CHILD(n, i));
--- 4976,4989 ----
 			break;
 		}
! 		/* fall through */
 	default:
+ 		/* Walk over every non-token child with a special case
+ 		 for one child.
+ 		*/
 		if (NCH(n) == 1) {
 			n = CHILD(n, 0);
 			goto loop;
 		}
! 		for (i = 0; i < NCH(n); ++i)
 			if (TYPE(CHILD(n, i)) >= single_input)
 				symtable_node(st, CHILD(n, i));
***************
*** 5190,5195 ****
 }
 
 static void 
! symtable_assign(struct symtable *st, node *n, int flag)
 {
 	node *tmp;
--- 5216,5227 ----
 }
 
+ /* The third argument to symatble_assign() is a flag to be passed to
+ symtable_add_def() if it is eventually called. The flag is useful
+ to specify the particular type of assignment that should be
+ recorded, e.g. an assignment caused by import.
+ */
+ 
 static void 
! symtable_assign(struct symtable *st, node *n, int def_flag)
 {
 	node *tmp;
***************
*** 5223,5227 ****
 		} else {
 			for (i = 0; i < NCH(n); i += 2)
! 				symtable_assign(st, CHILD(n, i), flag);
 		}
 		return;
--- 5255,5259 ----
 		} else {
 			for (i = 0; i < NCH(n); i += 2)
! 				symtable_assign(st, CHILD(n, i), def_flag);
 		}
 		return;
***************
*** 5235,5239 ****
 			int i;
 			for (i = 0; i < NCH(n); i += 2)
! 				symtable_assign(st, CHILD(n, i), flag);
 			return;
 		}
--- 5267,5271 ----
 			int i;
 			for (i = 0; i < NCH(n); i += 2)
! 				symtable_assign(st, CHILD(n, i), def_flag);
 			return;
 		}
***************
*** 5247,5251 ****
 			if (strcmp(STR(tmp), "__debug__") == 0)
 				symtable_warn(st, ASSIGN_DEBUG);
! 			symtable_add_def(st, STR(tmp), DEF_LOCAL | flag);
 		}
 		return;
--- 5279,5283 ----
 			if (strcmp(STR(tmp), "__debug__") == 0)
 				symtable_warn(st, ASSIGN_DEBUG);
! 			symtable_add_def(st, STR(tmp), DEF_LOCAL | def_flag);
 		}
 		return;
***************
*** 5253,5268 ****
 		if (NCH(n) == 3)
 			symtable_add_def(st, STR(CHILD(n, 2)),
! 					 DEF_LOCAL | flag);
 		else
 			symtable_add_def(st,
 					 STR(CHILD(CHILD(n,
 							 0), 0)),
! 					 DEF_LOCAL | flag);
 		return;
 	case dotted_name:
! 		symtable_add_def(st, STR(CHILD(n, 0)), DEF_LOCAL | flag);
 		return;
 	case NAME:
! 		symtable_add_def(st, STR(n), DEF_LOCAL | flag);
 		return;
 	default:
--- 5285,5300 ----
 		if (NCH(n) == 3)
 			symtable_add_def(st, STR(CHILD(n, 2)),
! 					 DEF_LOCAL | def_flag);
 		else
 			symtable_add_def(st,
 					 STR(CHILD(CHILD(n,
 							 0), 0)),
! 					 DEF_LOCAL | def_flag);
 		return;
 	case dotted_name:
! 		symtable_add_def(st, STR(CHILD(n, 0)), DEF_LOCAL | def_flag);
 		return;
 	case NAME:
! 		symtable_add_def(st, STR(n), DEF_LOCAL | def_flag);
 		return;
 	default:
***************
*** 5277,5281 ****
 		for (i = 0; i < NCH(n); ++i)
 			if (TYPE(CHILD(n, i)) >= single_input)
! 				symtable_assign(st, CHILD(n, i), flag);
 	}
 }
--- 5309,5313 ----
 		for (i = 0; i < NCH(n); ++i)
 			if (TYPE(CHILD(n, i)) >= single_input)
! 				symtable_assign(st, CHILD(n, i), def_flag);
 	}
 }

AltStyle によって変換されたページ (->オリジナル) /