This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Calling builtin function \'eval\' from C causes seg fault.
Type: Stage:
Components: None Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: georg.brandl, georg.brandl, karadoc, nnorwitz
Priority: normal Keywords:

Created on 2004-01-01 03:41 by karadoc, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
bug.c karadoc, 2004-01-01 03:41 sample code
eval.patch nnorwitz, 2004-01-01 21:52
Messages (4)
msg19494 - (view) Author: Zac Evans (karadoc) Date: 2004-01-01 03:41
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.
msg19495 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2004-01-01 21:52
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.
msg19496 - (view) Author: Zac Evans (karadoc) Date: 2004-01-02 03:04
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.
msg19497 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-09-15 10:47
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.
History
Date User Action Args
2022-04-11 14:56:01adminsetgithub: 39744
2004-01-01 03:41:15karadoccreate