[Python-checkins] python/dist/src/Python compile.c, 2.318, 2.319 graminit.c, 2.36, 2.37

mwh at users.sourceforge.net mwh at users.sourceforge.net
Tue Aug 17 19:29:44 CEST 2004


Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1056/Python

Modified Files:
	compile.c graminit.c 
Log Message:
This is Mark Russell's patch:

[ 1009560 ] Fix @decorator evaluation order

>From the description:

Changes in this patch:

- Change Grammar/Grammar to require
newlines between adjacent decorators.

- Fix order of evaluation of decorators
in the C (compile.c) and python
(Lib/compiler/pycodegen.py) compilers

- Add better order of evaluation check
to test_decorators.py (test_eval_order)

- Update the decorator documentation in
the reference manual (improve description
of evaluation order and update syntax
description)

and the comment:

Used Brett's evaluation order (see
http://mail.python.org/pipermail/python-dev/2004-August/047835.html)

(I'm checking this in for Anthony who was having problems getting SF to
talk to him)


Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.318
retrieving revision 2.319
diff -C2 -d -r2.318 -r2.319
*** compile.c	15 Aug 2004 07:21:24 -0000	2.318
--- compile.c	17 Aug 2004 17:29:15 -0000	2.319
***************
*** 4108,4121 ****
  com_decorator(struct compiling *c, node *n)
  {
! 	/* decorator: '@' dotted_name [ '(' [arglist] ')' ] */
  	int nch = NCH(n);
! 	assert(nch >= 2);
  	REQ(CHILD(n, 0), AT);
  	com_decorator_name(c, CHILD(n, 1));
  
! 	if (nch > 2) {
! 		assert(nch == 4 || nch == 5);
  		REQ(CHILD(n, 2), LPAR);
! 		REQ(CHILD(n, nch - 1), RPAR);
  		com_call_function(c, CHILD(n, 3));
  	}
--- 4108,4122 ----
  com_decorator(struct compiling *c, node *n)
  {
! 	/* decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE */
  	int nch = NCH(n);
! 	assert(nch >= 3);
  	REQ(CHILD(n, 0), AT);
+ 	REQ(RCHILD(n, -1), NEWLINE);
  	com_decorator_name(c, CHILD(n, 1));
  
! 	if (nch > 3) {
! 		assert(nch == 5 || nch == 6);
  		REQ(CHILD(n, 2), LPAR);
! 		REQ(RCHILD(n, -2), RPAR);
  		com_call_function(c, CHILD(n, 3));
  	}
***************
*** 4125,4148 ****
  com_decorators(struct compiling *c, node *n)
  {
! 	int i, nch, ndecorators;
  	
! 	/* decorator ([NEWLINE] decorator)* NEWLINE */
  	nch = NCH(n);
! 	assert(nch >= 2);
! 	REQ(CHILD(n, nch - 1), NEWLINE);
  
! 	ndecorators = 0;
! 	/* the application order for decorators is the reverse of how they are
! 	   listed; bottom-up */
! 	nch -= 1;
! 	for (i = 0; i < nch; i+=1) {
  		node *ch = CHILD(n, i);
! 		if (TYPE(ch) != NEWLINE) {
! 			com_decorator(c, ch);
! 			++ndecorators;
! 		}
  	}
  
! 	return ndecorators;
  }
  
--- 4126,4143 ----
  com_decorators(struct compiling *c, node *n)
  {
! 	int i, nch;
  	
! 	/* decorator+ */
  	nch = NCH(n);
! 	assert(nch >= 1);
  
! 	for (i = 0; i < nch; ++i) {
  		node *ch = CHILD(n, i);
! 		REQ(ch, decorator);
! 
! 		com_decorator(c, ch);
  	}
  
! 	return nch;
  }
  
***************
*** 4152,4155 ****
--- 4147,4151 ----
  	PyObject *co;
  	int ndefs, ndecorators;
+ 	
  	REQ(n, funcdef);
  	/*          -6            -5   -4   -3         -2  -1
***************
*** 4160,4164 ****
  	else
  		ndecorators = 0;
! 	
  	ndefs = com_argdefs(c, n);
  	if (ndefs < 0)
--- 4156,4160 ----
  	else
  		ndecorators = 0;
! 
  	ndefs = com_argdefs(c, n);
  	if (ndefs < 0)
***************
*** 4180,4188 ****
  			com_addoparg(c, MAKE_FUNCTION, ndefs);
  		com_pop(c, ndefs);
  		while (ndecorators > 0) {
  			com_addoparg(c, CALL_FUNCTION, 1);
  			com_pop(c, 1);
! 			ndecorators--;
  		}
  		com_addop_varname(c, VAR_STORE, STR(RCHILD(n, -4)));
  		com_pop(c, 1);
--- 4176,4186 ----
  			com_addoparg(c, MAKE_FUNCTION, ndefs);
  		com_pop(c, ndefs);
+ 
  		while (ndecorators > 0) {
  			com_addoparg(c, CALL_FUNCTION, 1);
  			com_pop(c, 1);
! 			--ndecorators;
  		}
+ 
  		com_addop_varname(c, VAR_STORE, STR(RCHILD(n, -4)));
  		com_pop(c, 1);

Index: graminit.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/graminit.c,v
retrieving revision 2.36
retrieving revision 2.37
diff -C2 -d -r2.36 -r2.37
*** graminit.c	2 Aug 2004 06:10:10 -0000	2.36
--- graminit.c	17 Aug 2004 17:29:16 -0000	2.37
***************
*** 52,68 ****
  static arc arcs_3_2[2] = {
  	{13, 3},
! 	{0, 2},
  };
  static arc arcs_3_3[2] = {
! 	{14, 4},
! 	{15, 5},
  };
  static arc arcs_3_4[1] = {
! 	{15, 5},
  };
  static arc arcs_3_5[1] = {
! 	{0, 5},
  };
! static state states_3[6] = {
  	{1, arcs_3_0},
  	{1, arcs_3_1},
--- 52,71 ----
  static arc arcs_3_2[2] = {
  	{13, 3},
! 	{2, 4},
  };
  static arc arcs_3_3[2] = {
! 	{14, 5},
! 	{15, 6},
  };
  static arc arcs_3_4[1] = {
! 	{0, 4},
  };
  static arc arcs_3_5[1] = {
! 	{15, 6},
  };
! static arc arcs_3_6[1] = {
! 	{2, 4},
! };
! static state states_3[7] = {
  	{1, arcs_3_0},
  	{1, arcs_3_1},
***************
*** 71,74 ****
--- 74,78 ----
  	{1, arcs_3_4},
  	{1, arcs_3_5},
+ 	{1, arcs_3_6},
  };
  static arc arcs_4_0[1] = {
***************
*** 76,90 ****
  };
  static arc arcs_4_1[2] = {
- 	{2, 2},
  	{10, 1},
  };
! static arc arcs_4_2[2] = {
! 	{10, 1},
! 	{0, 2},
! };
! static state states_4[3] = {
  	{1, arcs_4_0},
  	{2, arcs_4_1},
- 	{2, arcs_4_2},
  };
  static arc arcs_5_0[2] = {
--- 80,89 ----
  };
  static arc arcs_4_1[2] = {
  	{10, 1},
+ 	{0, 1},
  };
! static state states_4[2] = {
  	{1, arcs_4_0},
  	{2, arcs_4_1},
  };
  static arc arcs_5_0[2] = {
***************
*** 1619,1625 ****
  	{258, "eval_input", 0, 3, states_2,
  	 "\000\040\010\000\000\000\000\000\000\000\000\000\040\000\000\206\220\064\001\000"},
! 	{259, "decorator", 0, 6, states_3,
  	 "\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
! 	{260, "decorators", 0, 3, states_4,
  	 "\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
  	{261, "funcdef", 0, 7, states_5,
--- 1618,1624 ----
  	{258, "eval_input", 0, 3, states_2,
  	 "\000\040\010\000\000\000\000\000\000\000\000\000\040\000\000\206\220\064\001\000"},
! 	{259, "decorator", 0, 7, states_3,
  	 "\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
! 	{260, "decorators", 0, 2, states_4,
  	 "\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
  	{261, "funcdef", 0, 7, states_5,



More information about the Python-checkins mailing list