473,388 Members | 1,340 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

SystemError: com_backpatch: offset too large

(Sorry for my bad english )

I convert a php code to python. i have 10000 lines where i add and add
and add string.... like var += "xxxxxx"

And line 5139 i have SystemError: com_backpatch: offset too large.
All work except if i exceed line 5139 !

I dont find solution. I have only found this post
http://groups.google.com/groups?hl=f...3DN%26tab%3Dwg

There is a solution?
Do i to give up python and return to php?

Thank for your help
Alban
Jul 18 '05 #1
9 4127
al*************@wanadoo.fr wrote:
(Sorry for my bad english )

I convert a php code to python. i have 10000 lines where i add and add
and add string.... like var += "xxxxxx"

And line 5139 i have SystemError: com_backpatch: offset too large.
All work except if i exceed line 5139 !

I dont find solution. I have only found this post
http://groups.google.com/groups?hl=f...3DN%26tab%3Dwg

There is a solution?
Do i to give up python and return to php?

Thank for your help
Alban


It might help if we had some idea what the code looked like around line
5139, and if we knew the size of the data concerned, for example.

regards
Steve
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119
Jul 18 '05 #2
>
http://groups.google.com/groups?hl=f...3DN%26tab%3Dwg

There is a solution?
Do i to give up python and return to php?


I can't believe that a program with 10000 lines only adding strings can't be
written in a more concise way, which would most probably solve your
problem. So I suggest you post some parts of your code so that we can have
a look at it and suggest a solution.

Apart from that, it seems that if you insist on doing things the way you do
them ringht now, you'll have to stick with php. Sad to admit that, but it
appears to be that way...

--
Regards,

Diez B. Roggisch
Jul 18 '05 #3
al*************@wanadoo.fr <al*************@wanadoo.fr> wrote:
(Sorry for my bad english )

I convert a php code to python. i have 10000 lines where i add and add
and add string.... like var += "xxxxxx"


If 'var' is a string, make it into a list instead, change each
instruction such as the above += into a var.append('xxxxxx'), and when
you're finally done do var=''.join(var) -- by far the best way.
Alex
Jul 18 '05 #4
> It might help if we had some idea what the code looked like around line
5139, and if we knew the size of the data concerned, for example.


Line 5138 : var += "AAA"+"XXXXXX"+"BBB" # <----- OK
Line 5139 : var += "AAA"+"XXXXXX"+"BBB" # <---- !!! --->
com_backpatch: offset too large

If i replace, line 5139, by 'print 'hello python' : --->
com_backpatch: offset too large

len(var)--> 583
Alban
Jul 18 '05 #5
Thank, but same problem (now, i have com_backpatch: offset too large
at line 4567 !)
Alban
Jul 18 '05 #6
>Python supports a prefix opcode to give 32-bit operand values instead of
16-bit values, but the code generator isn't smart enough to use them.

There is a solution 'force' code generator 32-bit operand values instead of
16-bit values ?

Alban
Jul 18 '05 #7
al*************@wanadoo.fr wrote:
Thank, but same problem (now, i have com_backpatch: offset too large
at line 4567 !)


You'll probably get more effective help if you give us more
information. In particular, copy & paste the *entire* traceback that
you're getting. It's probably also a good idea to include at least a
segment of relevant code -- a few lines on either side of the one that's
generating the error, plus any functions that are called there.

Given the message that you posted a link to earlier, it sounds like the
problem *might* simply be that your code branch is too long -- that is,
that you've got too many statements at the same scoping level. To fix
this, find a way to reorganize your code to break it up into smaller
functions.

Where are all of these strings coming from? You can almost certainly
find some way to modify the data source into something that you can
iterate over, in a loop, rather than typing 'var += x + y + z' thousands
of times.

Jeff Shannon
Technician/Programmer
Credit International

Jul 18 '05 #8
al*************@wanadoo.fr wrote:
It might help if we had some idea what the code looked like around line
5139, and if we knew the size of the data concerned, for example.

Line 5138 : var += "AAA"+"XXXXXX"+"BBB" # <----- OK
Line 5139 : var += "AAA"+"XXXXXX"+"BBB" # <---- !!! --->
com_backpatch: offset too large

If i replace, line 5139, by 'print 'hello python' : --->
com_backpatch: offset too large

len(var)--> 583
Alban


Sounds like your module is simply too big. Could you split it up into
several modules instead, calling each in turn?

regards
STeve
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119
Jul 18 '05 #9
I wrote in a long-ago python-list thread:
Python supports a prefix opcode to give 32-bit operand values instead of
16-bit values, but the code generator isn't smart enough to use them.

On Thu, Nov 04, 2004 at 11:21:46PM -0800, al*************@wanadoo.fr wrote: There is a solution 'force' code generator 32-bit operand values instead of
16-bit values ?


The following patch (against CVS head, but it should apply manually to
any recent version of Python) makes all backwards branches use
EXTENDED_ARG unconditionally. This means that the bytecode will be 3
bytes bigger for each such branch, and the bytecode optimizer will not
run (one of its assumptions is that there is no EXTENDED_ARG. It should
detect this automatically, but I made it exit early unconditionally. It
will now run only for functions without backpatched branches, which I
think excludes any function with 'if', 'for', 'and', 'or', chain
comparison, or anything else that makes for a useful function)

A better approach would probably be to add a variable to 'struct
compiling' to denote whether EXTENDED_ARG branches are being used. It
would be initially set to zero, then if the com_backpatch error code is
hit, the compile is restarted with the flag set and all jumps become
EXTENDED_ARG jumps. Now, the price is paid only by overly complex
code objects, but it's still paid by all branches.

The best approach would be to use either of the strategies above, but
then fix the optimizer to notice when an EXTENDED_ARG is zero and remove
it, shifting all affected branches accordingly, to get the best possible
code.

I did not run the test suite after this change, but it does fail to
error out on the two pieces of code in my older message. (it also
compiles this statement with the value increased from ~16k to ~300k:
exec "if len:\n" + "\tNone\n" * 300000 + "else: pass"

}

You may use the code below under the terms of the Python license.

Jeff

Index: Python/compile.c
================================================== =================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.337
diff -u -r2.337 compile.c
--- Python/compile.c 7 Nov 2004 14:04:00 -0000 2.337
+++ Python/compile.c 8 Nov 2004 03:03:11 -0000
@@ -503,6 +503,7 @@
unsigned int *blocks = NULL;
char *name;

+ goto exitUnchanged;
/* Bail out if an exception is set */
if (PyErr_Occurred())
goto exitUnchanged;
@@ -1331,11 +1332,14 @@
/* Compile a forward reference for backpatching */
int here;
int anchor;
- com_addbyte(c, op);
+ com_addbyte(c, EXTENDED_ARG);
here = c->c_nexti;
anchor = *p_anchor;
*p_anchor = here;
- com_addint(c, anchor == 0 ? 0 : here - anchor);
+ anchor = anchor == 0 ? 0 : here - anchor;
+ com_addint(c, anchor >> 16);
+ com_addbyte(c, op);
+ com_addint(c, anchor & 0xffff);
}

static void
@@ -1347,17 +1351,16 @@
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;
+ prev = (code[anchor] << 16)+ (code[anchor+1] << 24)
+ + code[anchor+3] + (code[anchor+4] << 8);
+ dist = target - (anchor+5);
+ code[anchor+3] = dist & 0xff;
dist >>= 8;
- code[anchor+1] = dist;
+ code[anchor+4] = dist & 0xff;
dist >>= 8;
- if (dist) {
- com_error(c, PyExc_SystemError,
- "com_backpatch: offset too large");
- break;
- }
+ code[anchor] = dist & 0xff;
+ dist >>= 8;
+ code[anchor+1] = dist & 0xff;
if (!prev)
break;
anchor -= prev;

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFBjuX8Jd01MZaTXX0RAoRCAJsE0ZJ2tlaQrpQK8RDPh+ rtYL0v+ACgjv14
GfSpknOLPBc0oRQ2+83eqpE=
=a7fa
-----END PGP SIGNATURE-----

Jul 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Gerrit Holl | last post by:
Hi, I found a cool way to trigger a SystemError: >>> exec CodeType(0,0,0,0,"",(),(),(),"","",0,"") XXX lineno: 0, opcode: 0 Traceback (most recent call last): File "<stdin>", line 1, in ?...
1
by: Newgene | last post by:
Hi, group, I am trying to dynamically add a method to class by following this post: ...
3
by: Arto Huusko | last post by:
Hello, I'm wondering about the portability and correctness of the following scenario. I have a generic doubly linked list structure, and it contains generic nodes that look like this: ...
3
by: some one | last post by:
Does anyone know the algorithm or a function out there that will compute the offset location given the following: inputs: 1) x,y coordinate of starting point 2) angle (bearing) 3) distance to...
24
by: funkyj | last post by:
PROBLEM STATEMENT: I want to calculate the byte offset of a field with a struct at compile time without instantiating an instance of the struct at runtime AND I want to do this in an ANSI standard...
2
by: robert | last post by:
From the trace of a 2.3.5 software i got: \'SystemError: C:\\\\sf\\\\python\\\\dist23\\\\src\\\\Objects\\\\cellobject.c:22: bad argument to internal function\\n\'] from the middle of...
6
by: usenet1 | last post by:
I'm a newbie with hopefully an easy question. I'm trying to write some "C" code that will run a python script that can in turn call some "C" functions. However I'm having a problem getting...
11
by: zefciu | last post by:
I am trying to embed a c function in my python script for a first time. When I try to call it I get an error SystemError: new style getargs format but argument is not a tuple Guido said on...
0
by: rkmr.em | last post by:
hi, i get this error while using web.py and cheetah. how to fix this? happens everytime regularly thanks Traceback (most recent call last): File "/home/mark/work/pop/web/webapi.py", line...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.