COPY-TREE fails with stack overflow on long lists
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
COPY-TREE fails with a stack overflow when its argument is a long list. (I didn't try to find out what is the minimum length to trigger the error.)
COPY-LIST succeeds on a list of the same length.
Thank you for your attention to this. I searched the bug database but didn't find a similar report. I don't see anything about COPY-TREE in the change logs.
-------
* (defvar x nil)
X
* (dotimes (i 65536) (push 1 x))
NIL
* (copy-tree x)
INFO: Control stack guard page unprotected
Control stack guard page temporarily disabled: proceed with caution
debugger invoked on a SB-KERNEL:
Control stack exhausted (no more space for function call frames).
This is probably due to heavily nested or infinitely recursive function
calls, or a tail call that SBCL cannot or has not optimized away.
PROCEED WITH CAUTION.
Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.
restarts (invokable by number or by possibly-
0: [ABORT] Exit debugger, returning to top level.
(SB-KERNEL:
0]
-------
$ sbcl --version
SBCL 1.0.49
* *features*
(:ANSI-CL :COMMON-LISP :SBCL :SB-DOC :SB-TEST :SB-LDB :SB-PACKAGE-LOCKS
:SB-UNICODE :SB-EVAL :SB-SOURCE-
:LINUX :SB-THREAD :LARGEFILE :GENCGC :STACK-
:C-STACK-
:RAW-INSTANCE-
:STACK-
:CYCLE-COUNTER :INLINE-CONSTANTS :MEMORY-
:OS-PROVIDES-
:OS-PROVIDES-
$ uname -a
Linux robert-laptop 2.6.24-16-generic #1 SMP Thu Apr 10 13:23:42 UTC 2008 i686 GNU/Linux
commit 4b25bb8e20bf3c1 419a11b7d4cfefa 23e4f3279b
Author: Stas Boukarev <email address hidden>
Date: Mon May 14 05:12:45 2012 +0400
Optimize copy-tree.
copy-tree used to always call itself, even on linear lists, which
caused stack exhaustion on long lists. Make it copy linear lists
linearly, and recur only when necessary. This also makes it somewhat
faster.