[Python-checkins] python/dist/src/Python newcompile.c,1.1.2.48,1.1.2.49

jhylton@users.sourceforge.net jhylton@users.sourceforge.net
Mon, 31 Mar 2003 13:44:35 -0800


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

Modified Files:
      Tag: ast-branch
	newcompile.c 
Log Message:
A few small fixes.

The blockoff must always be allocated based on the number of allocated
blocks, not the number of reachable blocks.  The old code used the
number of reachable blocks which failed when there were unreachable
blocks.  (Also free blockoff when we're done with it.)

Move compiler_unit_check() above the call to compiler_unit_free(),
then call check from free.

Initialize u_tmpname.



Index: newcompile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/newcompile.c,v
retrieving revision 1.1.2.48
retrieving revision 1.1.2.49
diff -C2 -d -r1.1.2.48 -r1.1.2.49
*** newcompile.c	30 Mar 2003 23:02:32 -0000	1.1.2.48
--- newcompile.c	31 Mar 2003 21:44:31 -0000	1.1.2.49
***************
*** 283,286 ****
--- 283,287 ----
  	if (!u->u_blocks)
  		return 0;
+ 	u->u_tmpname = 0;
  	u->u_nfblocks = 0;
  	memset(u->u_blocks, 0, sizeof(struct basicblock *) * DEFAULT_BLOCKS);
***************
*** 312,319 ****
--- 313,338 ----
  
  static void
+ compiler_unit_check(struct compiler_unit *u)
+ {
+ 	int i;
+ 	assert(u->u_curblock < u->u_nblocks);
+ 	assert(u->u_nblocks <= u->u_nalloc);
+ 	for (i = 0; i < u->u_nblocks; i++) {
+ 		struct basicblock *block = u->u_blocks[i];
+ 		assert(block);
+ 		assert(block != (void *)0xcbcbcbcb);
+ 		assert(block != (void *)0xfbfbfbfb);
+ 		assert(block->b_ialloc > 0);
+ 		assert(block->b_iused >= 0 
+ 		       && block->b_ialloc >= block->b_iused);
+ 	}
+ }
+ 
+ static void
  compiler_unit_free(struct compiler_unit *u)
  {
  	int i;
  
+ 	compiler_unit_check(u);
  	for (i = 0; i < u->u_nblocks; i++)
  		PyObject_Free((void *)u->u_blocks[i]);
***************
*** 327,343 ****
  }
  
- static void
- compiler_unit_check(struct compiler_unit *u)
- {
-     int i;
-     assert(u->u_curblock < u->u_nblocks);
-     assert(u->u_nblocks <= u->u_nalloc);
-     for (i = 0; i < u->u_nblocks; i++) {
- 	assert(u->u_blocks[i]);
- 	assert(u->u_blocks[i] != (void *)0xcbcbcbcb);
- 	assert(u->u_blocks[i] != (void *)0xfbfbfbfb);
-     }
- }
- 
  static int
  compiler_exit_scope(struct compiler *c)
--- 346,349 ----
***************
*** 385,389 ****
  		u->u_nalloc += u->u_nalloc;
  	}
- 	compiler_unit_check(u);
  	b = (struct basicblock *)PyObject_Malloc(sizeof(struct basicblock));
  	if (b == NULL)
--- 391,394 ----
***************
*** 913,917 ****
  	case LOOP:
  		ADDOP_JABS(c, JUMP_ABSOLUTE, c->u->u_fblock[i].fb_block);
- 		NEW_BLOCK(c);
  		break;
  	case EXCEPT:
--- 918,921 ----
***************
*** 922,926 ****
  			return compiler_error(c, "'continue' outside loop");
  		ADDOP_I(c, CONTINUE_LOOP, c->u->u_fblock[i].fb_block);
- 		NEW_BLOCK(c);
  		break;
  	case FINALLY_END:
--- 926,929 ----
***************
*** 929,932 ****
--- 932,937 ----
  	}
  
+ 	/* If the continue wasn't an error, it will always end a block. */
+ 	NEW_BLOCK(c);
  	return 1;
  }
***************
*** 1126,1131 ****
  		identifier store_name;
  
! 		if (i == 0 && 
! 		    *PyString_AS_STRING(alias->name) == '*') {
  			assert(n == 1);
  			ADDOP(c, IMPORT_STAR);
--- 1131,1135 ----
  		identifier store_name;
  
! 		if (i == 0 && *PyString_AS_STRING(alias->name) == '*') {
  			assert(n == 1);
  			ADDOP(c, IMPORT_STAR);
***************
*** 2110,2114 ****
  	/* Compute the size of each block and fixup jump args.
  	   Replace block index with position in bytecode. */
! 	blockoff = malloc(sizeof(int) * a->a_nblocks);
  	if (!blockoff)
  		return 0;
--- 2114,2118 ----
  	/* Compute the size of each block and fixup jump args.
  	   Replace block index with position in bytecode. */
! 	blockoff = malloc(sizeof(int) * c->u->u_nblocks);
  	if (!blockoff)
  		return 0;
***************
*** 2116,2119 ****
--- 2120,2124 ----
  	   c_blocks[] indices.
  	*/
+ 	assert(a->a_nblocks <= c->u->u_nblocks);
  	for (i = a->a_nblocks - 1; i >= 0; i--) {
  		int block = a->a_postorder[i];
***************
*** 2140,2143 ****
--- 2145,2149 ----
  		}
  	}
+ 	free(blockoff);
  
  	return 1;