Skip to content

Commit

Permalink
decode: fix the workaround for "set -e" with "--prompt=attach"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Jul 7, 2022
1 parent 5ef28eb commit 5111323
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Expand Up @@ -219,6 +219,7 @@
- main: fix the workaround for `set -e` `#D1564` ab2f70b
- main: fix the workaround for `set -u` `#D1575` 76073a9
- main: fix the workaround for `set -eu` and refactor `#D1743` 6a946f0
- decode: fix the workaround for `set -e` with `--prompt=attach` `#D1832` XXXXXXX
- util: work around bash-3.0 bug `"${scal[@]/xxx}"` `#D1570` 24f79da
- sabbrev (`ble-sabbrev`): fix delayed output before the initialization `#D1573` 5d85238
- history: fix the workaround for bash-3.0 bug of reducing histories `#D1576` 15c9133
Expand Down
33 changes: 33 additions & 0 deletions note.txt
Expand Up @@ -6453,6 +6453,39 @@ bash_tips
Done (実装ログ)
-------------------------------------------------------------------------------

2022-07-06

* main, decode: ble-attach & set -e [#D1832]

bash -e で開始した時は寧ろ --attach=prompt でないと駄目な事が分かった。
ble-0.3 及び ble-0.4 で再現した。--attach=prompt を指定していても bashrc 内
部で手動で ble-attach すると失敗する。

うーん。これは ble/decode/.hook で set +e したら回避できるだろうか→どうや
ら回避できる様だ。-e も勝手に無効にはなっていない。

x これは文法エラー等によって状態回復に失敗した時に次の ble-decode/.hook の
呼び出しの時に set -e が消滅する原因になり得るが、その様な事は余り起こら
ないし起こったとしてもそもそも対話セッションで set -e を設定する事の方が
変だから基に思案くても良い?

a 或いは attach した直後だけは set +e を実行する様に変更する? 然し、
attach した直後かどうかを判定するのにまた処理時間を食う気がするし、微妙
な気がする。

b 或いは別の hook に登録するという可能性もある。

c 周りのコードを見渡してみたら既に set +v をしている部分がある。#D0930 が
対応する項目である。確認してみたら今回の -e と同様の事が書かれている。
うーん。前回のコマンドで解除に失敗した時にどうなるのかは非自明だが取り
敢えずここに set -e を追加しておけば良い気がする。

前回のコマンドで解除に失敗した時にはそもそもその場で errexit して終了し
てしまう筈なので、再び .hook が呼び出される事もない気がするので気にしな
くて良い気がする。

取り敢えず c の方針を使う様に修正した。改めてちゃんと動くか確認する→OK

2022-07-05

* bash: history timestamp に問題がある時に history の初期化が正しくない [#D1831]
Expand Down
11 changes: 9 additions & 2 deletions src/decode.sh
Expand Up @@ -645,9 +645,14 @@ function ble-decode/.hook {

local buflen=${#_ble_decode_input_buffer[@]}
if ((buflen%257==0&&buflen>=2000)); then
# その場で標準入力を読み切る
[[ ! $_ble_bash_options_adjusted ]] || set +ev

local IFS=$_ble_term_IFS
local _ble_decode_hook_Processing=prologue
ble-decode/PROLOGUE
_ble_decode_hook_Processing=body

# その場で標準入力を読み切る
local char=${_ble_decode_input_buffer[buflen-1]}
if ((_ble_bash<40000||char==0xC0||char==0xDF)); then
# Note: これらの文字は bind -s マクロの非終端文字。
Expand All @@ -662,7 +667,9 @@ function ble-decode/.hook {
ble/array#push _ble_decode_input_buffer "${ret[@]}"
done
fi
_ble_decode_hook_Processing=epilogue
ble-decode/EPILOGUE
ble/util/unlocal _ble_decode_hook_Processing

ble/array#pop _ble_decode_input_buffer
ble-decode/.hook "$ret"
Expand All @@ -673,7 +680,7 @@ function ble-decode/.hook {

# Note: bind -x 内の set +v は揮発性なのでできるだけ先頭で set +v しておく。
# (PROLOGUE 内から呼ばれる) stdout.on より前であれば大丈夫 #D0930
[[ $_ble_bash_options_adjusted ]] && set +v || :
[[ ! $_ble_bash_options_adjusted ]] || set +ev

local IFS=$_ble_term_IFS
local _ble_decode_hook_Processing=prologue
Expand Down

0 comments on commit 5111323

Please sign in to comment.