[New-bugs-announce] [issue14331] Python/import.c uses a lot of stack space due to MAXPATHLEN
Gregory P. Smith
report at bugs.python.org
Fri Mar 16 01:42:29 CET 2012
New submission from Gregory P. Smith <greg at krypto.org>:
Python/import.c in 2.7 and 3.2 consume a lot of stack space when importing modules. In stack constrained environments (think: 64k stack) this can cause a crash when you have a large chain of imports.
The bulk of this likely comes from places where a char buf[MAXPATHLEN+1] or similar is declared on the stack in the call chain. MAXPATHLEN is commonly defined to be in the 256..1024 range depending on the OS.
Changing the code to not put the large buffer on the stack but to malloc and free it instead is a pretty straightforward re-factor.
import is being significantly reworked in 3.3 so I won't consider this issue there until after that settles as it may no longer apply.
nosy: brett.cannon, gregory.p.smith, ncoghlan, twouters
title: Python/import.c uses a lot of stack space due to MAXPATHLEN
versions: Python 2.7, Python 3.2
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce