Commit 801014e6
801014e60f8eMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · ~2 modified
Description
fix: address Gemini review critical/high issues from PRs #175/#178/#180/#188
- sp_powmod: guard mod==0 to avoid SIGFPE (CRuby raises ZeroDivisionError; we return 0 to keep the program alive). [PR #175 critical]
- emit_constructor: filter ForwardingSuperNode alongside SuperNode in the
initialize body so bare
superin intermediate classes doesn't fall through to compile_stmt and emit a dummy0;. [PR #178 high] - emit_poly_builtin_dispatch PtrArray branch: drop the (mrb_int) cast on sp_PtrArray_get's void* result. The cast broke the non-poly path when result_tmp was a pointer type (sp_Foo ); void is implicitly convertible to any pointer for non-poly and accepted directly by sp_box_obj for poly. [PR #180 high]
- ParenthesesNode multi-stmt expression context: use compile_stmt for
leading statements (so puts/print/raise/writers actually emit their
side effects instead of degenerating to
0;) and short-circuit the void-typed final-statement case. [PR #188 high]
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 801014e60f8e
- Parent
- dac2f2f3c80d
lib/sp_runtime.hmodifiedView file
@@ -77,7 +77,8 @@
7777
7878
static mrb_int sp_gcd(mrb_int a,mrb_int b){if(a<0)a=-a;if(b<0)b=-b;while(b){mrb_int t=b;b=a%b;a=t;}return a;}7979
static mrb_int sp_lcm(mrb_int a,mrb_int b){if(a==0||b==0)return 0;mrb_int g=sp_gcd(a,b);if(a<0)a=-a;if(b<0)b=-b;return (a/g)*b;}80-
static mrb_int sp_powmod(mrb_int base,mrb_int exp,mrb_int mod){mrb_int r=1;mrb_int m=mod<0?-mod:mod;if(m==1){r=0;}else{base=base%m;if(base<0)base+=m;while(exp>0){if(exp%2==1)r=r*base%m;exp=exp/2;base=base*base%m;}}if(mod<0&&r>0)r-=m;return r;}80+
/* CRuby raises ZeroDivisionError on mod==0; we return 0 to avoid SIGFPE rather than crashing. */81+
static mrb_int sp_powmod(mrb_int base,mrb_int exp,mrb_int mod){if(mod==0)return 0;mrb_int r=1;mrb_int m=mod<0?-mod:mod;if(m==1){r=0;}else{base=base%m;if(base<0)base+=m;while(exp>0){if(exp%2==1)r=r*base%m;exp=exp/2;base=base*base%m;}}if(mod<0&&r>0)r-=m;return r;}8182
static mrb_int sp_int_clamp(mrb_int v,mrb_int lo,mrb_int hi){return v<lo?lo:v>hi?hi:v;}8283
static inline char *sp_str_alloc_raw(size_t total_with_null); /* fwd decl */8384
static const char*sp_int_chr(mrb_int n){char*s=sp_str_alloc_raw(2);s[0]=(char)n;s[1]=0;return s;}spinel_codegen.rbmodifiedView file
Loading diff…