Commit 24ec1cf6
24ec1cf637a4Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 6 files · +2 added · ~4 modified
Description
codegen,runtime: clang-clean string literals + base-0 to_i + each_line newlines
Three independent fixes squashed because they share the runtime helper and codegen string-emit paths:
-
clang's CI build rejected raw high bytes (>=0x80) in source with -Winvalid-source-encoding. c_string_literal now emits each such byte as \xHH (with a string-concat break before any following hex digit) so the source is pure ASCII.
-
String#to_i(0) auto-detects the base from the literal prefix (0x → 16, 0b → 2, 0/0o → 8, 0d → 10, otherwise decimal). Fixes #927.
-
String#each_line yields each line WITH its trailing newline, matching CRuby. Pre-fix relied on sp_str_split which strips the delimiter. Fixes #922.
Also updates test/str_to_i_overflow expectations to the RangeError-raising semantics introduced by #842.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 24ec1cf637a4
- Parent
- 7c38a7c82a6f
lib/sp_runtime.hmodifiedView file
far. Issue #883. */static mrb_int sp_str_to_i_base(const char *s, mrb_int base) { if (!s) return 0; if (base < 2 || base > 36) base = 10; /* base 0 = auto-detect from prefix (0x → 16, 0b → 2, 0/0o → 8, otherwise 10). Per CRuby, only base 0 enables prefix-based dispatch — explicit bases just *accept* the matching prefix. */ if (base != 0 && (base < 2 || base > 36)) base = 10; const char *p = s; while (isspace((unsigned char)*p)) p++; int neg = 0; if (*p == '+') p++; else if (*p == '-') { neg = 1; p++; } /* Optional `0x` / `0b` / `0o` prefix matching the explicit base. CRuby's String#to_i(base) accepts these. */ if (*p == '0' && p[1] != 0) { if (base == 0) { if (*p == '0') { if (p[1] == 'x' || p[1] == 'X') { base = 16; p += 2; } else if (p[1] == 'b' || p[1] == 'B') { base = 2; p += 2; } else if (p[1] == 'o' || p[1] == 'O') { base = 8; p += 2; } else if (p[1] == 'd' || p[1] == 'D') { base = 10; p += 2; } else if (p[1] >= '0' && p[1] <= '7') { base = 8; p++; } else { base = 10; } } else { base = 10; } } else if (*p == '0' && p[1] != 0) { /* Explicit base accepts the matching prefix. */ if ((base == 16) && (p[1] == 'x' || p[1] == 'X')) p += 2; else if ((base == 2) && (p[1] == 'b' || p[1] == 'B')) p += 2; else if ((base == 8) && (p[1] == 'o' || p[1] == 'O')) p += 2;spinel_codegen.rbmodifiedView file
Loading diff…
test/str_to_i_overflow.rbmodifiedView file
Loading diff…
test/str_to_i_overflow.rb.expectedmodifiedView file
Loading diff…
test/string_each_line_keeps_newline.rbaddedView file
Loading diff…
test/string_to_i_base_zero.rbaddedView file
Loading diff…