[ 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: 

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
All cause the same problem.
Other builtin functions seem to work correctly.
and eval seems to work correctly from python 
It's just calling eval from C which causes the crash.

Attached is some sample code which demonstrates the 


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

Logged In: YES 

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

Logged In: YES 

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 

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

Logged In: YES 

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: 

More information about the Python-bugs-list mailing list