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: 'nonlocal x' at top level crashes interpreter
Type: Stage:
Components: Interpreter Core Versions: Python 3.0
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ncoghlan Nosy List: georg.brandl, johnreese, ncoghlan
Priority: high Keywords:

Created on 2007-04-22 19:20 by johnreese, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg31861 - (view) Author: John Reese (johnreese) Date: 2007-04-22 19:20
A nonlocal declaration at the interpreter top level causes a bus error.  This happens in the p3yk branch at head (r54922).  Reporter is using MacOS 10.4.9 on Intel.  Reporter is perfectly aware that nonlocal doesn't do anything useful at the top level, but feels it should not crash the interpreter.


% gdb python3.0                                          
GNU gdb 6.3.50-20050815 (Apple version gdb-563) (Wed Jul 19 05:10:58 GMT 2006)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin"...Reading symbols for shared libraries .. done

(gdb) run
Starting program: /Users/jtr/bin/python3.0 
Reading symbols for shared libraries . done
Python 3.0x (p3yk:54922, Apr 22 2007, 12:15:19) 
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> nonlocal x

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00000004
PySet_Contains (anyset=0x0, key=0x532640) at Objects/setobject.c:2129
2129            if (!PyAnySet_Check(anyset)) {
(gdb) The program is running.  Exit anyway? (y or n) y
msg31862 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-04-22 22:23
Nick, that crash is in the symtable code you refactored with the setcomp patch.
msg31863 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2007-04-23 10:18
Fixed in rev 54925 to raise SyntaxError instead of crashing.

The bug appears to have been present in the original nonlocal code - both the original code and the refactored code checked if a nonlocal variable was in the set of bound names without first checking that the relevant pointer was non-NULL.
msg31864 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2007-04-23 11:07
Fixed in rev 54925 to raise SyntaxError instead of crashing.

The bug appears to have been present in the original nonlocal code - both the original code and the refactored code checked if a nonlocal variable was in the set of bound names without first checking that the relevant pointer was non-NULL.
History
Date User Action Args
2022-04-11 14:56:23adminsetgithub: 44882
2008-01-06 22:29:46adminsetkeywords: - py3k
versions: + Python 3.0
2007-04-22 19:20:48johnreesecreate