From 3e7d002118a92fad5934e11c75be6768a1476c1b Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Thu, 11 Jul 2019 19:20:53 +0900 Subject: Check exception flag as a bool [Bug #15987] --- ext/bigdecimal/bigdecimal.c | 12 ++++++++++++ ext/bigdecimal/extconf.rb | 1 + 2 files changed, 13 insertions(+) (limited to 'ext') diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index da1b24a631..430707a4d6 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -2560,6 +2560,10 @@ BigDecimal_clone(VALUE self) return self; } +#ifdef HAVE_RB_OPTS_EXCEPTION_P +int rb_opts_exception_p(VALUE opts, int default_value); +#define opts_exception_p(opts) rb_opts_exception_p((opts), 1) +#else static int opts_exception_p(VALUE opts) { @@ -2569,8 +2573,16 @@ opts_exception_p(VALUE opts) kwds[0] = rb_intern_const("exception"); } rb_get_kwargs(opts, kwds, 0, 1, &exception); + switch (exception) { + case Qtrue: case Qfalse: + break; + default: + rb_raise(rb_eArgError, "true or false is expected as exception: %+"PRIsVALUE, + flagname, obj); + } return exception != Qfalse; } +#endif static Real * BigDecimal_new(int argc, VALUE *argv) diff --git a/ext/bigdecimal/extconf.rb b/ext/bigdecimal/extconf.rb index a6a36304cc..7a7af10a2d 100644 --- a/ext/bigdecimal/extconf.rb +++ b/ext/bigdecimal/extconf.rb @@ -27,6 +27,7 @@ have_func("rb_rational_num", "ruby.h") have_func("rb_rational_den", "ruby.h") have_func("rb_array_const_ptr", "ruby.h") have_func("rb_sym2str", "ruby.h") +have_func("rb_opts_exception_p", "ruby.h") if File.file?(File.expand_path('../lib/bigdecimal.rb', __FILE__)) bigdecimal_rb = "$(srcdir)/lib/bigdecimal.rb" -- cgit v1.2.3