Skip to content

Commit d4c812b

Browse files
committed
canvas: work around Bash <= 4.1 for arithmetic recursion (fixup d56c7d2)
1 parent d56c7d2 commit d4c812b

File tree

5 files changed

+31
-12
lines changed

5 files changed

+31
-12
lines changed

docs/ChangeLog.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
- make: save commit id and branch name with `git archive` (requested by LecrisUT, blackteahamburger) `#D2290` 31f264ad
106106
- edit: revert edits with widget `discard-line` (reported by dezza) `#D2301` 3b2b4b81
107107
- vi_nmap: fix cursor position after <kbd>C-o</kbd> `#D2302` c106239a
108-
- decode (`ble-bind`): initialize specified keymaps (motivated by quantumfrost) `#D2324` xxxxxxxx
108+
- decode (`ble-bind`): initialize specified keymaps (motivated by quantumfrost) `#D2324` 66e450d7
109109

110110
## Fixes
111111

@@ -231,7 +231,7 @@
231231
- histdb: support `top`, `stats`, `calendar`, and `week` `#D2167` 4d7dd1ee
232232
- histdb: unify the color palette selection `#D2167` 4d7dd1ee
233233
- histdb: fix the seasonal default palette names `#D2289` 4fee44e6
234-
- histdb: fix the error with missing current working directory `#D2323` xxxxxxxx
234+
- histdb: fix the error with missing current working directory `#D2323` 98985f38
235235
- contrib/fzf-git: update to be consistent with the upstream (motivated by arnoldmashava) `#D2054` c78e5c9f
236236
- contrib/layer/pattern: add `{pattern}` layer `#D2074` 449d92ca
237237
- contrib/fzf-git: fix unsupported command modes (reported by dgudim) `#D2083` ba2b8865
@@ -316,7 +316,7 @@
316316
- global: avoid raw word splitting `#D2309` b55c4003
317317
- global: use `ble/util/assign` in more places `#D2312` b0e39732
318318
- main: show details of the loading time (motivated by tessus, Darukutsu) `#D2313` 3d8f6264
319-
- canvas: optimize binary search in tables `#D2325` xxxxxxxx
319+
- canvas: optimize binary search in tables `#D2325` d56c7d2f xxxxxxxx
320320

321321
<!---------------------------------------------------------------------------->
322322
# ble-0.4.0-devel3

lib/test-bash.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
ble-import lib/core-test
44

5-
ble/test/start-section 'bash' 69
5+
ble/test/start-section 'bash' 72
66

77
# case $word を quote する必要がある条件は?
88

@@ -51,6 +51,22 @@ ble/test/start-section 'bash' 69
5151
ble/test 'read -r ret <<< $b' ret="/*"
5252
)
5353

54+
# Arithmetic bugs
55+
(
56+
# BUG bash 3.0..4.1
57+
# && の遅延評価が働かない。従って愚直な条件付き算術式再帰はできない。
58+
L='0&&L'
59+
if ((40200<=_ble_bash)); then
60+
ble/test '((L,1))'
61+
else
62+
ble/test '! ((L,1))'
63+
fi
64+
65+
i=0 M='i++,M[i>=10]'
66+
ble/test '((M,1))'
67+
ble/test code:'ret=$i' ret=10
68+
)
69+
5470
# Variable bugs
5571
(
5672
# BUG bash-3.1

note.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7774,9 +7774,12 @@ bash_tips
77747774
ん、bash の内部実装的に sparse だとかどうだとかは関係ない気がする。やはり単
77757775
に遅いということだろう。
77767776

7777-
二分探索の while を再帰算術式に変えた方が速度が向上する。51 -> 45 という微
7778-
妙な向上だが折角分かったことなので実装に適用する事にする
7777+
二分探索の while を再帰算術式に変えた方が速度が向上する。51us -> 45us とい
7778+
う微妙な向上だが折角分かったことなので実装に適用する事にする
77797779

7780+
2025-03-21 bash <= 4.1 以下で無限再帰になってクラッシュするという事が分かっ
7781+
てしまった。bash <= 4.1 では遅延評価になっていないのだった。workaround とし
7782+
て再帰変数を配列要素として参照して、添字に条件を指定することにした。
77807783

77817784
* decode (ble-bind): initialize specified keymaps (motivated by quantumfrost) [#D2324]
77827785
https://github.com/akinomyoga/ble.sh/issues/561

src/canvas.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ function ble/unicode/c2w {
188188
ret=${_ble_unicode_c2w_index[c<0x20000?c>>8:((c>>12)-32+512)]}
189189
if [[ $ret == *:* ]]; then
190190
local l=${ret%:*} u=${ret#*:} m
191-
local L='_ble_unicode_c2w_ranges[m=(l+u)/2]<=c?(l=m):(u=m),l+1<u&&L'
191+
local L='_ble_unicode_c2w_ranges[m=(l+u)/2]<=c?(l=m):(u=m),L[l+1>=u]'
192192
((l+1<u&&L))
193193
ret=${_ble_unicode_c2w[_ble_unicode_c2w_ranges[l]]}
194194
fi
@@ -260,7 +260,7 @@ function ble/unicode/EmojiStatus {
260260
ret=$_ble_unicode_EmojiStatus_None
261261
if ((_ble_unicode_EmojiStatus_xmaybe)); then
262262
local l=0 u=${#_ble_unicode_EmojiStatus_ranges[@]} m
263-
local L='_ble_unicode_EmojiStatus_ranges[m=(l+u)/2]<=code?(l=m):(u=m),l+1<u&&L'
263+
local L='_ble_unicode_EmojiStatus_ranges[m=(l+u)/2]<=code?(l=m):(u=m),L[l+1>=u]'
264264
((l+1<u&&L))
265265
ret=${_ble_unicode_EmojiStatus[_ble_unicode_EmojiStatus_ranges[l]]:-0}
266266
fi
@@ -373,7 +373,7 @@ function ble/util/c2w:emacs {
373373
fi
374374

375375
local l=0 u=${#_ble_util_c2w_emacs_wranges[@]} m
376-
local L='_ble_util_c2w_emacs_wranges[m=(l+u)/2]<=tIndex?(l=m):(u=m),l+1<u&&L'
376+
local L='_ble_util_c2w_emacs_wranges[m=(l+u)/2]<=tIndex?(l=m):(u=m),L[l+1>=u]'
377377
((l+1<u&&L))
378378
((ret=((l&1)==0)?2:1))
379379
return 0
@@ -393,7 +393,7 @@ function ble/util/c2w:musl {
393393
fi
394394

395395
local l=0 u=${#_ble_util_c2w_musl_ranges[@]} m
396-
local L='_ble_util_c2w_musl_ranges[m=(l+u)/2]<=code?(l=m):(u=m),l+1<u&&L'
396+
local L='_ble_util_c2w_musl_ranges[m=(l+u)/2]<=code?(l=m):(u=m),L[l+1>=u]'
397397
((l+1<u&&L))
398398
ret=${_ble_util_c2w_musl[_ble_util_c2w_musl_ranges[l]]}
399399
}
@@ -585,7 +585,7 @@ function ble/unicode/GraphemeCluster/c2break {
585585
((ret>_ble_unicode_GraphemeClusterBreak_MaxCode)) && { ret=0; return 0; }
586586

587587
local l=0 u=${#_ble_unicode_GraphemeClusterBreak_ranges[@]} m
588-
local L='_ble_unicode_GraphemeClusterBreak_ranges[m=(l+u)/2]<=code?(l=m):(u=m),l+1<u&&L'
588+
local L='_ble_unicode_GraphemeClusterBreak_ranges[m=(l+u)/2]<=code?(l=m):(u=m),L[l+1>=u]'
589589
((l+1<u&&L))
590590

591591
ret=${_ble_unicode_GraphemeClusterBreak[_ble_unicode_GraphemeClusterBreak_ranges[l]]:-0}

src/color.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2034,7 +2034,7 @@ function ble/highlight/layer:{selection}/getg {
20342034
# When there are multiple selections, we identify the position of `index`
20352035
# using bisection.
20362036
local l=0 u=$((olen-1)) m
2037-
local L='osel[m=(l+u)/2]<=index?(l=m):(u=m),l+1<u&&L'
2037+
local L='osel[m=(l+u)/2]<=index?(l=m):(u=m),L[l+1>=u]'
20382038
((l+1<u&&L))
20392039

20402040
# When `l` sits at the end of a selection, check if the next selection

0 commit comments

Comments
 (0)