Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2008-07-13
09:20 • Closed ticket [1066755fff]: Surprisingly low recursion limit on Windows plus... artifact: d2b9254235 user: sf-robot
2008-06-28
21:23 • Pending ticket [1066755fff]. artifact: d34c6967f6 user: msofer
2007-06-18
23:23 • Ticket [1066755fff]: 4 changes artifact: 53abaf2846 user: dgp
2007-06-16
21:01 • Ticket [1066755fff]: 4 changes artifact: a02e96503f user: dkf
2007-06-15
00:13 • Ticket [1066755fff]: 7 changes artifact: 345dbb6342 user: hobbs
2007-06-14
16:27 • Ticket [1066755fff]: 4 changes artifact: 28d4fe614b user: dkf
09:46 • Ticket [1066755fff]: 5 changes artifact: 8146c64549 user: msofer
05:50 • Ticket [1066755fff]: 4 changes artifact: f7821f1bf6 user: msofer
03:44 • Ticket [1066755fff]: 4 changes artifact: 6337f73e0d user: dgp
03:39 • Ticket [1066755fff]: 6 changes artifact: 6a586b4d29 user: dgp
2007-06-13
02:43 • Ticket [1066755fff]: 7 changes artifact: 5616930ecd user: hobbs
2005-10-05
13:36 • Ticket [1066755fff]: 4 changes artifact: c2d7ff2e34 user: hobbs
2004-11-27
03:51 • Ticket [1066755fff]: 4 changes artifact: 5b8dba3b31 user: davygrvy
2004-11-26
23:37 • Ticket [1066755fff]: 4 changes artifact: ada54d2b70 user: stevebold
17:18 • Ticket [1066755fff]: 4 changes artifact: 1dcfe38ceb user: stevebold
06:22 • Ticket [1066755fff]: 4 changes artifact: 28a422268f user: davygrvy
2004-11-25
21:14 • Ticket [1066755fff]: 5 changes artifact: de1f04abea user: davygrvy
16:56 • Ticket [1066755fff]: 4 changes artifact: fe1cb1ff80 user: stevebold
06:23 • Ticket [1066755fff]: 4 changes artifact: d85db5dc17 user: davygrvy
03:03 • Ticket [1066755fff]: 4 changes artifact: f7d66044c0 user: davygrvy
2004-11-15
16:20 • New ticket [1066755fff]. artifact: c33555aeb2 user: stevebold

Surprisingly low recursion limit on Windows

Closed1066755fffffffffffffffffffffffffffffffffCreated 22 years agoUpdated 18 years ago
Descriptionplain2004-11-15 16:20:57
TIP 87 indicates that the default recursion depth for Tcl 
is 1000
and that this can be changed by scripts. However, on 
Windows XP this
does not seem to be the case.

Consider this script:

set level 0
proc a {} {
   set ::level [info level]
   a
}
a

With the Active Tcl build of 8.5a1, it fails with $level set 
to 375.

ActiveTcl 8.4.6 failed with $level set to 395.

My own build of 8.4.3 failed with $level set to 902.

Setting calling 'interp recursionlimit {} 2000' makes no 
difference
to these numbers.

On Solaris, this problem is not seen.
davygrvyplain2004-11-25 03:03:14
Logged In: YES 
user_id=7549

are we out of stack space or is it the soft limit?
davygrvyplain2004-11-25 06:23:42
Logged In: YES 
user_id=7549

This must be an actual stack space issue for you as I can go
to 999 for both 8.4 and 8.5 shells.  But I'm running on Win2K.
steveboldplain2004-11-25 16:56:56
Logged In: YES 
user_id=810219

Tried ActiveTcl 8.4.6 on a Windows 2000 box and still saw a 
limit of 395.

Used 'dumpbin -headers tclsh84.exe' to look at the stack 
size. On by own build
of 8.4.3 I see:

          231860 size of stack reserve
            1000 size of stack commit

On ActiveTcl 8.4.6 I see:

          100000 size of stack reserve
            1000 size of stack commit

With ActiveTcl8.5 I see:

          100000 size of stack reserve
            1000 size of stack commit

win/makefile.vc seems to be constant in specifying 2.3MB of 
stack space for 8.4
and 8.5. Dumpbin doesn't document the unit of stack size, it 
appears to be
in units of 10 bytes.

So it looks like:
a. ActiveTcl is built with the stack stack size set to the 
Windows default of 1MB,
   not that in makefile.vc
b. even 2.3MB is a little too small to achieve a stack depth of 
1000
davygrvyplain2004-11-25 21:14:28
Logged In: YES 
user_id=7549

editbin /stack:2300000,4096 tclsh85.exe

That's how to change it after the fact.  The TEA makefile
should have this modified to add the '-stack:2300000' switch
to the linker commandline.
davygrvyplain2004-11-26 06:22:41
Logged In: YES 
user_id=7549

units for dumpbin are in hex
2300000 == 0x231860

I think that it's odd that you can only go to 902, as I can
hit 1795 before the stack runs out.  I wonder if this is an
XP thing?
steveboldplain2004-11-26 17:18:36
Logged In: YES 
user_id=810219

Ok, I tried again today (on XP) and with my 8.4.3 build and,
with 'interp recursionlimit {} 2000' I'm now able to get
up to 1987.

I suppose something must have changed in the last couple of 
weeks
but I'm not sure what, we haven't changed or rebuilt the 
interpreter.

I did notice that running the script twice in the same tclsh
session gives a slightly higher limit the second time around
(1992 instead of 1987). I wonder if their are other factors
affecting the permitted size of the stack?

I'll try again in a few days and see if the numbers have shifted
again.
steveboldplain2004-11-26 23:37:39
Logged In: YES 
user_id=810219

Also found that, at least in 8.4.3, building using makefile.vc,
wish is built with a 1MB stack and only tclsh gets the 2.3MB 
stack. Has this been rationalised in 8.5, if not should it be?
davygrvyplain2004-11-27 03:51:24
Logged In: YES 
user_id=7549

yup, wish needs more stack.  I just tested 8.5, and I
couldn't get past 775.  Added -stack:2300000 to the link and
brought it up to 1795.

I'll push this out for Tk, but the TEA makefiles need this
added, too.
hobbsplain2005-10-05 13:36:47
Logged In: YES 
user_id=72656

Why does TEA need this?  It seems that this should just be
needed by the Tcl core makefiles and nowhere else.
hobbsplain2007-06-13 02:43:17
Logged In: YES 
user_id=72656
Originator: NO

Improvements have been made to stack handling that has 8.5a7 seeing 834 levels possible.  Don believes that more aggressive use of TclStackAlloc in the core will get us to the "default" 1000 without needing -stack.
dgpplain2007-06-14 03:39:18
Logged In: YES 
user_id=80530
Originator: NO


There are more places to use TclStackAlloc
and the newer TclStackRealloc, but it doesn't
appear those places will impact the particular
demo script here, which is focused specifically
on a recursive proc.

The call stack to examine for stack reduction
in the HEAD is:

TclExecuteByteCode (doInvocation)
TclEvalObjvKnownCommand
TclObjInterpProc
ObjInterpProcEx
TclObjInterpProcCore
TclCompEvalObj
TclExecuteByteCode
dgpplain2007-06-14 03:44:26
Logged In: YES 
user_id=80530
Originator: NO


A simple thing to try would be
to inline TclObjInterpProcCore
within what appears to be its
only caller, ObjInterpProcEx

(which raises the questions
why it is not a file static
routine, and why it's in
the internal stubs table?)
msoferplain2007-06-14 05:50:07
Logged In: YES 
user_id=148712
Originator: NO

As a service to OO extensions: tclOO calls into TclObjInterpProcCore, xotcl and itcl both call into TclObjInterpProc. I guess it could be feasible to modify things so that the core does not call TclObjInterpProc, thus removing one item from the stack. At least gcc optimises that tail call away: TclObjInterpProc does not appear in a stack trace in a standard -O2 (no -g) build.

Otherwise, maybe this is the signal that the time has come to bite the bullet and bring NRE up to date and into HEAD?
msoferplain2007-06-14 09:46:10
Logged In: YES 
user_id=148712
Originator: NO

Please test on HEAD - the call to TclCompEvalObj is now gone from that stack trace.
dkfplain2007-06-14 16:27:30
Logged In: YES 
user_id=79902
Originator: NO

TclObjInterpProcCore is an entry point I added so that TclOO's methods don't need to reach too deeply into the core's guts. The alternative to having it is that a *lot* more details get leaked to anyone who needs to build non-standard procedure-like things.
hobbsplain2007-06-15 00:13:21
Logged In: YES 
user_id=72656
Originator: NO

Improved to 857.  Miguel is looking at the NRE again and other methods to reduce call overheads.
dkfplain2007-06-16 21:01:46
Logged In: YES 
user_id=79902
Originator: NO

With the HEAD building with msys (optimized, but untweaked) on WinXPSP2, I'm now getting a recursion depth of 1755. Test script was:

  interp recursionlimit {} 2000
  proc foo {} {global i;incr i;foo}
  catch {foo bar}
  set i 0
  catch { foo }
  puts $i
  puts [time { catch { foo } } 1000]
  exit

If others can confirm this, I'd call this issue closed.
dgpplain2007-06-18 23:23:39
Logged In: YES 
user_id=80530
Originator: NO


perhaps an addition to the test suite
to alert us if/when the limit gets
small again?
msofer Pending ticket [1066755fff]. [History diff]2008-06-28 21:23:28
sf-robotplain2008-07-13 09:20:23
Logged In: YES 
user_id=1312539
Originator: NO

This Tracker item was closed automatically by the system. It was
previously set to a Pending status, and the original submitter
did not respond within 14 days (the time period specified by
the administrator of this Tracker).
Log in (anonymous is fine) to add a comment.