From: Chet Ramey Date: Fri, 23 Aug 2019 13:52:32 +0000 (-0400) Subject: commit bash-20190822 snapshot X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d11d79842a99e3312751fc783a83de9f173d9943;p=thirdparty%2Fbash.git commit bash-20190822 snapshot --- diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index df23c1698..e0b26a138 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -6460,3 +6460,18 @@ execute_cmd.c lib/readline/colors.c - _rl_print_color_indicator: eliminate one use of S_ISLNK. Report and fix from Christian Biesinger + + 8/22 + ---- +variables.c + - push_posix_temp_var: change to use bind_variable and modify variables + at the current local scope or create and modify variables at the + global scope, as if a standalone assignment statement had been + executed. This restores some bash-4.4 backwards compatibility with + respect to posix-mode assignment statements preceding special + builtins and shell functions. The bash-5.0 behavior, while perhaps + defensible, caused too many compatibility problems. Originally + prompted by several discussions with Martijn Dekker; the current + incarnation and tests based on a report to Debian BTS from + Thorsten Glaser + diff --git a/MANIFEST b/MANIFEST index 75c1ef902..eaa6c60b8 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1429,6 +1429,7 @@ tests/varenv13.sub f tests/varenv14.sub f tests/varenv15.sub f tests/varenv15.in f +tests/varenv16.sub f tests/version f tests/version.mini f tests/vredir.tests f diff --git a/doc/bashref.texi b/doc/bashref.texi index 965b758cb..d5beccd73 100644 --- a/doc/bashref.texi +++ b/doc/bashref.texi @@ -2334,7 +2334,7 @@ is an array variable subscripted with @samp{@@} or @samp{*}, the operation is applied to each member of the array in turn, and the expansion is the resultant list. -The result of the expansion is subject to word splitting and pathname +The result of the expansion is subject to word splitting and filename expansion as described below. @end table diff --git a/tests/RUN-ONE-TEST b/tests/RUN-ONE-TEST index 0b0638107..c8bef8dd1 100755 --- a/tests/RUN-ONE-TEST +++ b/tests/RUN-ONE-TEST @@ -1,4 +1,4 @@ -BUILD_DIR=/usr/local/build/chet/bash/bash-current +BUILD_DIR=/usr/local/build/bash/bash-current THIS_SH=$BUILD_DIR/bash PATH=$PATH:$BUILD_DIR diff --git a/tests/varenv.right b/tests/varenv.right index 159a87737..b86202273 100644 --- a/tests/varenv.right +++ b/tests/varenv.right @@ -146,12 +146,19 @@ declare -x foo="abc" inside: declare -x var="value" outside: declare -- var="one" inside: declare -x var="value" -outside: declare -x var="value" -inside: declare -- var="local" -outside: declare -x var="global" -foo= environment foo= -foo=foo environment foo=foo -foo=foo environment foo=foo +outside: declare -- var="outside" +inside: declare -x var="inside" +outside: declare -- var="outside" +outside 1.0: var=one +outside 1.1: var=one +inside func: var=two +outside 2.0: var=two +inside func: var=two +outside 2.1: var=two +inside func1: var=value +outside 3.0: var=value +inside func2: var=global +outside 4.0: var=outside ./varenv13.sub: line 3: `var[0]': not a valid identifier ./varenv13.sub: line 3: `var[@]': not a valid identifier ./varenv13.sub: line 1: declare: var: not found @@ -207,6 +214,22 @@ after source 1: a b c d e f g h i j k l m n o p q r s t u v w x y z varenv15.in: before set: one two three four five six seven eight nine ten varenv15.in: after set: a b c d e f g h i j k l m n o p q r s t u v w x y z after source 2: a b c d e f g h i j k l m n o p q r s t u v w x y z +foo=showfoo environment foo=showfoo +foo=showfoo environment foo=showfoo +foo=showfoo environment foo=showfoo +outside: foo= + +posix mode +foo=showfoo environment foo=showfoo +outside 1.0: foo= +foo=showfoo environment foo=showfoo +foo=showfoo environment foo=showfoo +outside 1.1: foo=foo +foo= environment foo= +outside 2.0: foo= +foo=foo environment foo=foo +foo=foo environment foo=foo +outside 2.1: foo=foo a=z a=b a=z diff --git a/tests/varenv.tests b/tests/varenv.tests index 34b855963..5c69bbf4a 100644 --- a/tests/varenv.tests +++ b/tests/varenv.tests @@ -242,5 +242,7 @@ ${THIS_SH} ./varenv14.sub ${THIS_SH} ./varenv15.sub +${THIS_SH} ./varenv16.sub + # make sure variable scoping is done right tt() { typeset a=b;echo a=$a; };a=z;echo a=$a;tt;echo a=$a diff --git a/tests/varenv12.sub b/tests/varenv12.sub index edba3c946..7e384ac77 100644 --- a/tests/varenv12.sub +++ b/tests/varenv12.sub @@ -50,10 +50,11 @@ unset -f func # this will probably change behavior; export shouldn't behave like this when # not in posix mode and the sequencing is probably wrong in posix mode. since # export is a special builtin, the variable assignment should modify the -# global variable, leaving the local variable unchanged. all shells, including -# bash, modify the local variable; bash is the only one that propagates the -# value out to the calling environment. bash does that only when in posix -# mode. +# local variable, as if a standalone assignment statement had been executed +# (posix modifying "the current execution environment") leaving the global +# variable unchanged. all shells, including bash, modify the local variable; +# bash was the only one that propagates the value out to the calling +# environment, but no longer does so. func() { @@ -72,7 +73,7 @@ unset -f func func() { local var=local - var=global : + var=inside : echo -n 'inside: ' ; declare -p var } @@ -83,18 +84,50 @@ echo -n 'outside: ' ; declare -p var unset -v var unset -f func -# test whether or not temporary environment assignments are exported -# in posix mode -showfoo() +func() { - printf %s "foo=${foo-}" - echo -n ' environment foo=' - printenv foo || echo + echo -n 'inside func: ' ; echo "var=${var-}" } -unset foo -showfoo -foo=foo showfoo -showfoo -unset -v foo -unset -f showfoo +unset -v var +var=one : +echo -n 'outside 1.0: ' ; echo "var=${var-}" + +unset -v var +var=one eval ':' +echo -n 'outside 1.1: ' ; echo "var=${var-}" + +unset -v var + +var=two func +echo -n 'outside 2.0: ' ; echo "var=${var-}" +var=global +var=two func +echo -n 'outside 2.1: ' ; echo "var=${var-}" + +unset -v var +unset -f func + +func1() +{ + var=value export var + echo -n 'inside func1: ' ; echo "var=${var-}" +} + +var=outside +func1 +echo -n 'outside 3.0: ' ; echo "var=${var-}" + +unset -v var +unset -f func1 + +func2() +{ + local var=local + var=global : + echo -n 'inside func2: ' ; echo "var=${var-}" +} + +var=outside +func2 +echo -n 'outside 4.0: ' ; echo "var=${var-}" diff --git a/tests/varenv16.sub b/tests/varenv16.sub new file mode 100644 index 000000000..b3c342ca8 --- /dev/null +++ b/tests/varenv16.sub @@ -0,0 +1,38 @@ +# test whether or not temporary environment assignments are exported +# in posix mode. works now, posix says it will not work in the future + +show2() +{ + printf %s "foo=${foo-}" + echo -n ' environment foo=' + printenv foo || echo +} + +showfoo() +{ + local foo + + foo=showfoo show2 +} + +unset foo +showfoo +foo=foo showfoo +showfoo +echo outside: "foo=${foo-}" + +echo ; echo 'posix mode' +set -o posix +unset foo +showfoo +echo outside 1.0: "foo=${foo-}" +foo=foo showfoo +showfoo +echo outside 1.1: "foo=${foo-}" + +unset foo +show2 +echo outside 2.0: "foo=${foo-}" +foo=foo show2 +show2 +echo outside 2.1: "foo=${foo-}" diff --git a/variables.c b/variables.c index 77a61c4f6..cbdd2d270 100644 --- a/variables.c +++ b/variables.c @@ -324,6 +324,7 @@ static void push_func_var __P((PTR_T)); static void push_builtin_var __P((PTR_T)); static void push_exported_var __P((PTR_T)); +/* This needs to be looked at again. */ static inline void push_posix_tempvar_internal __P((SHELL_VAR *, int)); static inline int find_special_var __P((const char *)); @@ -4600,7 +4601,6 @@ push_posix_temp_var (data) var = (SHELL_VAR *)data; -#if 0 /* TAG:bash-5.1 */ /* Just like do_assignment_internal(). This makes assignments preceding special builtins act like standalone assignment statements when in posix mode, satisfying the posix requirement that this affect the @@ -4612,13 +4612,6 @@ push_posix_temp_var (data) Set binding_table appropriately. It doesn't matter whether it's correct if the variable is local, only that it's not global_variables->table */ binding_table = v->context ? shell_variables->table : global_variables->table; -#else - binding_table = global_variables->table; - if (binding_table == 0) - binding_table = global_variables->table = hash_create (VARIABLES_HASH_BUCKETS); - - v = bind_variable_internal (var->name, value_cell (var), binding_table, 0, ASS_FORCE|ASS_NOLONGJMP); -#endif /* global variables are no longer temporary and don't need propagating. */ if (binding_table == global_variables->table) @@ -4628,9 +4621,6 @@ push_posix_temp_var (data) { v->attributes |= var->attributes; v->attributes &= ~att_tempvar; /* not a temp var now */ -#if 1 /* TAG:bash-5.1 code doesn't need this, disable for bash-5.1 */ - v->context = (binding_table == global_variables->table) ? 0 : shell_variables->scope; -#endif } if (find_special_var (var->name) >= 0) @@ -4770,6 +4760,15 @@ merge_temporary_env () dispose_temporary_env (posixly_correct ? push_posix_temp_var : push_temp_var); } +/* Temporary function to use if we want to separate function and special + builtin behavior. */ +void +merge_function_temporary_env () +{ + if (temporary_env) + dispose_temporary_env (push_temp_var); +} + void flush_temporary_env () {