Commit 01f36bc8
01f36bc8ec7aMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 9 files · +4 added · ~5 modified
Description
Merge pull request #353 from ryanseys/rs/zero-division-error
fix(codegen,runtime): raise ZeroDivisionError on integer division by zero
Details
- Commit
- 01f36bc8ec7a
- Parent
- 2ff7ba46856e
- Merge parent
- 64a699fda165
lib/mruby_shim.hmodifiedView file
@@ -41,13 +41,26 @@
4141
#define mrb_free(mrb, p) free(p)4242
#define mrb_malloc_simple(mrb, sz) malloc(sz)4343
44-
/* Error handling */45-
#define mrb_raise(mrb, cls, msg) do { fprintf(stderr, "%s\n", msg); exit(1); } while(0)46-
#define mrb_int_zerodiv(mrb) do { fprintf(stderr, "divided by 0\n"); exit(1); } while(0)47-
#define E_RANGE_ERROR 048-
#define E_RUNTIME_ERROR 049-
#define E_ARGUMENT_ERROR 050-
#define E_TYPE_ERROR 044+
/* Error handling — sp_bigint.c is compiled as a separate TU and45+
would otherwise hard-exit on internal errors (mini-gmp's zero-46+
divisor check, allocation overflow, etc.). The mrb_raise macro47+
now dispatches on the symbolic class enum: ZeroDivisionError is48+
routed through sp_bigint_raise_zerodiv (defined non-static in49+
sp_runtime.h, linked from gen.c) so it reaches spinel's longjmp50+
rescue net and is catchable by `rescue ZeroDivisionError`.51+
Other classes still hard-exit — they're internal invariants52+
(allocation overflow) where graceful handling buys little. */53+
extern void sp_bigint_raise_zerodiv(const char *msg);54+
#define E_RANGE_ERROR 155+
#define E_RUNTIME_ERROR 256+
#define E_ARGUMENT_ERROR 357+
#define E_TYPE_ERROR 458+
#define E_ZERODIV_ERROR 559+
#define mrb_raise(mrb, cls, msg) do { \60+
if ((cls) == E_ZERODIV_ERROR) { sp_bigint_raise_zerodiv(msg); } \61+
else { fprintf(stderr, "%s\n", msg); exit(1); } \62+
} while(0)63+
#define mrb_int_zerodiv(mrb) sp_bigint_raise_zerodiv("divided by 0")5164
5265
/* mrb_value stub - tagged union */5366
typedef struct mrb_value {lib/sp_bigint.cmodifiedView file
Loading diff…
lib/sp_runtime.hmodifiedView file
Loading diff…
spinel_codegen.rbmodifiedView file
Loading diff…
test/bigint_div_by_zero.rbaddedView file
Loading diff…
test/bigint_div_by_zero.rb.expectedaddedView file
Loading diff…
test/endless_method_rescue.rbmodifiedView file
Loading diff…
test/integer_div_by_zero.rbaddedView file
Loading diff…
test/integer_div_by_zero.rb.expectedaddedView file
Loading diff…