Conversation
在 load_file_1 函数中添加 shebang 行跳过逻辑, 使 Goldfish Scheme 能够正确执行以 #! 开头的脚本文件。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Greptile SummaryThis PR adds shebang (
Confidence Score: 3/5Safe to merge for Unix-like platforms; Windows shebang support is silently broken and no tests were added. The core logic is correct and non-crashing on all platforms (the is_string_port guard prevents NULL dereference on Windows/pseudo-files). However, the feature silently does nothing on Windows, and there are no test cases to verify correct behavior or catch regressions — both gaps that should be addressed before or shortly after merging. src/s7.c — specifically the Windows file_port path that is unhandled by the new shebang logic. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[load_file_1 called] --> B[fopen file]
B --> C{fp valid?}
C -- No --> Z[return NULL]
C -- Yes --> D["read_file(sc, fp, name, -1, 'load')"]
D --> E{Platform?}
E -- "Windows (#else)" --> F["port_type = file_port\nport_data = NULL"]
E -- "Non-Windows + size > 0" --> G["port_type = string_port\nport_data = content buffer"]
E -- "Non-Windows + size == 0\n(pseudo-files)" --> F
F --> J["is_string_port? → false\nShebang check SKIPPED"]
G --> H["is_string_port? → true\nCheck data[0]=='#' && data[1]=='!'"]
H -- No shebang --> K[port_position stays at 0]
H -- Shebang found --> I{newline found?}
I -- Yes --> L["port_position = pos + 1\n(skip shebang line)"]
I -- No --> M["port_position = port_data_size\n(empty remainder)"]
J --> N[push_input_port & parse]
K --> N
L --> N
M --> N
Reviews (1): Last reviewed commit: "[200_60] Goldfish Scheme 支持 shebang" | Re-trigger Greptile |
src/s7.c
Outdated
| if (is_string_port(port) && | ||
| port_data_size(port) >= 2 && | ||
| port_data(port)[0] == '#' && | ||
| port_data(port)[1] == '!') | ||
| { | ||
| uint8_t *data = port_data(port); | ||
| s7_int pos = 0; | ||
| while (pos < port_data_size(port) && data[pos] != '\n') | ||
| pos++; | ||
| if (pos < port_data_size(port)) /* 找到换行符,跳过它 */ | ||
| port_position(port) = pos + 1; | ||
| else /* 没有换行符,文件只有 shebang 行 */ | ||
| port_position(port) = port_data_size(port); | ||
| } |
There was a problem hiding this comment.
Shebang support silently skipped on Windows
The shebang-skip logic is guarded by is_string_port(port), but on Windows, read_file always creates a file_port (not a string_port) — see the #else branch starting at line 27577 in src/s7.c. This means the #! line is never skipped on Windows, and the interpreter will encounter a syntax error when loading a shebang script on that platform.
The Windows-specific branch sets port_data = NULL and port_data_size = 0, so the is_string_port guard correctly prevents a NULL-dereference crash, but the feature silently fails to work.
If Windows shebang support is needed, a separate code path for file_port (using getc/ungetc or similar) would be required. If Windows is intentionally out of scope, a comment here would clarify the limitation.
src/s7.c
Outdated
| if (is_string_port(port) && | ||
| port_data_size(port) >= 2 && | ||
| port_data(port)[0] == '#' && | ||
| port_data(port)[1] == '!') | ||
| { | ||
| uint8_t *data = port_data(port); | ||
| s7_int pos = 0; | ||
| while (pos < port_data_size(port) && data[pos] != '\n') | ||
| pos++; | ||
| if (pos < port_data_size(port)) /* 找到换行符,跳过它 */ | ||
| port_position(port) = pos + 1; | ||
| else /* 没有换行符,文件只有 shebang 行 */ | ||
| port_position(port) = port_data_size(port); | ||
| } |
There was a problem hiding this comment.
Shebang skipped for zero-size / pseudo-files (edge case)
When fseek/ftell reports size == 0 (e.g., files under /proc), read_file also creates a file_port, not a string_port. Those files won't receive shebang handling. This is unlikely to matter in practice since /proc pseudo-files don't use shebangs, but it is a subtle inconsistency worth noting alongside the Windows case above.
功能描述
在
load_file_1函数中添加 shebang 行跳过逻辑,使 Goldfish Scheme 能够正确执行以#!开头的脚本文件。实现细节
#!开头使用示例
用户现在可以创建如下脚本并直接执行:
相关文档
devel/200_60.md- 任务详细说明🤖 Generated with Claude Code