Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > RE: function causing core dump

Reply
Thread Tools

RE: function causing core dump

 
 
Robert Brewer
Guest
Posts: n/a
 
      05-10-2004
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
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
 
 
 
Xaver Hinterhuber
Guest
Posts: n/a
 
      05-11-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" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed)...
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
(E-Mail Removed)


 
Reply With Quote
 
 
 
 
Peter Otten
Guest
Posts: n/a
 
      05-11-2004
Xaver Hinterhuber wrote:

> I don't show you codeString because it is a real string variable.


You could show an _example_ codeString, though. That would have greatly
simplified the diagnosis.

> 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.


Maybe you can get away with a simple expression:

>>> from math import *
>>> codeString = "sin(0.5) + 23"
>>> eval(codeString)

23.479425538604204

If not, try

>>> codeString2 = "a=0.5\nb=23\nreturn sin(a) + b"
>>> funcString = "def f():\n " + "\n ".join(codeString2.split("\n"))
>>> funcString

'def f():\n a=0.5\n b=23\n return sin(a) + b'
>>> exec funcString
>>> f()

23.479425538604204
>>>


Peter

 
Reply With Quote
 
Xaver Hinterhuber
Guest
Posts: n/a
 
      05-11-2004
Hi Peter,

"Peter Otten" <(E-Mail Removed)> schrieb im Newsbeitrag
news:c7q1vs$oph$04$(E-Mail Removed)-online.com...
> Xaver Hinterhuber wrote:
>
> > I don't show you codeString because it is a real string variable.

>
> You could show an _example_ codeString, though. That would have greatly
> simplified the diagnosis.


For clarification: The codeString contains up to 500 lines of code. It's a
complete program to render a pdf page with
reportlab. It's really a huge monster. But in future I'll try give an
example with all variables declared.
>
> > 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.

>
> Maybe you can get away with a simple expression:
>
> >>> from math import *
> >>> codeString = "sin(0.5) + 23"
> >>> eval(codeString)

> 23.479425538604204
>
> If not, try
>
> >>> codeString2 = "a=0.5\nb=23\nreturn sin(a) + b"
> >>> funcString = "def f():\n " + "\n ".join(codeString2.split("\n"))
> >>> funcString

> 'def f():\n a=0.5\n b=23\n return sin(a) + b'
> >>> exec funcString
> >>> f()

> 23.479425538604204
> >>>


Thats a good idea. I'll try it as soon as possible.

Thanx


 
Reply With Quote
 
Xaver Hinterhuber
Guest
Posts: n/a
 
      05-17-2004
Hi Peter,

I now have tried it.
My problem is now, that I get unicode encoding errors.
I am working on a german windoze machine.
Could you plz give me a tip what encoding I should use (iso8859-1 and utf-8
dont't work)?

--
with kind regards
Xaver Hinterhuber

"Xaver Hinterhuber" <(E-Mail Removed)> schrieb im Newsbeitrag
news:c7qger$mml$(E-Mail Removed)...
> Hi Peter,
>
> "Peter Otten" <(E-Mail Removed)> schrieb im Newsbeitrag
> news:c7q1vs$oph$04$(E-Mail Removed)-online.com...
> > Xaver Hinterhuber wrote:
> >
> > > I don't show you codeString because it is a real string variable.

> >
> > You could show an _example_ codeString, though. That would have greatly
> > simplified the diagnosis.

>
> For clarification: The codeString contains up to 500 lines of code. It's a
> complete program to render a pdf page with
> reportlab. It's really a huge monster. But in future I'll try give an
> example with all variables declared.
> >
> > > 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.

> >
> > Maybe you can get away with a simple expression:
> >
> > >>> from math import *
> > >>> codeString = "sin(0.5) + 23"
> > >>> eval(codeString)

> > 23.479425538604204
> >
> > If not, try
> >
> > >>> codeString2 = "a=0.5\nb=23\nreturn sin(a) + b"
> > >>> funcString = "def f():\n " + "\n

".join(codeString2.split("\n"))
> > >>> funcString

> > 'def f():\n a=0.5\n b=23\n return sin(a) + b'
> > >>> exec funcString
> > >>> f()

> > 23.479425538604204
> > >>>

>
> Thats a good idea. I'll try it as soon as possible.
>
> Thanx
>
>



 
Reply With Quote
 
Peter Otten
Guest
Posts: n/a
 
      05-17-2004
Xaver Hinterhuber wrote:

> My problem is now, that I get unicode encoding errors.
> I am working on a german windoze machine.
> Could you plz give me a tip what encoding I should use (iso8859-1 and
> utf-8 dont't work)?


Other popular encodings are cp1252 and ISO-8859-15.

Since your new problem is totally unrelated to code objects and core dumps,
you should start a new thread. Remember to include as many hints that could
help solve your problem as possible. Providing a piece of code and a
traceback is always a good idea, since you could be misusing the api rather
than have picked the wrong encoding. Having this newsgroup suggest random
encodings is certainly not the way to go.

Good luck,
Peter


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dump complete java VM state as core dump (not via OS) possible? halfdog Java 12 02-21-2013 06:14 AM
Core Solo & Core Duo are not Core microarchitecture; 65nm Pentium M chips bigal Hardware 0 03-22-2006 11:24 AM
Read Core Dump file ns Cisco 8 05-26-2005 03:07 AM
Sig handler causing core dump Mark Brackett C Programming 3 11-04-2004 01:51 PM
function causing core dump Xaver Hinterhuber Python 4 05-10-2004 08:06 PM



Advertisments