Skip to content

Commit

Permalink
main: fix the workaround for "set -u"
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed May 28, 2021
1 parent afc4112 commit 76073a9
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 16 deletions.
13 changes: 7 additions & 6 deletions ble.pp
Expand Up @@ -290,6 +290,7 @@ function ble/base/restore-builtin-wrappers {
fi
} 2>/dev/null # set -x 対策

: "${_ble_bash_options_adjusted=}"
function ble/base/adjust-bash-options {
[[ $_ble_bash_options_adjusted ]] && return 1 || ((1)) # set -e 対策
_ble_bash_options_adjusted=1
Expand Down Expand Up @@ -483,7 +484,7 @@ function ble/base/read-blesh-arguments {
return 2 2>/dev/null || builtin exit 2
fi

if [[ $_ble_base ]]; then
if [[ ${_ble_base-} ]]; then
[[ $_ble_init_command ]] && _ble_init_attached=$_ble_attached
if ! ble/base/unload-for-reload; then
builtin echo "ble.sh: an old version of ble.sh seems to be already loaded." >&2
Expand Down Expand Up @@ -754,7 +755,7 @@ function ble/base/.create-user-directory {
##
function ble/base/initialize-base-directory {
local src=$1
local defaultDir=$2
local defaultDir=${2-}

# resolve symlink
if [[ -h $src ]] && type -t readlink &>/dev/null; then
Expand Down Expand Up @@ -854,7 +855,7 @@ function ble/base/clean-up-runtime-directory {
for file in "$_ble_base_run"/[1-9]*.*; do
[[ -e $file ]] || continue
pid=${file##*/}; pid=${pid%%.*}
[[ ${mark[pid]} ]] && continue
[[ ${mark[pid]+set} ]] && continue
mark[pid]=1
if ! builtin kill -0 "$pid" &>/dev/null; then
removed=("${removed[@]}" "$_ble_base_run/$pid."*)
Expand Down Expand Up @@ -1370,7 +1371,7 @@ function ble/base/attach-from-PROMPT_COMMAND {
# #D1354: 入れ子の ble/base/attach-from-PROMPT_COMMAND の時は一番
# 外側で ble-attach を実行する様にする。3>&2 2>/dev/null のリダ
# イレクトにより stdout.off の効果が巻き戻されるのを防ぐ為。
[[ $ble_base_attach_from_prompt_command != processing ]] || return
[[ ${ble_base_attach_from_prompt_command-} != processing ]] || return
fi

# 既に attach 状態の時は処理はスキップ
Expand Down Expand Up @@ -1434,9 +1435,9 @@ function ble/base/process-blesh-arguments {
blehook PRECMD+=ble/base/attach-from-PROMPT_COMMAND
fi
else
local q=\' Q="'\''"
local q=\' Q="'\''" prompt_command=${PROMPT_COMMAND-}
ble/function#lambda PROMPT_COMMAND \
"ble/base/attach-from-PROMPT_COMMAND '${PROMPT_COMMAND//$q/$Q}' \"\$FUNCNAME\""
"ble/base/attach-from-PROMPT_COMMAND '${prompt_command//$q/$Q}' \"\$FUNCNAME\""
if [[ $_ble_edit_detach_flag == reload ]]; then
_ble_edit_detach_flag=prompt-attach
blehook PRECMD+="$PROMPT_COMMAND"
Expand Down
1 change: 1 addition & 0 deletions memo/ChangeLog.md
Expand Up @@ -121,6 +121,7 @@
- main: fix the workaround for `set -e` `#D1564` ab2f70b
- util: work around bash-3.0 bug `"${scal[@]/xxx}"` `#D1570` 0000000
- sabbrev (`ble-sabbrev`): fix delayed output before the initialization `#D1573` 0000000
- main: fix the workaround for `set -u` `#D1575` 0000000

## Compatibility

Expand Down
10 changes: 10 additions & 0 deletions note.txt
Expand Up @@ -4655,6 +4655,16 @@ bash_tips

2021-05-28

* main: set -u で壊れていないか久しぶりに確認する必要がある気がする [#D1575]

試してみたら沢山のエラーが発生している。というか本来 set +u で待避している
筈なのに何故こんなに沢山のエラーが発生しているのだろうか。不思議である。
一通り attach する迄の部分を修正していったが実は必要なかった。

何故 set +u できていなかったのかというとそもそも adjust-bash-options 自体の
guard で未定義の変数を触っていた為に、adjust-bash-options が実行されていな
かったのが原因だった。それを直したら普通に動く様になった。

* main: expand_alias の設定を変えるのはやはり良くない [#D1574]

現在 ble.sh の内部では完全に alias を無効化しているが、そうすると blerc の
Expand Down
2 changes: 1 addition & 1 deletion src/benchmark.sh
Expand Up @@ -19,7 +19,7 @@ function ble-measure/.loop {
## 計測にかかった総時間を返します。
## @var[out] usec
## 1評価当たりの時間を返します。
if [[ $ZSH_VERSION ]]; then
if [[ ${ZSH_VERSION-} ]]; then
_ble_measure_resolution=1000 # [usec]
function ble-measure/.time {
local result
Expand Down
4 changes: 2 additions & 2 deletions src/color.sh
Expand Up @@ -24,7 +24,7 @@ function ble/color/define-options {
ncolor=88
fi
bleopt/declare -v term_true_colors semicolon
bleopt/declare -v term_index_colors "$bleopt_term_index_colors"
bleopt/declare -v term_index_colors "$ncolor"
}
ble/color/define-options

Expand Down Expand Up @@ -922,7 +922,7 @@ function ble/color/ansi2g {
# @hook color_init_setface (defined in src/def.sh)

# 遅延初期化
if [[ ! $_ble_faces_count ]]; then # reload #D0875
if [[ ! ${_ble_faces_count-} ]]; then # reload #D0875
_ble_faces_count=0
_ble_faces=()
fi
Expand Down
2 changes: 1 addition & 1 deletion src/decode.sh
Expand Up @@ -1452,7 +1452,7 @@ function ble/decode/keymap#unload {
done
}

if [[ $_ble_decode_kmaps ]]; then
if [[ ${_ble_decode_kmaps-} ]]; then
## @fn ble/decode/keymap/cleanup-old-keymaps
## 古い形式の keymap を削除する (#D1076)
## 0.4.0-devel1+e13e979 以前は unload 時に keymaps を削除していなかった為に、
Expand Down
2 changes: 1 addition & 1 deletion src/edit.sh
Expand Up @@ -8194,7 +8194,7 @@ if [[ $bleopt_internal_suppress_bash_output ]]; then
fi
fi

[[ $_ble_edit_detach_flag != reload ]] &&
[[ ${_ble_edit_detach_flag-} != reload ]] &&
_ble_edit_detach_flag=
function ble-edit/bind/.exit-TRAPRTMAX {
# シグナルハンドラの中では stty は bash によって設定されている。
Expand Down
11 changes: 6 additions & 5 deletions src/util.sh
Expand Up @@ -1426,7 +1426,7 @@ function ble/adict#keys {
if ((_ble_bash>=40000)); then
_ble_util_dict_declare='declare -A NAME'
function ble/dict#set { builtin eval -- "$1[x\$2]=\$3"; }
function ble/dict#get { builtin eval -- "ret=\${$1[x\$2]}; [[ \${$1[x\$2]+set} ]]"; }
function ble/dict#get { builtin eval -- "ret=\${$1[x\$2]-}; [[ \${$1[x\$2]+set} ]]"; }
function ble/dict#unset { builtin eval -- "builtin unset -v '$1[x\$2]'"; }
function ble/dict#has { builtin eval -- "[[ \${$1[x\$2]+set} ]]"; }
function ble/dict#clear { builtin eval -- "$1=()"; }
Expand Down Expand Up @@ -1905,7 +1905,7 @@ function ble/builtin/trap/.handler {
}

function ble/builtin/trap/install-hook {
local ret opts=:$2:
local ret opts=:${2-}:
ble/builtin/trap/.initialize
ble/builtin/trap/.get-sig-index "$1"
local sig=$ret name=${_ble_builtin_trap_signames[ret]}
Expand Down Expand Up @@ -2623,7 +2623,7 @@ function ble/function#push/call-top {
"ble/function#push/$((index-1)):$func" "$@"
}

[[ $_ble_util_lambda_count ]] || _ble_util_lambda_count=0
: "${_ble_util_lambda_count:=0}"
## @fn ble/function#lambda var body
## 無名関数を定義しその実際の名前を変数 var に格納します。
function ble/function#lambda {
Expand Down Expand Up @@ -3142,7 +3142,7 @@ function ble/util/msleep/calibrate {
## procsub
## 9< <(sleep) を使います。
function ble/util/msleep/.use-read-timeout {
local msleep_type=$1
local msleep_type=$1 opts=${2-}
_ble_util_msleep_fd=
case $msleep_type in
(socket)
Expand Down Expand Up @@ -3279,6 +3279,7 @@ function ble/util/msleep/.use-read-timeout {
return 0
}

_ble_util_msleep_builtin_available=
if ((_ble_bash>=40400)) && ble/util/msleep/.check-builtin-sleep; then
_ble_util_msleep_builtin_available=1
_ble_util_msleep_delay=300
Expand Down Expand Up @@ -4621,7 +4622,7 @@ if ((_ble_bash>=40000)); then
function ble/util/idle.push/.impl {
local base=$1 entry=$2
local i=$base
while [[ ${_ble_util_idle_task[i]} ]]; do ((i++)); done
while [[ ${_ble_util_idle_task[i]-} ]]; do ((i++)); done
_ble_util_idle_task[i]=$entry
}
function ble/util/idle.push {
Expand Down

0 comments on commit 76073a9

Please sign in to comment.