classification
Title: new.code and new.function crashes Python iterpretter
Type: crash Stage:
Components: Documentation Versions: Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, jeffdharper, loewis, terry.reedy
Priority: normal Keywords:

Created on 2012-07-04 17:29 by jeffdharper, last changed 2012-07-07 02:29 by terry.reedy.

Files
File name Uploaded Description Edit
bug3.py jeffdharper, 2012-07-04 17:29
tem.py terry.reedy, 2012-07-07 02:29 Crashes 3.3.0b0 pythonw run from IDLE
Messages (5)
msg164652 - (view) Author: Jeffrey Harper (jeffdharper) Date: 2012-07-04 17:29
I've attached a script that crashes the Python interpreter.  

I can get the crash to occur under Windows Vista with this version of Python:

C:\tmp\remote>c:\Python27\python.exe
Python 2.7.1 Stackless 3.1b3 060516 (release27-maint, Jan  1 2011, 13:04:37) [MSC v.1500 32 bit (Intel)] on win32

Also, I got it to segfault under Ubuntu Linux:

jharper@ubuntu:~$ uname -a
Linux ubuntu 2.6.35-27-generic #48-Ubuntu SMP Tue Feb 22 20:25:29 UTC 2011 i686 GNU/Linux
jharper@ubuntu:~$ python
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) 
[GCC 4.4.5] on linux2

Note, when I commented out the line, "pprint(code_args)", the script generated a SystemError exception instead of crashing.
msg164653 - (view) Author: Jeffrey Harper (jeffdharper) Date: 2012-07-04 17:34
The marshal loads and dumps don't seem to be necessary to reproduce the crash.  On both the Windows Vista and Ubuntu Linux systems, the crash still occurred when I replaced:

mcopy_code = loads(dumps(code))

with:

mcopy_code = code #loads(dumps(code))
msg164654 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2012-07-04 17:46
You need to pass co_freevars and co_cellvars as well for your example to work. It shouldn't crash, but I don't consider this particular crash as a bug, as it is a known limitation that new.code doesn't perform all consistency checks that are necessary to guarantee that the function execution doesn't crash the interpreter.

It certainly can't be fixed in 2.6.
msg164663 - (view) Author: Jeffrey Harper (jeffdharper) Date: 2012-07-04 22:20
Martin,

Thanks for your response.  I didn't know it was possible to pass freevars and cellvars to new.code.  I think the documentation needs to be updated.  The documentation for 2.7.3 located at http://docs.python.org/library/new.html?highlight=new#new.code is as follows:

new.code(argcount, nlocals, stacksize, flags, codestring, constants, names, varnames, filename, name, firstlineno, lnotab)

After I got your reply to this bug report I did help(new.code) and I see that it includes freevars and cellvars as optional arguments.
msg164775 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2012-07-07 02:29
In Py3, new.code and new.function become types.CodeType and types.FunctionType. The 'documentation' of their signatures is only available with help(types.xxx). So the library doc issue is 2.7 only.

Running with IDLE, 3.3b0, Win7, the converted example does crash after 5 seconds or so even with the missing arg and the pprint gone. The crash is in the new_fun(5) call. I might have gotten something wrong. Or maybe the the help is wrong.
History
Date User Action Args
2012-07-07 02:29:12terry.reedysetfiles: + tem.py
nosy: + terry.reedy
messages: + msg164775

2012-07-04 22:20:43jeffdharpersetnosy: + docs@python
messages: + msg164663

assignee: docs@python
components: + Documentation, - Library (Lib)
2012-07-04 17:46:22loewissetnosy: + loewis

messages: + msg164654
versions: - Python 2.6
2012-07-04 17:34:12jeffdharpersetmessages: + msg164653
2012-07-04 17:29:13jeffdharpercreate