busybox/shell/hush_test/hush-misc
Denys Vlasenko 9abf53beb4 ash: eval: Variable assignments on functions are no longer persistent
Upstream commit:

    Date: Wed, 4 Apr 2018 17:54:01 +0800
    eval: Variable assignments on functions are no longer persistent

    Dirk Fieldhouse <fieldhouse@gmx.net> wrote:
    > In POSIX.1-2017 ("simultaneously IEEE Std 1003.1™-2017 and The Open
    > Group Technical Standard Base Specifications, Issue 7")
    > <http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09>,
    > we read under '2.9.1 Simple Commands'
    >
    > "Variable assignments shall be performed as follows:
    > ...
    > -    If the command name is a standard utility implemented as a function
    > (see XBD Utility), the effect of variable assignments shall be as if the
    > utility was not implemented as a function.
    > ...
    > -    If the command name is a function that is not a standard utility
    > implemented as a function, variable assignments shall affect the current
    > execution environment during the execution of the function. It is
    > unspecified:
    >
    >     *   Whether or not the variable assignments persist after the
    > completion of the function
    >
    >     *   Whether or not the variables gain the export attribute during
    > the execution of the function
    >
    >     *   Whether or not export attributes gained as a result of the
    > variable assignments persist after the completion of the function (if
    > variable assignments persist after the completion of the function)"

    POSIX used to require the current dash behaviour.  However, you're
    right that this is no longer the case.

    This patch will remove the persistence of the variable assignment.

    I have considered the exporting the variables during the function
    execution but have decided against it because:

    1) It makes the code bigger.
    2) dash has never done this in the past.
    3) You cannot use this portably anyway.

    Reported-by: Dirk Fieldhouse <fieldhouse@gmx.net>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

function                                             old     new   delta
evalcommand                                         1606    1635     +29
evalcase                                             313     317      +4
evalfun                                              280     268     -12
pushlocalvars                                         48       -     -48
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 2/1 up/down: 33/-60)            Total: -27 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-05 11:14:11 +02:00
..
and-or.right
and-or.tests
assignment1.right
assignment1.tests
assignment2.right
assignment2.tests
assignment3.right
assignment3.tests
assignment4.right
assignment4.tests
assignment5.right
assignment5.tests
break1.right
break1.tests
break2.right
break2.tests
break3.right
break3.tests
break4.right
break4.tests
break5.right
break5.tests
builtin1.right
builtin1.tests
case1.right
case1.tests
colon.right
colon.tests
command2.right
command2.tests
compound.right
compound.tests
continue1.right
continue1.tests
continue2.right
continue2.tests
continue3.right
continue3.tests
control_char1.right
control_char1.tests
control_char2.right
control_char2.tests
echo_write_error.right
echo_write_error.tests
empty_args.right
empty_args.tests
empty_for1.right
empty_for1.tests
empty_for2.right
empty_for2.tests
empty_for.right
empty_for.tests
env_and_func.right
env_and_func.tests
errexit1.right
errexit1.tests
eval1.right
eval1.tests
eval2.right
eval2.tests
exec.right
exec.tests
exit1.right
exit1.tests
exitcode1.right
exitcode1.tests
exitcode2.right
exitcode2.tests
exitcode_EACCES.right
exitcode_EACCES.tests
exitcode_ENOENT.right
exitcode_ENOENT.tests
export-n.right
export-n.tests
export.right
export.tests
for_with_bslashes.right
for_with_bslashes.tests
for_with_keywords.right
for_with_keywords.tests
for.right
for.tests
func1.right
func1.tests
func2.right
func2.tests
func3.right
func3.tests
func4.right
func4.tests
func5.right
func5.tests
func_args1.right
func_args1.tests
func_local1.right
func_local1.tests
func_local2.right
func_local2.tests
func_prio_over_builtins.right
func_prio_over_builtins.tests
func_return1.right
func_return1.tests
func_return2.right
func_return2.tests
group_in_braces.right
group_in_braces.tests
if_false_exitcode.right
if_false_exitcode.tests
last_amp.right
last_amp.tests
local1.right
local1.tests
nommu1.right
nommu1.tests
nommu2.right
nommu2.tests
nommu3.right
nommu3.tests
nulltick1.right
nulltick1.tests
opts1.right
opts1.tests
pid.right
pid.tests
pipefail.right
pipefail.tests
read.right
read.tests
return1.right
return1.tests
shift1.right
shift1.tests
shift.right
shift.tests
sig_exitcode.right
sig_exitcode.tests
source1.right
source1.tests
source2.right
source2.tests
source3.right
source3.tests
source4.right
source4.tests
source5.right
source5.tests
source_argv_and_shift.right
source_argv_and_shift.tests
syntax_err_negate.right
syntax_err_negate.tests
syntax_err.right
syntax_err.tests
tickquote1.right
tickquote1.tests
unicode1.right
unicode1.tests
until1.right
until1.tests
wait1.right
wait1.tests
wait2.right
wait2.tests
wait3.right
wait3.tests
wait4.right
wait4.tests
wait5.right
wait5.tests
wait6.right
wait6.tests
while1.right
while1.tests
while2.right
while2.tests
while3.right
while3.tests
while4.right
while4.tests
while_in_subshell.right
while_in_subshell.tests