Too Many if Statements?

Terry Reedy tjreedy at udel.edu
Fri Feb 10 14:59:43 EST 2006


"slogging_away" <hinnc at yahoo.com> wrote in message 
news:1139583025.428875.225500 at g14g2000cwa.googlegroups.com...
> SystemError: com_backpatch: offset too large

This message is generated in the backpatch function in Python/compile.c in 
the source tree.  (See below: sorry, tab indents did not survive cut and 
paste operation.)  As the comment says, and the code shows, it patches in a 
2-byte jump offset.  The error is raised if the offset is not 0 after 
beinging divided by 256 twice (ie, by 65536).  This code is called from any 
function that compiles a construct that potentially jumps: for, while, 
if/elif, and short-circuiting logic expressions.

To me, this message indicates not a bug but a mismatch between code demand 
and interpreter capability.  The solution is to reduce the demand.  In the 
present case, changing

for line in file:
  <extra-long body>

to

def checkline(line):
  <extra-long body>
for line in file:
  checkline(line)

might be sufficient.  If not, break up the <extra-lone body> into multiple 
pieces.

Terry Jan Reedy

static void
com_backpatch(struct compiling *c, int anchor)
{
unsigned char *code = (unsigned char *) PyString_AS_STRING(c->c_code);
int target = c->c_nexti;
int dist;
int prev;
for (;;) {
/* Make the JUMP instruction at anchor point to target */
prev = code[anchor] + (code[anchor+1] << 8);
dist = target - (anchor+2);
code[anchor] = dist & 0xff;
dist >>= 8;
code[anchor+1] = dist;
dist >>= 8;
if (dist) {
com_error(c, PyExc_SystemError,
"com_backpatch: offset too large");
break;
}
if (!prev)
break;
anchor -= prev;
}
}







More information about the Python-list mailing list