[Python-checkins] python/dist/src/Python compile.c,2.241,2.242

nascheme@sourceforge.net nascheme@sourceforge.net
Thu, 25 Apr 2002 18:57:21 -0700


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv24670/Python

Modified Files:
	compile.c 
Log Message:
If Py_OptimizeFlag is false then always evaluate assert conditions, don't
test __debug__ at runtime.  Closes SF patch #548833.


Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.241
retrieving revision 2.242
diff -C2 -d -r2.241 -r2.242
*** compile.c	22 Apr 2002 02:33:27 -0000	2.241
--- compile.c	26 Apr 2002 01:57:19 -0000	2.242
***************
*** 2665,2689 ****
  com_assert_stmt(struct compiling *c, node *n)
  {
! 	int a = 0, b = 0;
  	int i;
  	REQ(n, assert_stmt); /* 'assert' test [',' test] */
! 	/* Generate code like for
  	   
! 	   if __debug__:
! 	      if not <test>:
  	         raise AssertionError [, <message>]
  
  	   where <message> is the second test, if present.
  	*/
- 
- 	if (Py_OptimizeFlag)
- 		return;
- 	com_addop_name(c, LOAD_GLOBAL, "__debug__");
- 	com_push(c, 1);
- 	com_addfwref(c, JUMP_IF_FALSE, &a);
- 	com_addbyte(c, POP_TOP);
- 	com_pop(c, 1);
  	com_node(c, CHILD(n, 1));
! 	com_addfwref(c, JUMP_IF_TRUE, &b);
  	com_addbyte(c, POP_TOP);
  	com_pop(c, 1);
--- 2665,2682 ----
  com_assert_stmt(struct compiling *c, node *n)
  {
! 	int a = 0;
  	int i;
  	REQ(n, assert_stmt); /* 'assert' test [',' test] */
! 	if (Py_OptimizeFlag)
! 		return;
! 	/* Generate code like
  	   
! 	     if not <test>:
  	         raise AssertionError [, <message>]
  
  	   where <message> is the second test, if present.
  	*/
  	com_node(c, CHILD(n, 1));
! 	com_addfwref(c, JUMP_IF_TRUE, &a);
  	com_addbyte(c, POP_TOP);
  	com_pop(c, 1);
***************
*** 2697,2703 ****
  	com_pop(c, i);
  	/* The interpreter does not fall through */
! 	/* All jumps converge here */
  	com_backpatch(c, a);
- 	com_backpatch(c, b);
  	com_addbyte(c, POP_TOP);
  }
--- 2690,2695 ----
  	com_pop(c, i);
  	/* The interpreter does not fall through */
! 	/* Jump ends up here */
  	com_backpatch(c, a);
  	com_addbyte(c, POP_TOP);
  }