]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
commit bash-20120511 snapshot
authorChet Ramey <chet@caleb.ins.cwru.edu>
Tue, 5 Jun 2012 14:16:44 +0000 (10:16 -0400)
committerChet Ramey <chet@caleb.ins.cwru.edu>
Tue, 5 Jun 2012 14:16:44 +0000 (10:16 -0400)
13 files changed:
CWRU/CWRU.chlog
MANIFEST
arrayfunc.c
arrayfunc.h
doc/bash.1
doc/bashref.texi
execute_cmd.c
tests/RUN-ONE-TEST
tests/appendop.right
tests/appendop.tests
tests/appendop1.sub [new file with mode: 0644]
tests/run-printf.save [new file with mode: 0644]
variables.c

index 6168935f37faa08d02156ac32ad4be5f060a6ef8..74022607ae2c987c39f52fa10a9bb56c6608c5da 100644 (file)
@@ -13803,3 +13803,23 @@ subst.c
          only set W_HASQUOTEDNULL in the returned word flags if the word is
          a quoted null string AND had_quoted_null is set.  Rest of fix
 
+                                   5/9
+                                   ---
+variables.c
+       - bind_variable_internal: if we get an array variable here (implicit
+         assignment to index 0), call make_array_variable_value, which
+         dummies up a fake SHELL_VAR * from array[0].  This matters when
+         we're appending and have to use the current value
+       - bind_variable_internal: after computing the new value, treat assoc
+         variables with higher precedence than simple array variables; it
+         might be that a variable has both attributes set
+
+arrayfunc.c
+       - bind_array_var_internal: break code out that handles creating the
+         new value to be assigned to an array variable index into a new
+         function, make_array_variable_value.  This handles creating a
+         dummy SHELL_VAR * for implicit array[0] assignment.  Fixes bug
+         reported by Dan Douglas <ormaaj@gmail.com>
+
+arrayfunc.h
+       - make_array_variable_value: new extern declaration
index 770102d4590240ee3382d525ec5f01b42d0c05a0..966f76126c79ae17b2dc5924e2e910d6a0ffb949 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -766,6 +766,7 @@ tests/alias.tests   f
 tests/alias1.sub       f
 tests/alias.right      f
 tests/appendop.tests   f
+tests/appendop1.sub    f
 tests/appendop.right   f
 tests/arith-for.tests  f
 tests/arith-for.right  f
index 0ae89dacf76305fc5b572cfbf54eec8008363de9..5fcfa91d19fcb7859f006343906fba0dbfd754e1 100644 (file)
@@ -118,8 +118,8 @@ convert_var_to_assoc (var)
   return var;
 }
 
-static SHELL_VAR *
-bind_array_var_internal (entry, ind, key, value, flags)
+char *
+make_array_variable_value (entry, ind, key, value, flags)
      SHELL_VAR *entry;
      arrayind_t ind;
      char *key;
@@ -156,6 +156,21 @@ bind_array_var_internal (entry, ind, key, value, flags)
   else
     newval = make_variable_value (entry, value, flags);
 
+  return newval;
+}
+  
+static SHELL_VAR *
+bind_array_var_internal (entry, ind, key, value, flags)
+     SHELL_VAR *entry;
+     arrayind_t ind;
+     char *key;
+     char *value;
+     int flags;
+{
+  char *newval;
+
+  newval = make_array_variable_value (entry, ind, key, value, flags);
+
   if (entry->assign_func)
     (*entry->assign_func) (entry, newval, ind, key);
   else if (assoc_p (entry))
index 23649bcdde44a3e632d16cb0fc9998eaf6f0ab9e..26f4879af3d48149d6c74a3895fd6648dccb1311 100644 (file)
@@ -33,6 +33,8 @@
 extern SHELL_VAR *convert_var_to_array __P((SHELL_VAR *));
 extern SHELL_VAR *convert_var_to_assoc __P((SHELL_VAR *));
 
+extern char *make_array_variable_value __P((SHELL_VAR *, arrayind_t, char *, char *, int));
+
 extern SHELL_VAR *bind_array_variable __P((char *, arrayind_t, char *, int));
 extern SHELL_VAR *bind_array_element __P((SHELL_VAR *, arrayind_t, char *, int));
 extern SHELL_VAR *assign_array_element __P((char *, char *, int));
index d1b12423174e4d0cc4b40e331b0adb4992cecaff..077a172cf5180826d800e06294ec9f3552e9fb7e 100644 (file)
@@ -2382,6 +2382,7 @@ be indexed or assigned contiguously.
 Indexed arrays are referenced using integers (including arithmetic
 expressions)  and are zero-based; associative arrays are referenced
 using arbitrary strings.
+Unless otherwise noted, indexed array indices must be non-negative integers.
 .PP
 An indexed array is created automatically if any variable is assigned to
 using the syntax \fIname\fP[\fIsubscript\fP]=\fIvalue\fP.  The
index 19c56c1715759bc03b8dc5f14d15d689c307d357..820d1fd4308a3bffa887f40021d73fe3b55ef547 100644 (file)
@@ -6462,6 +6462,7 @@ be indexed or assigned contiguously.
 Indexed arrays are referenced using integers (including arithmetic
 expressions (@pxref{Shell Arithmetic})) and are zero-based;
 associative arrays use arbitrary strings.
+Unless otherwise noted, indexed array indices must be non-negative integers.
 
 An indexed array is created automatically if any variable is assigned to
 using the syntax
index f6f7bc8cec337f3572bf4e84b1319250c01d2e81..eefa05e537d2b9c4152b09171dc6f4874b5de437 100644 (file)
@@ -4118,7 +4118,7 @@ run_builtin:
     }
 
   if (command_line == 0)
-    command_line = savestring (the_printed_command_except_trap);
+    command_line = savestring (the_printed_command_except_trap ? the_printed_command_except_trap : "");
 
 #if defined (PROCESS_SUBSTITUTION)
   if ((subshell_environment & SUBSHELL_COMSUB) && (simple_command->flags & CMD_NO_FORK) && fifos_pending() > 0)
index 72ec06a2c1fd8dde92acea5e8ac773e35f1d061b..3efcf32d68e9722024b6ca9d67f9e81b2aa5ac04 100755 (executable)
@@ -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
 
index 1e24333236db82909386b2e50b5ef8280e0f2b64..5d55b9c211524cbe49d280922be2f41babbc7942 100644 (file)
@@ -16,3 +16,8 @@
 9
 16
 ./appendop.tests: line 83: x: readonly variable
+declare -A foo='([one]="bar" [two]="baz" [three]="quux" )'
+declare -A foo='([one]="bar" [two]="baz" [0]="zero" [three]="quux" )'
+declare -A foo='([four]="four" [one]="bar" [two]="baz" [0]="zero" [three]="quux" )'
+declare -ai iarr='([0]="3" [1]="2" [2]="3")'
+declare -ai iarr='([0]="3" [1]="2" [2]="3" [3]="4" [4]="5" [5]="6")'
index 7b61f3f158b2f5630c0b841f9b77c3fc07ef7737..be6c971661678b97e418efd7375f0b10f4e4ce75 100644 (file)
@@ -81,3 +81,5 @@ readonly x+=7
 echo $x
 
 x+=5
+
+${THIS_SH} ./appendop1.sub
diff --git a/tests/appendop1.sub b/tests/appendop1.sub
new file mode 100644 (file)
index 0000000..7101d0c
--- /dev/null
@@ -0,0 +1,15 @@
+typeset -A foo=([one]=bar [two]=baz [three]=quux)
+typeset -p foo
+
+foo+=zero
+typeset -p foo
+
+foo+=([four]=four)
+typeset -p foo
+
+typeset -ia iarr=(2 2 3)
+iarr+=1
+typeset -p iarr
+
+iarr+=(4 5 6)
+typeset -p iarr
diff --git a/tests/run-printf.save b/tests/run-printf.save
new file mode 100644 (file)
index 0000000..4555c62
--- /dev/null
@@ -0,0 +1,5 @@
+# See whether or not we can use `diff -a'
+( diff -a ./printf.tests ./printf.tests >/dev/null 2>&1 ) && AFLAG=-a
+
+${THIS_SH} ./printf.tests > /tmp/xx 2>&1
+diff $AFLAG /tmp/xx printf.right && rm -f /tmp/xx
index 13fccbd2d392c378b506923acff89520f2293555..10000d9d33afc34dbea4f7f86fdb105e4cd6bd8f 100644 (file)
@@ -2241,6 +2241,12 @@ bind_variable_internal (name, value, table, hflags, aflags)
       /* Variables which are bound are visible. */
       VUNSETATTR (entry, att_invisible);
 
+#if defined (ARRAY_VARS)
+      if (assoc_p (entry) || array_p (entry))
+        newval = make_array_variable_value (entry, 0, "0", value, aflags);
+      else
+#endif
+
       newval = make_variable_value (entry, value, aflags);     /* XXX */
 
       /* Invalidate any cached export string */
@@ -2251,14 +2257,14 @@ bind_variable_internal (name, value, table, hflags, aflags)
       /* If an existing array variable x is being assigned to with x=b or
         `read x' or something of that nature, silently convert it to
         x[0]=b or `read x[0]'. */
-      if (array_p (entry))
+      if (assoc_p (entry))
        {
-         array_insert (array_cell (entry), 0, newval);
+         assoc_insert (assoc_cell (entry), savestring ("0"), newval);
          free (newval);
        }
-      else if (assoc_p (entry))
+      else if (array_p (entry))
        {
-         assoc_insert (assoc_cell (entry), savestring ("0"), newval);
+         array_insert (array_cell (entry), 0, newval);
          free (newval);
        }
       else