diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 2c19aef5..2e892652 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -11270,3 +11270,26 @@ variables.c assignment on a nameref variable, display a warning and remove the nameref attribute (as bash-4.3 did). Reported by Dan Douglas + + 6/14 + ---- +test.c + - posixtest: handle four-argument case where argv[1] == '(' and + argv[4] == ')' by performing two-argument test on $2 and $3. Reported + by Joerg Schilling + + 6/15 + ---- +variables.c + - sv_ignoreeof: make sure ignoreeof is set only if IGNOREEOF is set and + has a value (no `local IGNOREEOF'). Reported by Grisha Levit + + - sv_strict_posix: make sure posixly_correct is set only if POSIXLY_CORRECT + is set and has a value. Reported by Grisha Levit + + 6/16 + ---- +builtins/declare.def + - declare_internal: analogous to 6/12 change; when performing an array + subscript assignment on a nameref, display a warning, remove the + nameref attribute, and go on diff --git a/MANIFEST b/MANIFEST index 8e16b116..00ae485d 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1088,6 +1088,7 @@ tests/nameref14.sub f tests/nameref15.sub f tests/nameref16.sub f tests/nameref17.sub f +tests/nameref18.sub f tests/nameref.right f tests/new-exp.tests f tests/new-exp1.sub f diff --git a/builtins/declare.def b/builtins/declare.def index bab3979b..5f92f9f5 100644 --- a/builtins/declare.def +++ b/builtins/declare.def @@ -563,6 +563,21 @@ restart_new_var_name: if (refvar) var = mkglobal ? find_global_variable (nameref_cell (refvar)) : find_variable (nameref_cell (refvar)); } +#if defined (ARRAY_VARS) + /* If we have an array assignment to a nameref, remove the nameref + attribute and go on. */ + else if (var == 0 && offset && array_subscript_assignment) + { + var = mkglobal ? find_global_variable_noref (name) : find_variable_noref (name); + if (var && nameref_p (var)) + { + internal_warning (_("%s: removing nameref attribute"), name); + FREE (value_cell (var)); /* XXX - bash-4.3 compat */ + var_setvalue (var, (char *)NULL); + VUNSETATTR (var, att_nameref); + } + } +#endif /* See if we are trying to set flags or value for an existing nameref that points to a non-existent variable: e.g., diff --git a/jobs.c b/jobs.c index bae67cc9..55d6ba19 100644 --- a/jobs.c +++ b/jobs.c @@ -1905,6 +1905,7 @@ make_child (command, async_p) /* If we can't create any children, try to reap some dead ones. */ waitchld (-1, 0); + errno = EAGAIN; /* restore errno */ sys_error ("fork: retry"); RESET_SIGTERM; diff --git a/test.c b/test.c index 95e10a02..ee634204 100644 --- a/test.c +++ b/test.c @@ -823,6 +823,13 @@ posixtest () value = !three_arguments (); break; } + else if (argv[pos][0] == '(' && argv[pos][1] == '\0' && argv[argc-1][0] == ')' && argv[argc-1][1] == '\0') + { + advance (1); + value = two_arguments (); + pos = argc; + break; + } /* FALLTHROUGH */ default: value = expr (); diff --git a/tests/RUN-ONE-TEST b/tests/RUN-ONE-TEST index a5ab273d..d29259a9 100755 --- a/tests/RUN-ONE-TEST +++ b/tests/RUN-ONE-TEST @@ -1,4 +1,4 @@ -BUILD_DIR=/usr/local/build/bash/bash-current +BUILD_DIR=/usr/local/build/chet/bash/bash-current THIS_SH=$BUILD_DIR/bash PATH=$PATH:$BUILD_DIR diff --git a/tests/lastpipe.right b/tests/lastpipe.right index 0168df85..cca5938d 100644 --- a/tests/lastpipe.right +++ b/tests/lastpipe.right @@ -17,3 +17,4 @@ A1 A2 B1 B2 +HI -- 42 -- 0 42 diff --git a/tests/lastpipe2.sub b/tests/lastpipe2.sub index 7cb6dc14..3bcc37d3 100644 --- a/tests/lastpipe2.sub +++ b/tests/lastpipe2.sub @@ -18,3 +18,13 @@ echo -e 'A\nB' | while read letter; do done rm -f $TMPDIR/outfile + +unset -f myPipefunc +myPipefunc() +{ + cat | read var + return 42 +} +echo HI | myPipefunc + +echo $var -- $? -- ${PIPESTATUS[@]} diff --git a/tests/nameref.right b/tests/nameref.right index b777f907..9ad0aee4 100644 --- a/tests/nameref.right +++ b/tests/nameref.right @@ -320,6 +320,20 @@ declare -n ref="var[@]" ./nameref15.sub: line 48: var[@]: bad array subscript declare -n bar="var[@]" ./nameref15.sub: line 53: var[@]: bad array subscript +declare -n a="b" +declare -n b="a[1]" +./nameref15.sub: line 61: warning: a: removing nameref attribute +declare -a a=([1]="foo") +declare -n b="a[1]" +./nameref15.sub: line 66: warning: a: removing nameref attribute +declare -a a=([1]="foo") +declare -n b="a[1]" +declare -n n="v" +declare -a v=([1]="1") +./nameref15.sub: line 82: typeset: n: not found +declare -a v=([0]="0" [1]="1") +declare -n n="v[1]" +declare -a v=([0]="0") declare -n r1="y" declare -n r2="x" ./nameref16.sub: line 12: typeset: x: not found @@ -372,3 +386,27 @@ declare -nr foo5 declare -r foo5 declare -nr foo5 declare -r foo5 +./nameref18.sub: line 2: mapfile: `XXX[0]': not a valid identifier +./nameref18.sub: line 3: declare: XXX[0]: not found +./nameref18.sub: line 9: `XXX[0]': not a valid identifier +./nameref18.sub: line 10: declare: XXX[0]: not found +declare -n ref="XXX[0]" +declare -a XXX=([0]="4") +./nameref18.sub: line 24: `XXX[0]': not a valid identifier +declare -n ref="XXX[0]" +./nameref18.sub: line 25: declare: XXX[0]: not found +./nameref18.sub: line 29: read: `XXX[0]': not a valid identifier +./nameref18.sub: line 30: declare: XXX[0]: not found +./nameref18.sub: line 35: `XXX[0]': not a valid identifier +declare -n ref="XXX[0]" +./nameref18.sub: line 38: `XXX[0]': not a valid identifier +./nameref18.sub: line 38: declare: XXX[0]: not found +declare -n ref="var[123]" +./nameref18.sub: line 46: declare: var[123]: not found +declare -a var=([123]="") +declare -n ref="var[123]" +./nameref18.sub: line 50: declare: var[123]: not found +declare -a var=([123]="") +declare -n ref="var[123]" +./nameref18.sub: line 54: declare: var[123]: not found +declare -a var=([123]="X") diff --git a/tests/nameref.tests b/tests/nameref.tests index 4114b586..f4af904c 100644 --- a/tests/nameref.tests +++ b/tests/nameref.tests @@ -115,20 +115,6 @@ declare -n v=var echo ${!x//c/x} echo ${v//c/x} -${THIS_SH} ./nameref1.sub -${THIS_SH} ./nameref2.sub -${THIS_SH} ./nameref3.sub -${THIS_SH} ./nameref4.sub -${THIS_SH} ./nameref5.sub -${THIS_SH} ./nameref6.sub -${THIS_SH} ./nameref7.sub -${THIS_SH} ./nameref8.sub -${THIS_SH} ./nameref9.sub -${THIS_SH} ./nameref10.sub -${THIS_SH} ./nameref11.sub -${THIS_SH} ./nameref12.sub -${THIS_SH} ./nameref13.sub -${THIS_SH} ./nameref14.sub -${THIS_SH} ./nameref15.sub -${THIS_SH} ./nameref16.sub -${THIS_SH} ./nameref17.sub +for testfile in ./nameref[0-9].sub ./nameref[1-9][0-9].sub ; do + ${THIS_SH} "$testfile" +done diff --git a/tests/nameref15.sub b/tests/nameref15.sub index 3ccfff4a..6c9ace5e 100644 --- a/tests/nameref15.sub +++ b/tests/nameref15.sub @@ -51,3 +51,38 @@ typeset -n bar bar=var[@] typeset -p bar bar=7 + +unset a b +unset -n a b + +typeset -n a=b b +b=a[1] +typeset -p a b +a=foo +typeset -p a b + +unset a +typeset -n a=b +declare a=foo +typeset -p a b + +unset n v +unset -n n v + +v=(0 1) +typeset -n n=v +unset n[0] +typeset -p n v + +unset -n n + +v=(0 1) +typeset -n n=v +unset -n n +typeset -p n v + +v=(0 1) +declare -n n=v[1] +unset n +declare -p n v + diff --git a/tests/nameref18.sub b/tests/nameref18.sub new file mode 100644 index 00000000..1b022959 --- /dev/null +++ b/tests/nameref18.sub @@ -0,0 +1,54 @@ +declare -n ref=XXX[0] +mapfile ref <<< $'1\n2' +declare -p XXX[0] + +unset -n ref + +declare -n ref=XXX[0] +declare -A ref +ref[foo]=bar +declare -p XXX[0] + +unset -n ref +unset XXX + +typeset -n ref=XXX[0] +typeset ref=4 + +typeset -p ref XXX + +unset -n ref +unset XXX + +declare -n ref=XXX[0] +ref+=([2]=x) +declare -p ref XXX[0] +unset -n ref + +declare -n ref=XXX[0] +read -a ref <<< "A B C" +declare -p XXX[0] +unset -n ref + +declare -n ref=XXX[0] +unset ref +ref=() +declare -p ref + +coproc ref { :; }; declare -p ${!ref} +wait + +unset -n ref + +declare -n ref=var[123] +unset ref +declare ref= +declare -p ref ${!ref} var + +unset ref +declare ref+= +declare -p ref ${!ref} var + +declare +t ref +ref=X +declare -p ref ${!ref} var diff --git a/variables.c b/variables.c index f249838c..be2446e0 100644 --- a/variables.c +++ b/variables.c @@ -2723,17 +2723,16 @@ bind_variable_internal (name, value, table, hflags, aflags) /* declare -n foo=x[2] ; foo=bar */ if (valid_array_reference (newval, 0)) { -tname = array_variable_name (newval, (char **)0, (int *)0); -if (tname && (tentry = find_variable_noref (tname)) && nameref_p (tentry)) - { - /* nameref variables can't be arrays */ - internal_warning (_("%s: removing nameref attribute"), name_cell (tentry)); -#if 1 - FREE (value_cell (tentry)); /* XXX - bash-4.3 compat */ - var_setvalue (tentry, (char *)NULL); -#endif - VUNSETATTR (tentry, att_nameref); - } + tname = array_variable_name (newval, (char **)0, (int *)0); + if (tname && (tentry = find_variable_noref (tname)) && nameref_p (tentry)) + { + /* nameref variables can't be arrays */ + internal_warning (_("%s: removing nameref attribute"), name_cell (tentry)); + FREE (value_cell (tentry)); /* XXX - bash-4.3 compat */ + var_setvalue (tentry, (char *)NULL); + VUNSETATTR (tentry, att_nameref); + } + free (tname); /* XXX - should it be aflags? */ entry = assign_array_element (newval, make_variable_value (entry, value, 0), aflags|ASS_NAMEREF); if (entry == 0) @@ -5399,7 +5398,7 @@ sv_ignoreeof (name) eof_encountered = 0; tmp_var = find_variable (name); - ignoreeof = tmp_var != 0; + ignoreeof = tmp_var && var_isset (tmp_var); temp = tmp_var ? value_cell (tmp_var) : (char *)NULL; if (temp) eof_encountered_limit = (*temp && all_digits (temp)) ? atoi (temp) : 10; @@ -5448,7 +5447,10 @@ void sv_strict_posix (name) char *name; { - SET_INT_VAR (name, posixly_correct); + SHELL_VAR *var; + + var = find_variable (name); + posixly_correct = var && var_isset (var); posix_initialize (posixly_correct); #if defined (READLINE) if (interactive_shell)