Commit 36cfb8c
committed
fix(include): snapshot base_dir at load_file_into_program entry
base_dir was aliased to get_base_dir()'s static buffer at the call
site. A nested #INCLUDE "../foo" recursive call recomputed
get_base_dir() inside the recursion, overwriting that buffer — so
when the recursion returned, the parent's view of *its own*
directory was now the included file's directory. The parent's
next #INCLUDE in the same file then resolved against the wrong
base.
Concrete failure: shooter.bas at /shooter/shooter.bas with
#INCLUDE "../maplib.bas"
#INCLUDE "level1.bas"
The first include recursed into /shooter/../maplib.bas; on return
shooter.bas's base_dir had been clobbered to "/shooter/..", so
"level1.bas" resolved to "/shooter/../level1.bas" (no such file)
and basic-gfx exit(1)'d with "Cannot open …".
Fix: copy base_dir into a stack-local buffer at function entry and
re-point the parameter at it. Each recursion now has its own
stable base_dir even though get_base_dir's static is shared.
Test added:
tests/include_chain_test.bas + include_chain/main.bas + inner.bas
+ include_chain_lib.bas — two-include chain that pre-fix exit(1)'d
on the second include and now returns 18 (7+11).1 parent 7129f57 commit 36cfb8c
5 files changed
Lines changed: 37 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15883 | 15883 | | |
15884 | 15884 | | |
15885 | 15885 | | |
| 15886 | + | |
| 15887 | + | |
| 15888 | + | |
| 15889 | + | |
| 15890 | + | |
| 15891 | + | |
| 15892 | + | |
| 15893 | + | |
| 15894 | + | |
| 15895 | + | |
15886 | 15896 | | |
15887 | 15897 | | |
15888 | 15898 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
0 commit comments