Skip to content

Commit 8e9c60d

Browse files
author
Andy Chu
committed
[demo] Repro of bug #858.
I guess this is about when the main loop runs signal handlers. Unrelated: doc edits.
1 parent 481562f commit 8e9c60d

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

demo/bug-858-trap.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
action() {
2+
echo "from signal"
3+
}
4+
5+
trap "action" USR1
6+
7+
echo "Run: kill -USR1 $$; date"
8+
while true; do
9+
date
10+
sleep 10 &
11+
wait $!
12+
done

doc/variable-scope.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ Also see [Oil Keywords](oil-keywords.html).
1818

1919
This doc is filled with details, so it will help to keep these goals in mind:
2020

21+
- Code written in Oil style (with `proc`) is easier to read/audit than code
22+
written in shell style.
23+
- in shell, functions can pollute the caller's stack, because of the dynamic
24+
scope rule.
2125
- Remove dynamic scope. This mechanism is unfamiliar to most programmers, and
2226
may result in mutating variables where you don't expect it.
2327
- Instead of using dynamic scope by default, Oil lets you choose it
@@ -59,7 +63,12 @@ Don't use the old style of `local`, `readonly`, `x=y`.
5963

6064
This covers 95%+ of shell programming.
6165

62-
### `shopt --unset dynamic_scope` in `bin/oil`
66+
### When Dynamic Scope Is Off
67+
68+
`shopt --unset dynamic_scope`
69+
70+
- it's off when calling a `proc`.
71+
- it's off in `bin/oil`
6372

6473
This option affects how nearly **every** shell assignment construct behaves. There are a lot of them!
6574

@@ -136,8 +145,11 @@ The other ones deal with values. These deal with cells. These also change to
136145
- `declare -p` to print variables
137146
- `${x@a}` to print flags
138147
- `pp .cell`
148+
139149
- weird `TZ` test in `printf`. I think this could just look in the
140150
environment itself? Do `getenv()`?
151+
- yeah I think this is a separate case
152+
- I think it should just look for a GLOBAL honestly
141153

142154

143155
### `Dynamic` → `LocalOnly` (keyword `setlocal`)

mycpp/cppgen_pass.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1909,7 +1909,7 @@ def visit_func_def(self, o: 'mypy.nodes.FuncDef') -> T:
19091909
# osh/word_eval.py
19101910
class_name is None and func_name == 'CheckCompatArray' or
19111911
# core/state.py
1912-
class_name is None and func_name in ('_PackFlags', 'SetVar') or
1912+
class_name is None and func_name in ('_PackFlags', 'SetLocalShopt') or
19131913
class_name == 'Mem' and func_name in ('GetValue', 'SetValue', 'GetCell') or
19141914
class_name == 'SearchPath' and func_name == 'Lookup' or
19151915
# core/ui.py

0 commit comments

Comments
 (0)