Skip to content

Commit

Permalink
global: fix leakvar "ret" and apply 0.3 backports
Browse files Browse the repository at this point in the history
* edit: fix leak variable "ret" in "ble-edit/exec/print-PS0"
* keymap/emacs: fix leak variable "ret" in "ble/widget/emacs/__after_widget__"
* complete: fix leak variable "ret" in "ble/complete/sabbrev/expand"
* util.bgproc: fix leak variable "ret" in "ble/util/bgproc#keepalive"
* util (ble/util/clock/.initialize): explicitly specify -1 to '%()T' for bash-4.2
* main: work around for "set -u" for undefined "USER", "HOSTNAME", and "LANG"
  • Loading branch information
akinomyoga committed Mar 12, 2023
1 parent 7803305 commit 6f5604d
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 9 deletions.
6 changes: 3 additions & 3 deletions ble.pp
Expand Up @@ -1045,7 +1045,7 @@ function ble/init/check-environment {
ble/util/print "ble.sh: modified PATH=${PATH::${#PATH}-${#original_path}}\$PATH" >&2
fi

if [[ ! $USER ]]; then
if [[ ! ${USER-} ]]; then
ble/util/print "ble.sh: insane environment: \$USER is empty." >&2
if USER=$(id -un 2>/dev/null) && [[ $USER ]]; then
export USER
Expand All @@ -1054,7 +1054,7 @@ function ble/init/check-environment {
fi
_ble_base_env_USER=$USER

if [[ ! $HOSTNAME ]]; then
if [[ ! ${HOSTNAME-} ]]; then
ble/util/print "ble.sh: suspicious environment: \$HOSTNAME is empty."
if HOSTNAME=$(uname -n 2>/dev/null) && [[ $HOSTNAME ]]; then
export HOSTNAME
Expand All @@ -1063,7 +1063,7 @@ function ble/init/check-environment {
fi
_ble_base_env_HOSTNAME=$HOSTNAME

if [[ ! $LANG ]]; then
if [[ ! ${LANG-} ]]; then
ble/util/print "ble.sh: suspicious environment: \$LANG is empty." >&2
fi

Expand Down
3 changes: 2 additions & 1 deletion docs/ChangeLog.md
Expand Up @@ -139,7 +139,7 @@
- sabbrev: add widget `magic-slash` to approximate Zsh named directories (motivated by mozirilla213) `#D2008` e6b9581c
- sabbrev: support inline and linewise sabbre with `ble-sabbrev -il` `#D2012` 56208534
- complete: add `bleopt complete_source_sabbrev_{opts,ignore}` (motivated by mozirilla213) `#D2013` f95eb0cc `#D2016` 45c76746
- util.bgproc: separate `ble/util/bgproc` from `histdb` (motivated by bkerin) `#D2017` xxxxxxxx
- util.bgproc: separate `ble/util/bgproc` from `histdb` (motivated by bkerin) `#D2017` 7803305f

## Changes

Expand Down Expand Up @@ -577,6 +577,7 @@
- global: avoid directly using `/dev/tty` `#D1986` a835b83
- util: add `ble/util/message` `#D2001` 2a524f34
- global: normalize bracket expressions to `_a-zA-Z` / `_a-zA-Z0-9` `#D2006` 41faa494
- global: fix leak variables `#D2018` xxxxxxxx

## Contrib

Expand Down
2 changes: 1 addition & 1 deletion keymap/emacs.sh
Expand Up @@ -123,7 +123,7 @@ function ble/keymap:emacs/update-mode-indicator {
local version=$COLUMNS,$_ble_edit_lineno,$_ble_history_count,$_ble_edit_CMD
local prompt_hashref_base='$version'
ble/prompt/unit#update _ble_keymap_emacs_mode_indicator
ble/prompt/unit:{section}/get _ble_keymap_emacs_mode_indicator; local str=$ret
local ret; ble/prompt/unit:{section}/get _ble_keymap_emacs_mode_indicator; local str=$ret

[[ $_ble_edit_arg ]] &&
str=${str:+"$str "}$'(arg: \e[1;34m'$_ble_edit_arg$'\e[m)'
Expand Down
1 change: 1 addition & 0 deletions lib/core-complete.sh
Expand Up @@ -8616,6 +8616,7 @@ function ble/complete/sabbrev/expand {
opts=$opts:wordwise:literal

local -a patterns=()
local ret
ble/opts#extract-all-optargs "$opts" pattern &&
patterns=("${ret[@]}")

Expand Down
4 changes: 3 additions & 1 deletion lib/core-debug.sh
Expand Up @@ -34,11 +34,13 @@ function ble/debug/leakvar#reset {
builtin eval "$1=__t1wJltaP9nmow__"
}
function ble/debug/leakvar#check {
if [[ ${!1} != __t1wJltaP9nmow__ ]]; then
local ext=$?
if [[ ${!1} != __t1wJltaP9nmow__ ]] && ble/variable#is-global "$1"; then
local IFS=$_ble_term_IFS
ble/util/print "$1=${!1}:${*:2} [${FUNCNAME[*]:1:5}]" >> ~/a.txt # DEBUG_LEAKVAR
builtin eval "$1=__t1wJltaP9nmow__"
fi
return "$?"
}
function ble/debug/leakvar#list {
local _ble_local_exclude_file=${_ble_base_repository:-$_ble_base}/make/debug.leakvar.exclude-list.txt
Expand Down
1 change: 1 addition & 0 deletions lib/util.bgproc.sh
Expand Up @@ -376,6 +376,7 @@ function ble/util/bgproc#keepalive {

local timeout_proc="ble/util/bgproc#keepalive/.timeout $1"
ble/util/idle.cancel "$timeout_proc"
local ret
ble/opts#extract-last-optarg "${bgproc[3]}" timeout || return 0; local bgproc_timeout=$ret
if ((bgproc_timeout>0)); then
ble/util/idle.push --sleep="$bgproc_timeout" "$timeout_proc"
Expand Down
111 changes: 111 additions & 0 deletions note.txt
Expand Up @@ -1991,6 +1991,103 @@ bash_tips
- keymap の移動 (これは別 commit にする?)
- make_command.sh の整理 (scan 分離, char_width 分離)

2023-03-09

* sabbrev: suffix alias in Zsh (拡張子で実行形式を選択)
コマンド名補間も一緒に対応する必要がある。

* complete: 末尾に不完全な \ がある候補の specialchars フィルタリング?

最後に中途半端な \ がある時には実はフィルターする時にも \ で quote する必要
性のある文字が続いている物だけにするべきなのではないか。と思ったが処理的に
複雑になるのではないか? 取り敢えず末端に中途半端な \ があるかどうかは
comps_flags に B が含まれているかどうかで分かる。

その上でその事実を用いて生成するファイル名を制限するかどうかというのが問題。
然しその制限を適用する事によって候補がなくなってしまっては変な気もする。

a 全ての候補を生成してから、生成候補を制限しても候補が残るようであれば制限
をかける事にしようと思ったがそうしたとしても異なる種類の候補が混ざってい
る時に不用意にフィルタできない。例えば sabbrev 候補は絞り込みの為に cand
には quote を処理した後の値を入れている。

b と思ったが quote の必要のない候補ばかりの時には生成候補がなくなっても良い
気がしてきた。

そうは言っても問題になるのが bash-completion によって生成される候補を制限す
るかしないかという事。実際に生成している側でないとその意図は分からない。

2023-03-08

* :name: に対して emoji 変換を実装する?

https://www.webfx.com/tools/emoji-cheat-sheet/ に一覧がある。
然し、emoji リストの難点は思い出すのが大変という事。リストを表示できたら良いのだが。
例えば sabbrev -m 経由で挿入するというのが良いかもしれない。

* [保留] canvas/panel: 一旦 scroll buffer に行ったものを元に戻す可能性? (motivated by mozirilla213)

https://github.com/akinomyoga/ble.sh/discussions/288#discussioncomment-5226973
> (And the completion words fill and cut the previous output when scrolling
> up the terminal which I think is a known limitation which is fine,

panel の set-height で行が消えてなくなる? うーん。然し報告者の使っているら
しき konsole では特に内容が失われるということはない様である。ちゃんと
scroll buffer に内容が残っている。

恐らく scroll buffer に行って一旦画面から見えなくなるという事を言っているの
だろう。或いは、一旦 scroll buffer に行った物を、menu が閉じた後にある程度
回復するという事。端末によっては何かそういう様な拡張をしていた様な気がする
のでそれを有効にする可能性はある。

2023-03-06

* menu-complete: 番号で選択する
https://github.com/akinomyoga/ble.sh/discussions/284

これは実は実装はそんなに大変ではない気がする。

LASTWIDGET のチェックは必要? 否、他のものは全て抜けるから関係ない? と思っ
たが TAB や cursor key 等の移動コマンドの後も番号はリセットしたい。なのでや
はり LASTWIDGET はチェックする。番号が溜まって一致する物がなくなったら一つ
ずつ古い文字を削除して一致するものが出るまで削る。一つも一致しなかったら削
る前にリセットして新しい文字自体をなかった事にする?

2023-03-02

* menu-complete: C-TAB を連続で押すと仮挿入をそのままに新しい補完が始まる

menu-complete の外側の keymap で menu-complete が設定されている時には単に
menu_complete/forward にしたりなどした方が良いのではないか。

と思ったが menu_complete に対して引数が指定されている時などにどのように対処
するべきかわからない。例えば insert_all や insert_brances や context=* が指
定されている場合には単に移動するのではなくて今の補完を明示的にキャンセルし
て新しく補完し直すべきなのではないか。然し、単なる complete や
menu-completion や menu-complete backward 等の時には改めて開始するのではな
くて内部での補完候補の移動を行いたい気もする。

* menu-complete: suffix もメニュー選択時に表示する機能?
https://github.com/akinomyoga/ble.sh/discussions/297#discussioncomment-5159146

然しこれは最後の確定時にならないと計算されない。メニューを選択した時にそれ
も計算する? 然しそうするとしてもrequote だとか前方の文字列の吸収だとかその
他の処理についてはどうするのか。

特に前方の文字列の吸収に関しては実際に実行してしまうと元々の内容が消滅して
しまうので駄目である。或いは前方の文字列に一致する物がある場合には単に挿入
部分の方を短くすれば良いのかもしれないが、それはそれで着色範囲が変になって
しまって見にくい。更に前方に完全に一致する場合には挿入文字列の幅が 0 になっ
てしまって見えなくなる。また確定した時に何処にカーソルが移動するのかという
のも分かりにくい。

* wiki: Design Widget の翻訳?
https://github.com/akinomyoga/ble.sh/discussions/272#discussioncomment-5013253
https://github.com/akinomyoga/ble.sh/discussions/294
https://github.com/akinomyoga/ble.sh/discussions/301

何やら色々変な事を試そうとしている人がいるみたいなので。

2023-03-01

* [保留] decode: M-S-o と M-O のどちらか一方でに強制的に揃える?
Expand Down Expand Up @@ -6635,6 +6732,20 @@ bash_tips

2023-03-12

* ret が leak する様になっている [#D2018]

だいぶ遡ってもずっと leak している。何故だろうか。取り敢えず最新版で修正した。

* ble/util/bgproc#keepalive がリークしていた
* ble/complete/sabbrev/expand もリークしていた

→ずっと遡っても発生している ret の上書きはどうも ble.sh --norc で発生して
いる? 調べてみると任意のキー入力の後で低確率で発生している様に見える。或い
は auto-complete が関係しているのだろうか。

* 結局 emacs keymap の __after_widget__ に問題があった。
* 更に類似の呼び出しで PS0 についても ret の leak があった。両方とも直した。

* bgproc: histdb から切り離して再利用可能にする (motivated by bkerin) [#D2017]
https://lists.gnu.org/archive/html/help-bash/2023-03/msg00068.html
https://github.com/akinomyoga/ble.sh/issues/302#issuecomment-1462977627
Expand Down
30 changes: 30 additions & 0 deletions src/decode.sh
Expand Up @@ -2167,7 +2167,13 @@ function ble-decode/widget/.invoke-hook {
local dicthead=_ble_decode_${_ble_decode_keymap}_kmap_
builtin eval "local hook=\${$dicthead[key]-}"
hook=${hook:2}
#%if leakvar
ble/debug/leakvar#check $"leakvar" "widget.hook.0"
#%end.i
[[ $hook ]] && builtin eval -- "$hook"
#%if leakvar
ble/debug/leakvar#check $"leakvar" "widget.hook.1 $hook"
#%end.i
}

## @fn ble-decode/widget/.call-keyseq
Expand Down Expand Up @@ -2211,7 +2217,13 @@ function ble-decode/widget/.call-keyseq {
_ble_decode_key__seq=

ble-decode/widget/.invoke-hook "$_ble_decode_KCODE_BEFORE_WIDGET"
#%if leakvar
ble/debug/leakvar#check $"leakvar" widget.0
#%end.i
builtin eval -- "$WIDGET"; local ext=$?
#%if leakvar
ble/debug/leakvar#check $"leakvar" "widget $WIDGET"
#%end.i
ble-decode/widget/.invoke-hook "$_ble_decode_KCODE_AFTER_WIDGET"
((_ble_decode_keylog_depth==1)) &&
_ble_decode_keylog_chars_count=0 _ble_decode_keylog_keys_count=0
Expand Down Expand Up @@ -2242,22 +2254,40 @@ function ble/decode/widget/call-interactively {
local -a KEYS; KEYS=("${@:2}")
_ble_decode_widget_last=$WIDGET
ble-decode/widget/.invoke-hook "$_ble_decode_KCODE_BEFORE_WIDGET"
#%if leakvar
ble/debug/leakvar#check $"leakvar" widget.0
#%end.i
builtin eval -- "$WIDGET"; local ext=$?
#%if leakvar
ble/debug/leakvar#check $"leakvar" "widget $WIDGET"
#%end.i
ble-decode/widget/.invoke-hook "$_ble_decode_KCODE_AFTER_WIDGET"
return "$ext"
}
function ble/decode/widget/call {
local WIDGET=$1 KEYMAP=$_ble_decode_keymap LASTWIDGET=$_ble_decode_widget_last
local -a KEYS; KEYS=("${@:2}")
_ble_decode_widget_last=$WIDGET
#%if leakvar
ble/debug/leakvar#check $"leakvar" widget.0
#%end.i
builtin eval -- "$WIDGET"
#%if leakvar
ble/debug/leakvar#check $"leakvar" "widget $WIDGET"
#%end.i
}
## @fn ble/decode/widget/dispatch widget args...
function ble/decode/widget/dispatch {
local ret; ble/string#quote-command "ble/widget/$@"
local WIDGET=$ret
_ble_decode_widget_last=$WIDGET
#%if leakvar
ble/debug/leakvar#check $"leakvar" widget.0
#%end.i
builtin eval -- "$WIDGET"
#%if leakvar
ble/debug/leakvar#check $"leakvar" "widget $WIDGET"
#%end.i
}
## @fn ble/decode/widget/suppress-widget
## __before_widget__ に登録された関数から呼び出します。
Expand Down
8 changes: 7 additions & 1 deletion src/edit.sh
Expand Up @@ -5911,7 +5911,7 @@ function ble-edit/exec/print-PS0 {
local prompt_cols=${COLUMNS:-80}
local "${_ble_prompt_cache_vars[@]/%/=}" # WA #D1570 checked
ble/prompt/unit#update _ble_prompt_ps10
ble/prompt/unit:{section}/get _ble_prompt_ps10
local ret; ble/prompt/unit:{section}/get _ble_prompt_ps10
ble/util/put "$ret"
fi
}
Expand Down Expand Up @@ -10264,9 +10264,15 @@ function ble-edit/bind/.tail-without-draw {

if ((_ble_bash>=40000)); then
function ble-edit/bind/.tail {
#%if leakvar
ble/debug/leakvar#check $"leakvar" tail.beg
#%end.i
ble/application/render
ble/util/idle.do
ble/textarea#adjust-for-bash-bind # bash-4.0+
#%if leakvar
ble/debug/leakvar#check $"leakvar" tail.end
#%end.i
ble-edit/bind/stdout.off
}
else
Expand Down
4 changes: 2 additions & 2 deletions src/util.sh
Expand Up @@ -4822,11 +4822,11 @@ function ble/util/clock/.initialize {
((ret=integral*1000+10#0$fraction))
}
elif ((_ble_bash>=40200)); then
printf -v _ble_util_clock_base '%(%s)T'
printf -v _ble_util_clock_base '%(%s)T' -1
_ble_util_clock_reso=1000
_ble_util_clock_type=printf
function ble/util/clock {
local now; printf -v now '%(%s)T'
local now; printf -v now '%(%s)T' -1
((ret=(now-_ble_util_clock_base)*1000))
}
elif [[ $SECONDS && ! ${SECONDS//[0-9]} ]]; then
Expand Down

0 comments on commit 6f5604d

Please sign in to comment.