Debian Codegraph @

memo/D2092/adjust-bash-options.refactor.patch

raw
1 From 605ab7d6d6aab29402e046b80c64e735364a262c Mon Sep 17 00:00:00 2001
2 From: Koichi Murase <[email protected]>
3 Date: Sun, 10 Dec 2023 12:21:00 +0900
4 Subject: [PATCH 1/2] [reject] main: skip nested .adjust-bash-options
5
6 ---
7 ble.pp | 26 +++++++++++++++-----------
8 src/decode.sh | 5 +++--
9 src/edit.sh | 15 ++++++++-------
10 src/history.sh | 11 ++++++-----
11 src/util.hook.sh | 22 ++++++++++++----------
12 src/util.sh | 11 ++++++-----
13 6 files changed, 50 insertions(+), 40 deletions(-)
14
15 diff --git a/ble.pp b/ble.pp
16 index 028e64a1..89944cbf 100644
17 --- a/ble.pp
18 +++ b/ble.pp
19 @@ -475,12 +475,18 @@ function ble/base/xtrace/restore {
20 fi
21 }
22
23 +{
24 + _ble_bash_shopt=('' "$-" "${BASHOPTS-}")
25 + : "${_ble_bash_options_adjusted=}"
26 +} 2>/dev/null # set -x 対策
27 +
28 function ble/base/.adjust-bash-options {
29 - builtin eval -- "$1=\$-"
30 + ((_ble_bash_shopt++==0)) || return 0
31 + _ble_bash_shopt[1]=$-
32 set +evukT -B
33 ble/base/xtrace/adjust
34
35 - [[ $2 == shopt ]] || local shopt
36 + local shopt
37 if ((_ble_bash>=40100)); then
38 shopt=$BASHOPTS
39 else
40 @@ -489,7 +495,7 @@ function ble/base/.adjust-bash-options {
41 shopt -q extdebug 2>/dev/null && shopt=$shopt:extdebug
42 shopt -q nocasematch 2>/dev/null && shopt=$shopt:nocasematch
43 fi
44 - [[ $2 == shopt ]] || builtin eval -- "$2=\$shopt"
45 + _ble_bash_shopt[2]=$shopt
46 shopt -u extdebug
47 shopt -u nocasematch 2>/dev/null
48 return 0
49 @@ -497,7 +503,10 @@ function ble/base/.adjust-bash-options {
50 ## @fn ble/base/.restore-bash-options var_set var_shopt
51 ## @param[out] var_set var_shopt
52 function ble/base/.restore-bash-options {
53 - local set=${!1} shopt=${!2}
54 + ((--_ble_bash_shopt<=0)) || return 0
55 + _ble_bash_shopt=0
56 +
57 + local set=${_ble_bash_shopt[1]} shopt=${_ble_bash_shopt[2]}
58 [[ :$shopt: == *:nocasematch:* ]] && shopt -s nocasematch
59 [[ :$shopt: == *:extdebug:* ]] && shopt -s extdebug
60 ble/base/xtrace/restore
61 @@ -510,16 +519,11 @@ function ble/base/.restore-bash-options {
62 return 0
63 } 2>/dev/null # set -x 対策
64
65 -{
66 - : "${_ble_bash_options_adjusted=}"
67 - _ble_bash_set=$-
68 - _ble_bash_shopt=${BASHOPTS-}
69 -} 2>/dev/null # set -x 対策
70 function ble/base/adjust-bash-options {
71 [[ $_ble_bash_options_adjusted ]] && return 1 || ((1)) # set -e 対策
72 _ble_bash_options_adjusted=1
73
74 - ble/base/.adjust-bash-options _ble_bash_set _ble_bash_shopt
75 + ble/base/.adjust-bash-options
76
77 # Note: expand_aliases はユーザー設定を復元する為に記録する
78 _ble_bash_expand_aliases=
79 @@ -571,7 +575,7 @@ function ble/base/restore-bash-options {
80
81 [[ $_ble_bash_nocasematch ]] && shopt -s nocasematch
82
83 - ble/base/.restore-bash-options _ble_bash_set _ble_bash_shopt
84 + ble/base/.restore-bash-options
85 } 2>/dev/null # set -x 対策 #D0930 / locale 変更
86 function ble/base/recover-bash-options {
87 # bind -x が終わる度に設定が復元されてしまうので毎回設定し直す #D1526 #D1574
88 diff --git a/src/decode.sh b/src/decode.sh
89 index 821b7c61..5ba20cdc 100644
90 --- a/src/decode.sh
91 +++ b/src/decode.sh
92 @@ -4074,7 +4074,8 @@ function ble/builtin/bind/read-user-settings {
93 }
94
95 function ble/builtin/bind {
96 - local set shopt; ble/base/.adjust-bash-options set shopt
97 + local _ble_bash_shopt=$_ble_bash_shopt
98 + ble/base/.adjust-bash-options
99
100 [[ ! $_ble_attached || $_ble_edit_exec_inside_userspace ]] &&
101 ble/base/adjust-BASH_REMATCH
102 @@ -4092,7 +4093,7 @@ function ble/builtin/bind {
103
104 [[ ! $_ble_attached || $_ble_edit_exec_inside_userspace ]] &&
105 ble/base/restore-BASH_REMATCH
106 - ble/base/.restore-bash-options set shopt
107 + ble/base/.restore-bash-options
108 return "$ext"
109 }
110 function bind { ble/builtin/bind "$@"; }
111 diff --git a/src/edit.sh b/src/edit.sh
112 index 81297d4e..4bf4e12a 100644
113 --- a/src/edit.sh
114 +++ b/src/edit.sh
115 @@ -6138,13 +6138,14 @@ function ble/builtin/exit {
116 return "$?" # オプションの指定間違いなどで失敗する可能性がある。
117 fi
118
119 - local set shopt; ble/base/.adjust-bash-options set shopt
120 + local _ble_bash_shopt=$_ble_bash_shopt
121 + ble/base/.adjust-bash-options
122 local opt_flags=
123 local -a opt_args=()
124 ble/builtin/exit/.read-arguments "$@"
125 if [[ $opt_flags == *[EH]* ]]; then
126 [[ $opt_flags == *H* ]] && builtin exit --help
127 - ble/base/.restore-bash-options set shopt
128 + ble/base/.restore-bash-options
129 return 2
130 fi
131 ((${#opt_args[@]})) || ble/array#push opt_args "$ext"
132 @@ -6183,7 +6184,7 @@ function ble/builtin/exit {
133 case $ret in
134 ([yY]|[yY][eE][sS]) break ;;
135 ([nN]|[nN][oO]|'')
136 - ble/base/.restore-bash-options set shopt
137 + ble/base/.restore-bash-options
138 return 0 ;;
139 esac
140 done
141 @@ -6218,7 +6219,7 @@ function ble/builtin/exit {
142 TIMEFORMAT=
143 fi
144
145 - ble/base/.restore-bash-options set shopt
146 + ble/base/.restore-bash-options
147 _ble_builtin_exit_processing=1
148 ble/fd#alloc _ble_builtin_exit_stdout '>&1' # EXIT trap で stdin/stdout を復元する
149 ble/fd#alloc _ble_builtin_exit_stderr '>&2'
150 @@ -9984,8 +9985,8 @@ function ble/builtin/read {
151 return "$?"
152 fi
153
154 - local _ble_local_set _ble_local_shopt
155 - ble/base/.adjust-bash-options _ble_local_set _ble_local_shopt
156 + local _ble_bash_shopt=$_ble_bash_shopt
157 + ble/base/.adjust-bash-options
158
159 # used by core-complete to cancel progcomp
160 [[ $_ble_builtin_read_hook ]] &&
161 @@ -9996,7 +9997,7 @@ function ble/builtin/read {
162 ble/builtin/read/.impl "$@"; local __ble_ext=$?
163 [[ ! $_ble_attached || $_ble_edit_exec_inside_userspace ]] && ble/base/restore-BASH_REMATCH
164
165 - ble/base/.restore-bash-options _ble_local_set _ble_local_shopt
166 + ble/base/.restore-bash-options
167 [[ $__ble_command ]] || return "$__ble_ext"
168 # 局所変数により被覆されないように外側で評価
169 builtin eval -- "$__ble_command"
170 diff --git a/src/history.sh b/src/history.sh
171 index 825df0f8..ef9e3d93 100644
172 --- a/src/history.sh
173 +++ b/src/history.sh
174 @@ -1756,7 +1756,8 @@ function ble/builtin/history/option:s {
175 _ble_builtin_history_prevmax=$max
176 }
177 function ble/builtin/history {
178 - local set shopt; ble/base/.adjust-bash-options set shopt
179 + local _ble_bash_shopt=$_ble_bash_shopt
180 + ble/base/.adjust-bash-options
181 local opt_d= flag_error=
182 local opt_c= opt_p= opt_s=
183 local opt_a= flags=
184 @@ -1803,14 +1804,14 @@ function ble/builtin/history {
185 done
186 if [[ $flag_error ]]; then
187 builtin history --usage 2>&1 1>/dev/null | ble/bin/grep ^history >&2
188 - ble/base/.restore-bash-options set shopt
189 + ble/base/.restore-bash-options
190 return 2
191 fi
192
193 if [[ $flags == *h* ]]; then
194 builtin history --help
195 local ext=$?
196 - ble/base/.restore-bash-options set shopt
197 + ble/base/.restore-bash-options
198 return "$ext"
199 fi
200
201 @@ -1835,7 +1836,7 @@ function ble/builtin/history {
202 flag_processed=1
203 fi
204 if [[ $flag_processed ]]; then
205 - ble/base/.restore-bash-options set shopt
206 + ble/base/.restore-bash-options
207 return 0
208 fi
209
210 @@ -1848,7 +1849,7 @@ function ble/builtin/history {
211
212 [[ ! $_ble_attached || $_ble_edit_exec_inside_userspace ]] &&
213 ble/base/restore-BASH_REMATCH
214 - ble/base/.restore-bash-options set shopt
215 + ble/base/.restore-bash-options
216 return "$ext"
217 }
218 function history { ble/builtin/history "$@"; }
219 diff --git a/src/util.hook.sh b/src/util.hook.sh
220 index ebbc6fcc..2a7dc5b3 100644
221 --- a/src/util.hook.sh
222 +++ b/src/util.hook.sh
223 @@ -184,9 +184,9 @@ function blehook/.read-arguments {
224 }
225
226 function blehook {
227 - local set shopt
228 + local _ble_bash_shopt=$_ble_bash_shopt
229 ble/base/adjust-BASH_REMATCH
230 - ble/base/.adjust-bash-options set shopt
231 + ble/base/.adjust-bash-options
232
233 local flags print process
234 local rex1='^([_a-zA-Z@][_a-zA-Z0-9@]*)$'
235 @@ -199,7 +199,7 @@ function blehook {
236 blehook/.print-help
237 fi
238 [[ $flags != *E* ]]; local ext=$?
239 - ble/base/.restore-bash-options set shopt
240 + ble/base/.restore-bash-options
241 ble/base/restore-BASH_REMATCH
242 return "$ext"
243 fi
244 @@ -248,7 +248,7 @@ function blehook {
245 blehook/.print "${print[@]}"
246 fi
247
248 - ble/base/.restore-bash-options set shopt
249 + ble/base/.restore-bash-options
250 ble/base/restore-BASH_REMATCH
251 return "$ext"
252 }
253 @@ -611,17 +611,18 @@ function ble/builtin/trap/finalize {
254 done
255 }
256 function ble/builtin/trap {
257 - local set shopt; ble/base/.adjust-bash-options set shopt
258 + local _ble_bash_shopt=$_ble_bash_shopt
259 + ble/base/.adjust-bash-options
260 local flags command sigspecs
261 ble/builtin/trap/.read-arguments "$@"
262
263 if [[ $flags == *h* ]]; then
264 builtin trap --help
265 - ble/base/.restore-bash-options set shopt
266 + ble/base/.restore-bash-options
267 return 2
268 elif [[ $flags == *E* ]]; then
269 builtin trap --usage 2>&1 1>/dev/null | ble/bin/grep ^trap >&2
270 - ble/base/.restore-bash-options set shopt
271 + ble/base/.restore-bash-options
272 return 2
273 elif [[ $flags == *l* ]]; then
274 builtin trap -l
275 @@ -723,7 +724,7 @@ function ble/builtin/trap {
276
277 [[ ! $_ble_attached || $_ble_edit_exec_inside_userspace ]] &&
278 ble/base/restore-BASH_REMATCH
279 - ble/base/.restore-bash-options set shopt
280 + ble/base/.restore-bash-options
281 return 0
282 }
283 function trap { ble/builtin/trap "$@"; }
284 @@ -918,7 +919,8 @@ function ble/builtin/trap/.handler {
285 fi
286
287 # Adjust trap context
288 - local _ble_trap_set _ble_trap_shopt; ble/base/.adjust-bash-options _ble_trap_set _ble_trap_shopt
289 + local _ble_bash_shopt=$_ble_bash_shopt
290 + ble/base/.adjust-bash-options
291 local _ble_trap_name=${_ble_builtin_trap_sig_name[_ble_trap_sig]#SIG}
292 local -a _ble_trap_args; _ble_trap_args=("$@")
293 if [[ ! $_ble_trap_bash_command ]] || ((_ble_bash<30200)); then
294 @@ -1016,7 +1018,7 @@ function ble/builtin/trap/.handler {
295 ble/builtin/trap/user-handler#update:RETURN
296 fi
297
298 - ble/base/.restore-bash-options _ble_trap_set _ble_trap_shopt
299 + ble/base/.restore-bash-options
300 }
301
302 ## @fn ble/builtin/trap/install-hook sig [opts]
303 diff --git a/src/util.sh b/src/util.sh
304 index 2eca8d12..7b8c30c3 100644
305 --- a/src/util.sh
306 +++ b/src/util.sh
307 @@ -3549,7 +3549,8 @@ if ((_ble_bash>=40400)) && ble/util/msleep/.check-builtin-sleep; then
308 }
309
310 function ble/builtin/sleep {
311 - local set shopt; ble/base/.adjust-bash-options set shopt
312 + local _ble_bash_shopt=$_ble_bash_shopt
313 + ble/base/.adjust-bash-options
314 local frac_scale=100000000000000
315 local a=0 b=0 flags=
316 if (($#==0)); then
317 @@ -3595,7 +3596,7 @@ if ((_ble_bash>=40400)) && ble/util/msleep/.check-builtin-sleep; then
318 builtin sleep "$a.$b"
319 fi
320 local ext=$?
321 - ble/base/.restore-bash-options set shopt 1
322 + ble/base/.restore-bash-options
323 return "$ext"
324 }
325 function sleep { ble/builtin/sleep "$@"; }
326 @@ -7182,8 +7183,8 @@ function ble/builtin/readonly/.print-warning {
327 return 0
328 }
329 function ble/builtin/readonly {
330 - local _ble_local_set _ble_local_shopt
331 - ble/base/.adjust-bash-options _ble_local_set _ble_local_shopt
332 + local _ble_bash_shopt=$_ble_bash_shopt
333 + ble/base/.adjust-bash-options
334
335 local _ble_local_flags=
336 local -a _ble_local_options=()
337 @@ -7219,7 +7220,7 @@ function ble/builtin/readonly {
338 builtin readonly "${_ble_local_options[@]}"
339 _ble_local_ext=$?
340 fi
341 - ble/base/.restore-bash-options _ble_local_set _ble_local_shopt
342 + ble/base/.restore-bash-options
343 return "$?"
344 }
345
346 --
347 2.41.0
348