1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Allow to just warn as bool expected, without an exception

This commit is contained in:
Nobuyoshi Nakada 2022-05-24 16:48:34 +09:00
parent 15db2e9496
commit a58611dfb1
Notes: git 2022-06-20 19:35:35 +09:00
6 changed files with 21 additions and 15 deletions

2
dir.c
View file

@ -2948,7 +2948,7 @@ dir_glob_option_base(VALUE base)
static int
dir_glob_option_sort(VALUE sort)
{
return (rb_bool_expected(sort, "sort") ? 0 : FNM_GLOB_NOSORT);
return (rb_bool_expected(sort, "sort", TRUE) ? 0 : FNM_GLOB_NOSORT);
}
static VALUE

View file

@ -1273,7 +1273,7 @@ check_highlight_keyword(VALUE opt, int auto_tty_detect)
switch (highlight) {
default:
rb_bool_expected(highlight, "highlight");
rb_bool_expected(highlight, "highlight", TRUE);
UNREACHABLE;
case Qtrue: case Qfalse: case Qnil: break;
}

View file

@ -22,7 +22,7 @@ double rb_num_to_dbl(VALUE val);
VALUE rb_obj_dig(int argc, VALUE *argv, VALUE self, VALUE notfound);
VALUE rb_immutable_obj_clone(int, VALUE *, VALUE);
VALUE rb_check_convert_type_with_id(VALUE,int,const char*,ID);
int rb_bool_expected(VALUE, const char *);
int rb_bool_expected(VALUE, const char *, int raise);
static inline void RBASIC_CLEAR_CLASS(VALUE obj);
static inline void RBASIC_SET_CLASS_RAW(VALUE obj, VALUE klass);
static inline void RBASIC_SET_CLASS(VALUE obj, VALUE klass);

4
io.c
View file

@ -3385,7 +3385,7 @@ io_read_nonblock(rb_execution_context_t *ec, VALUE io, VALUE length, VALUE str,
}
shrinkable = io_setstrbuf(&str, len);
rb_bool_expected(ex, "exception");
rb_bool_expected(ex, "exception", TRUE);
GetOpenFile(io, fptr);
rb_io_check_byte_readable(fptr);
@ -3433,7 +3433,7 @@ io_write_nonblock(rb_execution_context_t *ec, VALUE io, VALUE str, VALUE ex)
if (!RB_TYPE_P(str, T_STRING))
str = rb_obj_as_string(str);
rb_bool_expected(ex, "exception");
rb_bool_expected(ex, "exception", TRUE);
io = GetWriteIO(io);
GetOpenFile(io, fptr);

View file

@ -3158,16 +3158,22 @@ rb_check_integer_type(VALUE val)
}
int
rb_bool_expected(VALUE obj, const char *flagname)
rb_bool_expected(VALUE obj, const char *flagname, int raise)
{
switch (obj) {
case Qtrue: case Qfalse:
break;
default:
rb_raise(rb_eArgError, "expected true or false as %s: %+"PRIsVALUE,
flagname, obj);
case Qtrue:
return TRUE;
case Qfalse:
return FALSE;
default: {
static const char message[] = "expected true or false as %s: %+"PRIsVALUE;
if (raise) {
rb_raise(rb_eArgError, message, flagname, obj);
}
rb_warning(message, flagname, obj);
return !NIL_P(obj);
}
}
return obj != Qfalse;
}
int
@ -3176,7 +3182,7 @@ rb_opts_exception_p(VALUE opts, int default_value)
static const ID kwds[1] = {idException};
VALUE exception;
if (rb_get_kwargs(opts, kwds, 0, 1, &exception))
return rb_bool_expected(exception, "exception");
return rb_bool_expected(exception, "exception", TRUE);
return default_value;
}
@ -3562,7 +3568,7 @@ rb_f_float1(rb_execution_context_t *ec, VALUE obj, VALUE arg)
static VALUE
rb_f_float(rb_execution_context_t *ec, VALUE obj, VALUE arg, VALUE opts)
{
int exception = rb_bool_expected(opts, "exception");
int exception = rb_bool_expected(opts, "exception", TRUE);
return rb_convert_to_float(arg, exception);
}

View file

@ -2210,7 +2210,7 @@ rb_execarg_addopt_rlimit(struct rb_execarg *eargp, int rtype, VALUE val)
}
#endif
#define TO_BOOL(val, name) NIL_P(val) ? 0 : rb_bool_expected((val), name)
#define TO_BOOL(val, name) (NIL_P(val) ? 0 : rb_bool_expected((val), name, TRUE))
int
rb_execarg_addopt(VALUE execarg_obj, VALUE key, VALUE val)
{