[ python-Bugs-868706 ] Calling builtin function \'eval\' from C causes seg fault.

SourceForge.net noreply at sourceforge.net
Mon Feb 20 14:13:24 CET 2006


Bugs item #868706, was opened at 2004-01-01 03:41
Message generated for change (Settings changed) made by gbrandl
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=868706&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Closed
Resolution: Fixed
Priority: 5
Submitted By: Zac Evans (karadoc)
>Assigned to: Georg Brandl (gbrandl)
>Summary: Calling builtin function \'eval\' from C causes seg fault.

Initial Comment:
Using C to get the eval function from builtins then call it 
causes a Seg-Fault.
I've tried calling it using
PyObject_CallObject, "_CallFunction, "_CallFunctionObjArg
s.
All cause the same problem.
Other builtin functions seem to work correctly.
and eval seems to work correctly from python 
(obviously).
It's just calling eval from C which causes the crash.

Attached is some sample code which demonstrates the 
problem.

----------------------------------------------------------------------

Comment By: Georg Brandl (birkenfeld)
Date: 2005-09-15 10:47

Message:
Logged In: YES 
user_id=1188172

I fixed this; eval() now raises a TypeError when called from
C without globals/locals.

Committed in Python/bltinmodule.c r2.325, r2.318.2.3.

----------------------------------------------------------------------

Comment By: Zac Evans (karadoc)
Date: 2004-01-02 03:04

Message:
Logged In: YES 
user_id=117625

In my opinion, the 'bug' isn't really a big problem. If it is nicer 
for the internals of Python if the bug isn't fixed, than that 
would be fine. Although, it would be a good thing to 
document somewhere. Ideally, the call should raise an 
expection saying what the problem is. That's always nicer 
than a seg-fault.

Also, on an almost unrelated note, why are
PyEval_EvalCode() and a whole lot of other PyEval_* 
functions missing from the Python/C API index in the docs 
(http://www.python.org/doc/current/api/genindex.html)?

And that's about all I have to say about that.
Thank you for you time and quick reponse.

----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2004-01-01 21:52

Message:
Logged In: YES 
user_id=33168

The attached patch fixes the problem, but I'm not sure this
should be applied.  Partially because I'm not sure it's the
best solution.  I'm also not sure if your use should be
considered correct.  I'm not sure if this is documented. 
Perhaps that should be changed?

I understand your complaint, however, you can fix the
problem my passing a dictionary for globals.  You can also
call PyEval_EvalCode or PyEval_EvalCodeEx.  But in both of
those cases you will need to supply globals.

I believe the reason for the segfault is that globals is
NULL since there is no frame.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=868706&group_id=5470


More information about the Python-bugs-list mailing list