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: Problem with recursion in dict (crash with core dump)
Type: Stage:
Components: Interpreter Core Versions: Python 2.4
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: josiahcarlson, mwh, ncoghlan, rhettinger, vys
Priority: normal Keywords:

Created on 2005-05-13 15:43 by vys, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (10)
msg25301 - (view) Author: Vladimir Yu. Stepanov (vys) Date: 2005-05-13 15:43
Please see example code. 
msg25302 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2005-05-13 15:46
Logged In: YES 
user_id=6656

I see no code.  SF can be a pain with this...
msg25303 - (view) Author: Vladimir Yu. Stepanov (vys) Date: 2005-05-13 15:46
Logged In: YES 
user_id=384980

d = {} 
 
class test: 
        def __hash__(self): 
                d[self] = None 
 
d[test()] = None 
msg25304 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2005-05-13 15:55
Logged In: YES 
user_id=6656

I get an infinite recursion runtime error.  What platform
are you on?
msg25305 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2005-05-13 15:55
Logged In: YES 
user_id=80475

I get the expected behavior:

  RuntimeError: maximum recursion depth exceeded
msg25306 - (view) Author: Vladimir Yu. Stepanov (vys) Date: 2005-05-13 16:06
Logged In: YES 
user_id=384980

This is output from `uname -a`: 
FreeBSD fox.renet.ru 5.3-RELEASE FreeBSD 5.3-RELEASE 
#1: Fri Apr 15 10:38:49 MSD 2005     
root@fox.renet.ru:/M/safedir/src/sys/i386/compile/FOX  i386 
 
I get some others with this code: 
 
Python 2.4.1 (#2, Apr 26 2005, 14:16:31) 
[GCC 3.4.2 [FreeBSD] 20040728] on freebsd5 
Type "help", "copyright", "credits" or "license" for more 
information. 
>>> d = {} 
>>> 
>>> class test: 
...         def __hash__(self): 
...                 d[self] = None 
... 
>>> d[test()] = None 
Bus error (core dumped) 
 
 
fox:vys!~ > gdb python python.core 
GNU gdb 6.1.1 [FreeBSD] 
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-marcel-freebsd"...(no 
debugging symbols found)... 
Core was generated by `python'. 
Program terminated with signal 10, Bus error. 
<skip> 
(gdb) where 
#0  0x2828b3b1 in ldexp () from /lib/libc.so.5 
#1  0x2828b618 in malloc () from /lib/libc.so.5 
#2  0x080bdca1 in _PyObject_GC_Malloc () 
#3  0x080bdd4a in _PyObject_GC_New () 
#4  0x0805f556 in PyMethod_New () 
#5  0x0805c1a6 in PyInstance_NewRaw () 
#6  0x0805c66a in PyInstance_New () 
#7  0x0805cca1 in _PyInstance_Lookup () 
#8  0x080703e6 in PyDict_SetItem () 
#9  0x0809bb0e in PyEval_EvalFrame () 
#10 0x0809fc20 in PyEval_EvalCodeEx () 
#11 0x080d4d66 in PyFunction_SetClosure () 
#12 0x0805a38c in PyObject_Call () 
#13 0x0805fbe2 in PyMethod_New () 
#14 0x0805a38c in PyObject_Call () 
#15 0x08099f1b in PyEval_CallObjectWithKeywords () 
#16 0x0805ccb9 in _PyInstance_Lookup () 
#17 0x080703e6 in PyDict_SetItem () 
#18 0x0809bb0e in PyEval_EvalFrame () 
#19 0x0809fc20 in PyEval_EvalCodeEx () 
#20 0x080d4d66 in PyFunction_SetClosure () 
#21 0x0805a38c in PyObject_Call () 
#22 0x0805fbe2 in PyMethod_New () 
<and so on> 
msg25307 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2005-05-18 12:15
Logged In: YES 
user_id=1038590

What does sys.getrecursionlimit() return?

Does the buggy code generate the expected exception if you
use sys.setrecursionlimit() to make the value smaller (e.g.
500)?

FreeBSD has a history of not playing well with CPython's
ability to detect inifinite recursion. . .
msg25308 - (view) Author: Vladimir Yu. Stepanov (vys) Date: 2005-05-18 13:05
Logged In: YES 
user_id=384980

sys.getrecursionlimit() returns 1000. 
I set sys.setrecursionlimit() to 500 and problem was resolved :) 
 
Thank you very much ! 
 
PS. Is it possible to add some checks in Py_SetRecursionLimit  
to reject overflow values ? 
msg25309 - (view) Author: Josiah Carlson (josiahcarlson) * (Python triager) Date: 2005-05-23 04:29
Logged In: YES 
user_id=341410

If your system has sufficient stack space (and/or a
reasonably sane malloc), a recursion limit of 1000 should be
fine.  My windows systems print tracebacks properly for up
to a recursion limit of around 5750 levels (after which I
get MemoryErrors with tracebacks, not cores).

Place a sys.setrecursionlimit() call in your site.py.
msg25310 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2005-05-23 04:46
Logged In: YES 
user_id=80475

FWIW,  the OP's original situation may have tickled a
genuine bug where one of the recursed into routines makes a
malloc request but fails to check for, report, or gracefully
exit from a memory error.

His gdb trace may show the way, but I didn't see the bug.
History
Date User Action Args
2022-04-11 14:56:11adminsetgithub: 41979
2005-05-13 15:43:19vyscreate