function causing core dump

Xaver Hinterhuber xaver_hinterhuber at web.de
Tue May 11 02:26:48 EDT 2004


Hi Robert,

I don't show you codeString because it is a real string variable.
And yes, its uncompiled.
The user in my program enters a python program in this variable without a
def statement
and then the code is executed and the result returned.

Maybe you can help me to add a "def f():" to the codeString, take care of
the
indentation and then execute the code?

I really don't know how to handle the indentation thing. A "def
f():\n"+codeString is easy, but this doesn't solve
this issue.

Greets
Xaver

"Robert Brewer" <fumanchu at amor.org> schrieb im Newsbeitrag
news:mailman.398.1084203482.25742.python-list at python.org...
Xaver Hinterhuber wrote:
> I build a function with the following code segment:
>
>     codeObject = new.code(
>       0, # argcount
>       0, # nlocals
>       0, # stacksize
>       0, # flags
>       codeString, # code
>       (), # consts
>       (), # names
>       (), # varnames
>       'content', # filename
>       'content', # name
>       3, # first line number
>       codeString # lnotab
>       )
>     f = new.function(codeObject, dict, 'f')
>     f()
>
> Everything runs fine, until the function is called with f().
> When python tries to execute f(), the core dump happens.
> I don't have any clue why python core dumps.
> The codeString is nothing complex, its a one-liner.
> Could you plz give me some tips what I have to do?

As usual, the tip is: include the one piece of information you left out
of your post. What is the value of codeString?

My first guess is that codeString is something like "return None", or
some other string of uncompiled Python code, in which case, you should
use eval() instead of new.code and new.function. Those two are used for
creating code objects and functions from a _compiled_ codestring, like
'\x88\x00\x00Sd\x00\x00S'. In addition, nearly all of the args passed to
new.code are *very* important, and cannot simply be set to 0.

If you want more info, show us the codeString! :)


Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org





More information about the Python-list mailing list