[TUHS] Lorinda Cherry
Otto Moerbeek
otto at drijf.net
Wed Feb 23 01:53:06 AEST 2022
On Tue, Feb 22, 2022 at 10:39:48AM +0000, Ralph Corderoy wrote:
> Hi Otto,
>
> > MacOS uses the GNU implementation which has a long standing issue with
> > deep recursion. It even cannot handle the tail recursive calls used
> > here and will run out of its stack.
>
> When learning dc and seeing it relied on tail calls, the first thing
> I did was check it did tail-call elimination, and it did. That was
> GNU dc.
>
> Trying just now, I see no growth in memory usage despite heavy CPU load
> shown by TIME increasing.
>
> $ dc
> !ps u `pidof dc`
> USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
> ralph 11489 0.0 0.0 2332 1484 pts/1 S+ 10:33 0:00 dc
> [lmx]smlmx
> ^C
> Interrupt!
> !ps u `pidof dc`
> USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
> ralph 11489 75.5 0.0 2332 1488 pts/1 S+ 10:33 0:46 dc
>
> The memory used remained at that level during the macro execution too,
> watched from outside.
>
> Do you have more detail on what GNU dc can't handle? dc without
> tail-call elimination is a bit crippled.
>
> --
> Cheers, Ralph.
On MacOS:
$ dc --version
dc (GNU bc 1.06) 1.3
...
$ dc
[lmx]smlmx
Segmentation fault: 11
$
On debian bullseye:
$ dc --version
dc (GNU bc 1.07.1) 1.4.1
...
$ dc
[lmx]smlmx
...
all ok.
So the basic tail recursion case seems to be fixed in recent versions.
But note that
[laxp]sa
1 lax
still segfaults on both GNU dc versions while on OpenBSD, using the
dc I wrote:
dc: recursion too deep: Cannot allocate memory
This is not a tail recursion case, but segfaulting is not nice at all.
-Otto
More information about the TUHS
mailing list