Commit 3f2e6f28
3f2e6f288a05Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +1 added · ~2 modified
Description
codegen,analyze: punctuation global variables compile to safe identifiers
Any program referencing `$!` / `$;` / `$,` / `$/` / `$:` etc. hit a C compile error because spinel emitted `gv_!` / `gv_;` / ... which aren't valid C identifiers. Map each non-alphanumeric char to a stable word (`!` → `bang`, `;` → `semi`, ...) so the suffix becomes a valid identifier and the same Ruby global maps to one C name everywhere it appears.
`$!` reads as the rescued exception message string (NULL outside rescue → inspects as "nil"); `$/` reads as `"\n"` (its only meaningful default); other punct globals read as nil.
Fixes #831
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 3f2e6f288a05
- Parent
- cf0d43265ab5
spinel_analyze.rbmodifiedView file
if gname == "$~" || gname == "$&" || gname == "$`" || gname == "$'" return "string" end # Issue #831: $! is the currently-rescued exception. Read as # the rescue message string (NULL outside rescue → .inspect = "nil"). if gname == "$!" || gname == "$;" || gname == "$," || gname == "$/" return "string" end gi = 0 while gi < @gvar_names.length if @gvar_names[gi] == gnamespinel_codegen.rbmodifiedView file
Loading diff…
test/global_var_punct.rbaddedView file
Loading diff…