mirror of
git://git.suckless.org/sbase
synced 2026-01-26 13:43:17 +00:00
dc: Relax tail call optimization
Classical dc implementations only apply tail recursion optimization but we were applying tail call recursion, removing one frame even when no recursion was involved. This creates problems with bc that does not track this optimization and it generates values for the Q command without caring about this optimization.
This commit is contained in:
parent
9439e85c04
commit
2544b70216
6
dc.c
6
dc.c
@ -1892,14 +1892,14 @@ execmacro(void)
|
||||
return;
|
||||
}
|
||||
|
||||
/* check for tail recursion */
|
||||
for (ch = *input->s; ch > 0 && ch < UCHAR_MAX; ch = *input->s) {
|
||||
for (ch = *input->s; ch > 0 && ch <= UCHAR_MAX; ch = *input->s) {
|
||||
if (!isspace(ch))
|
||||
break;
|
||||
++input->s;
|
||||
}
|
||||
|
||||
if (ch == '\0') {
|
||||
/* check for tail recursion */
|
||||
if (ch == '\0' && strcmp(input->buf, v.u.s) == 0) {
|
||||
free(input->buf);
|
||||
input->buf = input->s = v.u.s;
|
||||
return;
|
||||
|
||||
19
tests/0045-dc.sh
Executable file
19
tests/0045-dc.sh
Executable file
@ -0,0 +1,19 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
tmp=$$.tmp
|
||||
|
||||
trap 'rm -f $tmp' EXIT
|
||||
trap 'exit $?' HUP INT TERM
|
||||
|
||||
echo 0 > $tmp
|
||||
|
||||
../dc -i <<'EOF' | diff -u - $tmp
|
||||
[ 0 Lxs. 2Q]s<128>
|
||||
[ .7853981633974483096156608458198757210492923498437764 1/ Lxs. 3Q]s<130>
|
||||
[K 52><130> ]s<129>
|
||||
[Sxlx 0=<128> lx 1=<129> 0 Lxs. 1Q]s<1>
|
||||
|
||||
1l<1>xps.
|
||||
EOF
|
||||
Loading…
x
Reference in New Issue
Block a user