1 |
vapier 09/02/26 22:21:51 |
2 |
|
3 |
Added: bash-4.0-associative-array-subscripts.patch |
4 |
Log: |
5 |
Add upstream patch for associative array issues. |
6 |
(Portage version: 2.2_rc23/cvs/Linux x86_64) |
7 |
|
8 |
Revision Changes Path |
9 |
1.1 app-shells/bash/files/bash-4.0-associative-array-subscripts.patch |
10 |
|
11 |
file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/app-shells/bash/files/bash-4.0-associative-array-subscripts.patch?rev=1.1&view=markup |
12 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/app-shells/bash/files/bash-4.0-associative-array-subscripts.patch?rev=1.1&content-type=text/plain |
13 |
|
14 |
Index: bash-4.0-associative-array-subscripts.patch |
15 |
=================================================================== |
16 |
http://lists.gnu.org/archive/html/bug-bash/2009-02/msg00188.html |
17 |
|
18 |
*** ../bash-4.0/parse.y 2009-01-08 08:29:12.000000000 -0500 |
19 |
--- parse.y 2009-02-25 17:25:56.000000000 -0500 |
20 |
*************** |
21 |
*** 2916,2919 **** |
22 |
--- 2919,2923 ---- |
23 |
#define P_COMMAND 0x08 /* parsing a command, so look for comments */ |
24 |
#define P_BACKQUOTE 0x10 /* parsing a backquoted command substitution */ |
25 |
+ #define P_ARRAYSUB 0x20 /* parsing a [...] array subscript for assignment */ |
26 |
|
27 |
/* Lexical state while parsing a grouping construct or $(...). */ |
28 |
*************** |
29 |
*** 3130,3133 **** |
30 |
--- 3134,3139 ---- |
31 |
FREE (nestret); |
32 |
} |
33 |
+ else if ((flags & P_ARRAYSUB) && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */ |
34 |
+ goto parse_dollar_word; |
35 |
} |
36 |
/* Parse an old-style command substitution within double quotes as a |
37 |
*************** |
38 |
*** 3146,3149 **** |
39 |
--- 3152,3156 ---- |
40 |
/* check for $(), $[], or ${} inside quoted string. */ |
41 |
{ |
42 |
+ parse_dollar_word: |
43 |
if (open == ch) /* undo previous increment */ |
44 |
count--; |
45 |
*************** |
46 |
*** 4249,4253 **** |
47 |
(token_index == 0 && (parser_state&PST_COMPASSIGN)))) |
48 |
{ |
49 |
! ttok = parse_matched_pair (cd, '[', ']', &ttoklen, 0); |
50 |
if (ttok == &matched_pair_error) |
51 |
return -1; /* Bail immediately. */ |
52 |
--- 4256,4260 ---- |
53 |
(token_index == 0 && (parser_state&PST_COMPASSIGN)))) |
54 |
{ |
55 |
! ttok = parse_matched_pair (cd, '[', ']', &ttoklen, P_ARRAYSUB); |
56 |
if (ttok == &matched_pair_error) |
57 |
return -1; /* Bail immediately. */ |
58 |
*** ../bash-4.0/arrayfunc.c 2009-01-04 14:32:21.000000000 -0500 |
59 |
--- arrayfunc.c 2009-02-25 07:58:54.000000000 -0500 |
60 |
*************** |
61 |
*** 605,666 **** |
62 |
} |
63 |
|
64 |
! /* This function assumes s[i] == '['; returns with s[ret] == ']' if |
65 |
! an array subscript is correctly parsed. */ |
66 |
! int |
67 |
! skipsubscript (s, i) |
68 |
! const char *s; |
69 |
! int i; |
70 |
! { |
71 |
! int count, c; |
72 |
! #if defined (HANDLE_MULTIBYTE) |
73 |
! mbstate_t state, state_bak; |
74 |
! size_t slength, mblength; |
75 |
! #endif |
76 |
! |
77 |
! #if defined (HANDLE_MULTIBYTE) |
78 |
! memset (&state, '\0', sizeof (mbstate_t)); |
79 |
! slength = strlen (s + i); |
80 |
! #endif |
81 |
! |
82 |
! count = 1; |
83 |
! while (count) |
84 |
! { |
85 |
! /* Advance one (possibly multibyte) character in S starting at I. */ |
86 |
! #if defined (HANDLE_MULTIBYTE) |
87 |
! if (MB_CUR_MAX > 1) |
88 |
! { |
89 |
! state_bak = state; |
90 |
! mblength = mbrlen (s + i, slength, &state); |
91 |
! |
92 |
! if (MB_INVALIDCH (mblength)) |
93 |
! { |
94 |
! state = state_bak; |
95 |
! i++; |
96 |
! slength--; |
97 |
! } |
98 |
! else if (MB_NULLWCH (mblength)) |
99 |
! return i; |
100 |
! else |
101 |
! { |
102 |
! i += mblength; |
103 |
! slength -= mblength; |
104 |
! } |
105 |
! } |
106 |
! else |
107 |
! #endif |
108 |
! ++i; |
109 |
! |
110 |
! c = s[i]; |
111 |
! |
112 |
! if (c == 0) |
113 |
! break; |
114 |
! else if (c == '[') |
115 |
! count++; |
116 |
! else if (c == ']') |
117 |
! count--; |
118 |
! } |
119 |
! |
120 |
! return i; |
121 |
! } |
122 |
|
123 |
/* This function is called with SUB pointing to just after the beginning |
124 |
--- 605,609 ---- |
125 |
} |
126 |
|
127 |
! /* skipsubscript moved to subst.c to use private functions. 2009/02/24. */ |
128 |
|
129 |
/* This function is called with SUB pointing to just after the beginning |
130 |
*** ../bash-4.0/subst.c 2009-01-28 14:34:12.000000000 -0500 |
131 |
--- subst.c 2009-02-25 09:18:33.000000000 -0500 |
132 |
*************** |
133 |
*** 223,226 **** |
134 |
--- 223,227 ---- |
135 |
static char *extract_delimited_string __P((char *, int *, char *, char *, char *, int)); |
136 |
static char *extract_dollar_brace_string __P((char *, int *, int, int)); |
137 |
+ static int skip_matched_pair __P((const char *, int, int, int, int)); |
138 |
|
139 |
static char *pos_params __P((char *, int, int, int)); |
140 |
*************** |
141 |
*** 1375,1378 **** |
142 |
--- 1376,1480 ---- |
143 |
#define CQ_RETURN(x) do { no_longjmp_on_fatal_error = 0; return (x); } while (0) |
144 |
|
145 |
+ /* This function assumes s[i] == open; returns with s[ret] == close; used to |
146 |
+ parse array subscripts. FLAGS currently unused. */ |
147 |
+ static int |
148 |
+ skip_matched_pair (string, start, open, close, flags) |
149 |
+ const char *string; |
150 |
+ int start, open, close, flags; |
151 |
+ { |
152 |
+ int i, pass_next, backq, si, c, count; |
153 |
+ size_t slen; |
154 |
+ char *temp, *ss; |
155 |
+ DECLARE_MBSTATE; |
156 |
+ |
157 |
+ slen = strlen (string + start) + start; |
158 |
+ no_longjmp_on_fatal_error = 1; |
159 |
+ |
160 |
+ i = start + 1; /* skip over leading bracket */ |
161 |
+ count = 1; |
162 |
+ pass_next = backq = 0; |
163 |
+ ss = (char *)string; |
164 |
+ while (c = string[i]) |
165 |
+ { |
166 |
+ if (pass_next) |
167 |
+ { |
168 |
+ pass_next = 0; |
169 |
+ if (c == 0) |
170 |
+ CQ_RETURN(i); |
171 |
+ ADVANCE_CHAR (string, slen, i); |
172 |
+ continue; |
173 |
+ } |
174 |
+ else if (c == '\\') |
175 |
+ { |
176 |
+ pass_next = 1; |
177 |
+ i++; |
178 |
+ continue; |
179 |
+ } |
180 |
+ else if (backq) |
181 |
+ { |
182 |
+ if (c == '`') |
183 |
+ backq = 0; |
184 |
+ ADVANCE_CHAR (string, slen, i); |
185 |
+ continue; |
186 |
+ } |
187 |
+ else if (c == '`') |
188 |
+ { |
189 |
+ backq = 1; |
190 |
+ i++; |
191 |
+ continue; |
192 |
+ } |
193 |
+ else if (c == open) |
194 |
+ { |
195 |
+ count++; |
196 |
+ i++; |
197 |
+ continue; |
198 |
+ } |
199 |
+ else if (c == close) |
200 |
+ { |
201 |
+ count--; |
202 |
+ if (count == 0) |
203 |
+ break; |
204 |
+ i++; |
205 |
+ continue; |
206 |
+ } |
207 |
+ else if (c == '\'' || c == '"') |
208 |
+ { |
209 |
+ i = (c == '\'') ? skip_single_quoted (ss, slen, ++i) |
210 |
+ : skip_double_quoted (ss, slen, ++i); |
211 |
+ /* no increment, the skip functions increment past the closing quote. */ |
212 |
+ } |
213 |
+ else if (c == '$' && (string[i+1] == LPAREN || string[i+1] == LBRACE)) |
214 |
+ { |
215 |
+ si = i + 2; |
216 |
+ if (string[si] == '\0') |
217 |
+ CQ_RETURN(si); |
218 |
+ |
219 |
+ if (string[i+1] == LPAREN) |
220 |
+ temp = extract_delimited_string (ss, &si, "$(", "(", ")", SX_NOALLOC|SX_COMMAND); /* ) */ |
221 |
+ else |
222 |
+ temp = extract_dollar_brace_string (ss, &si, 0, SX_NOALLOC); |
223 |
+ i = si; |
224 |
+ if (string[i] == '\0') /* don't increment i past EOS in loop */ |
225 |
+ break; |
226 |
+ i++; |
227 |
+ continue; |
228 |
+ } |
229 |
+ else |
230 |
+ ADVANCE_CHAR (string, slen, i); |
231 |
+ } |
232 |
+ |
233 |
+ CQ_RETURN(i); |
234 |
+ } |
235 |
+ |
236 |
+ #if defined (ARRAY_VARS) |
237 |
+ int |
238 |
+ skipsubscript (string, start) |
239 |
+ const char *string; |
240 |
+ int start; |
241 |
+ { |
242 |
+ return (skip_matched_pair (string, start, '[', ']', 0)); |
243 |
+ } |
244 |
+ #endif |
245 |
+ |
246 |
/* Skip characters in STRING until we find a character in DELIMS, and return |
247 |
the index of that character. START is the index into string at which we |