classification
Title: Evaluating func_code causing core dump
Type: Stage:
Components: Interpreter Core Versions: Python 2.2
process
Status: closed Resolution: later
Dependencies: Superseder:
Assigned To: jhylton Nosy List: gvanrossum, jhogg, jhylton, skip.montanaro, tim.peters
Priority: low Keywords:

Created on 2001-07-23 17:48 by jhogg, last changed 2002-07-11 18:11 by jhylton. This issue is now closed.

Messages (7)
msg5559 - (view) Author: Jonathan Hogg (jhogg) Date: 2001-07-23 17:48
Python 2.2a1 (#1, Jul 19 2001, 18:18:51)
[GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-81)] on 
linux2

The intepreter dies hard if you directly evaluate the 
func_code of a function that has a closure. E.g.:

-----
def func1():
    return lambda: 4 + y

f = func1()
print "Ugly test 1:", eval( f.func_code, {'y': 38} )


def func2(x):
    return lambda: x + y

f = func2(4)
print "Ugly test 2:", eval( f.func_code, {'y': 38} )
-----

The second eval will cause a core dump on UNIX. The 
offending code is in PyEval_EvalCodeEx() of ceval.c 
line 2466. This loop attempts to match free vars 
against the closure, but the closure is NULL if the 
function is called with eval.

I know this is very broken usage of the interpreter, 
but it should die more cleanly than a core dump ;-)
msg5560 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2001-07-24 22:35
Logged In: YES 
user_id=31435

Assigned to Jeremy in the hopes this will speed his return 
to us <wink>.
msg5561 - (view) Author: Jeremy Hylton (jhylton) (Python triager) Date: 2001-07-30 21:51
Logged In: YES 
user_id=31392

Fixed in rev 2.219 of bltinmodule.c
msg5562 - (view) Author: Jeremy Hylton (jhylton) (Python triager) Date: 2001-07-30 21:53
Logged In: YES 
user_id=31392

It might be useful to extend eval() with a means to specify
bindings from free variables.  It's not at all clear how to
do this under the current implementation, which refers to
free variables using integer indexes assigned at compile
time.
msg5563 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2001-12-12 05:29
Logged In: YES 
user_id=6380

Jeremy, since you claimed this to be fixed, is there a
reason to keep this bug report open? If you want a feature,
please open a (new, please!) feature request.
msg5564 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2002-03-10 01:44
Logged In: YES 
user_id=44345

just a reminder that this appears to be fixed -skip
msg5565 - (view) Author: Jeremy Hylton (jhylton) (Python triager) Date: 2002-07-11 18:11
Logged In: YES 
user_id=31392

Added feature request to pep 42.
History
Date User Action Args
2001-07-23 17:48:19jhoggcreate