Commit caa3993c
caa3993ceda8Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
codegen: case/when with regex pattern routes through sp_re_match_p
case "x" when /regex/ segfaulted because compile_when_conds'
generic strcmp arm passed 0 (compile_expr fallback for
RegularExpressionNode) into strcmp. Add a regex arm that
extracts the pattern via regex_pat_c_expr and emits
sp_re_match_p against the string predicate.
Refs #852
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- caa3993ceda8
- Parent
- 54de5e4a00ac
spinel_codegen.rbmodifiedView file
@@ -31444,6 +31444,18 @@
3144431444
# tmp, tripping the C compile.3144531445
elsif @nd_type[cid] == "ConstantReadNode" && not_in(@nd_name[cid], @builtin_class_names) == 03144631446
result = result + (@nd_name[cid] == "String" ? "1" : "0")31447+
# Issue #852: `case <string> when /regex/` -- Regexp#=== runs31448+
# the regex against the receiver. Route through sp_re_match_p.31449+
# Without this, the generic strcmp arm passed `0` (compile_expr31450+
# fallback for RegularExpressionNode) and segfaulted.31451+
elsif @nd_type[cid] == "RegularExpressionNode" || @nd_type[cid] == "InterpolatedRegularExpressionNode"31452+
rpat_w = regex_pat_c_expr(cid)31453+
if rpat_w != ""31454+
@needs_regexp = 131455+
result = result + "sp_re_match_p(" + rpat_w + ", " + tmp + ")"31456+
else31457+
result = result + "0"31458+
end3144731459
else3144831460
result = result + "strcmp(" + tmp + ", " + compile_expr(cid) + ") == 0"3144931461
endtest/case_when_regex.rbaddedView file
Loading diff…
test/case_when_regex.rb.expectedaddedView file
Loading diff…