1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

[1.0 release prep] Remove tilde expansion discipline

Defining a .sh.tilde.get or .sh.tilde.set discipline function to
extend tilde expansion works well as long as the discipline
function doesn't get interrupted (e.g. with Crtl+C) or produce an
error message. Either of those will cause the shell to become
unstable and crash.

This feature is now removed from the 1.0 branch as it is not ready
for prime time. It can return to a release branch if/when we manage
to fix it on the master branch.

Related: https://github.com/ksh93/ksh/issues/346
This commit is contained in:
Martijn Dekker 2021-11-24 07:46:58 +01:00
parent 40de1e92b0
commit c0334e32a1
9 changed files with 1 additions and 134 deletions

View file

@ -751,24 +751,6 @@ r ^:test-2: echo Success\r\n$
r ^Success\r\n$
!
# err_exit #
((SHOPT_VSH || SHOPT_ESH)) && tst $LINENO <<"!"
L value of $? after tilde expansion in tab completion
# Make sure that a .sh.tilde.set discipline function
# cannot influence the exit status.
w .sh.tilde.set() { true; }
w HOME=/tmp
w false ~\t
u false /tmp
w echo "Exit status is: $?"
u Exit status is: 1
w (exit 42)
w echo $? ~\t
u 42 /tmp
!
# err_exit #
((SHOPT_MULTIBYTE && (SHOPT_VSH || SHOPT_ESH))) &&
[[ ${LC_ALL:-${LC_CTYPE:-${LANG:-}}} =~ [Uu][Tt][Ff]-?8 ]] &&

View file

@ -107,8 +107,6 @@ got=~
HOME=$saveHOME
# ======
# Tilde expansion discipline function tests
# This nonfunctional mess was removed in ksh 93u+m ...
if builtin .sh.tilde 2>/dev/null
then got=$(.sh.tilde & wait "$!" 2>&1)
@ -116,57 +114,5 @@ then got=$(.sh.tilde & wait "$!" 2>&1)
"(got status $e$( ((e>128)) && print -n / && kill -l "$e"), $(printf %q "$got"))"
fi
# ... and replaced by a proper use of discipline functions that allows customising tilde expansion.
((.sh.version >= 20210316)) &&
for disc in get set
do (
ulimit -t unlimited 2>/dev/null # fork subshell to cope with a possible crash
eval ".sh.tilde.$disc()
{
case \${.sh.${ [[ $disc == get ]] && print tilde || print value; }} in
'~tmp') .sh.value=\$tmp ;;
'~INC') .sh.value=\$((++i)) ;;
'~spc') .sh.value=$'one\ttwo three\n\tfour' ;;
'~') .sh.value=~/addition ;; # this should not recurse
esac
}"
got=~/foo
exp=$HOME/addition/foo
[[ $got == "$exp" ]] || err_exit "$disc discipline: bare tilde expansion:" \
"expected $(printf %q "$exp"), got $(printf %q "$got")"
.sh.tilde=oldvalue
got=$(print ~tmp/foo.$$; print "${.sh.tilde}")
exp=$tmp/foo.$$$'\n'$tmp
[[ $got == "$exp" ]] || err_exit "$disc discipline: result left in \${.sh.tilde}:" \
"expected $(printf %q "$tmp"), got $(printf %q "${.sh.tilde}")"
[[ ${.sh.tilde} == oldvalue ]] || err_exit "$disc discipline: \${.sh.tilde} subshell leak"
i=0
set -- ~INC ~INC ~INC ~INC ~INC
got=$#,$1,$2,$3,$4,$5
exp=5,1,2,3,4,5
[[ $got == "$exp" ]] || err_exit "$disc discipline: counter:" \
"expected $(printf %q "$exp"), got $(printf %q "$got")"
((i==5)) || err_exit "$disc discipline: counter: $i != 5"
set -- ~spc ~spc ~spc
got=$#,$1,$2,$3
exp=$'3,one\ttwo three\n\tfour,one\ttwo three\n\tfour,one\ttwo three\n\tfour'
[[ $got == "$exp" ]] || err_exit "$disc discipline: quoting of whitespace:" \
"expected $(printf %q "$exp"), got $(printf %q "$got")"
print "$Errors" >$tmp/Errors
) &
wait "$!" 2>crashmsg
if ((!(e = $?)))
then read Errors <$tmp/Errors
else err_exit ".sh.tilde.$disc discipline function crashes the shell" \
"(got status $e$( ((e>128)) && print -n / && kill -l "$e"), $(printf %q "$(<crashmsg)"))"
fi
done
# ======
exit $((Errors<125?Errors:125))

View file

@ -1026,7 +1026,6 @@ set -- \
".sh.math" \
".sh.pool" \
".sh.pid" \
".sh.tilde" \
"SHLVL" \
"CSWIDTH"