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:
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
2
dir.c
|
@ -2948,7 +2948,7 @@ dir_glob_option_base(VALUE base)
|
||||||
static int
|
static int
|
||||||
dir_glob_option_sort(VALUE sort)
|
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
|
static VALUE
|
||||||
|
|
2
error.c
2
error.c
|
@ -1273,7 +1273,7 @@ check_highlight_keyword(VALUE opt, int auto_tty_detect)
|
||||||
|
|
||||||
switch (highlight) {
|
switch (highlight) {
|
||||||
default:
|
default:
|
||||||
rb_bool_expected(highlight, "highlight");
|
rb_bool_expected(highlight, "highlight", TRUE);
|
||||||
UNREACHABLE;
|
UNREACHABLE;
|
||||||
case Qtrue: case Qfalse: case Qnil: break;
|
case Qtrue: case Qfalse: case Qnil: break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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_obj_dig(int argc, VALUE *argv, VALUE self, VALUE notfound);
|
||||||
VALUE rb_immutable_obj_clone(int, VALUE *, VALUE);
|
VALUE rb_immutable_obj_clone(int, VALUE *, VALUE);
|
||||||
VALUE rb_check_convert_type_with_id(VALUE,int,const char*,ID);
|
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_CLEAR_CLASS(VALUE obj);
|
||||||
static inline void RBASIC_SET_CLASS_RAW(VALUE obj, VALUE klass);
|
static inline void RBASIC_SET_CLASS_RAW(VALUE obj, VALUE klass);
|
||||||
static inline void RBASIC_SET_CLASS(VALUE obj, VALUE klass);
|
static inline void RBASIC_SET_CLASS(VALUE obj, VALUE klass);
|
||||||
|
|
4
io.c
4
io.c
|
@ -3385,7 +3385,7 @@ io_read_nonblock(rb_execution_context_t *ec, VALUE io, VALUE length, VALUE str,
|
||||||
}
|
}
|
||||||
|
|
||||||
shrinkable = io_setstrbuf(&str, len);
|
shrinkable = io_setstrbuf(&str, len);
|
||||||
rb_bool_expected(ex, "exception");
|
rb_bool_expected(ex, "exception", TRUE);
|
||||||
|
|
||||||
GetOpenFile(io, fptr);
|
GetOpenFile(io, fptr);
|
||||||
rb_io_check_byte_readable(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))
|
if (!RB_TYPE_P(str, T_STRING))
|
||||||
str = rb_obj_as_string(str);
|
str = rb_obj_as_string(str);
|
||||||
rb_bool_expected(ex, "exception");
|
rb_bool_expected(ex, "exception", TRUE);
|
||||||
|
|
||||||
io = GetWriteIO(io);
|
io = GetWriteIO(io);
|
||||||
GetOpenFile(io, fptr);
|
GetOpenFile(io, fptr);
|
||||||
|
|
24
object.c
24
object.c
|
@ -3158,16 +3158,22 @@ rb_check_integer_type(VALUE val)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
rb_bool_expected(VALUE obj, const char *flagname)
|
rb_bool_expected(VALUE obj, const char *flagname, int raise)
|
||||||
{
|
{
|
||||||
switch (obj) {
|
switch (obj) {
|
||||||
case Qtrue: case Qfalse:
|
case Qtrue:
|
||||||
break;
|
return TRUE;
|
||||||
default:
|
case Qfalse:
|
||||||
rb_raise(rb_eArgError, "expected true or false as %s: %+"PRIsVALUE,
|
return FALSE;
|
||||||
flagname, obj);
|
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
|
int
|
||||||
|
@ -3176,7 +3182,7 @@ rb_opts_exception_p(VALUE opts, int default_value)
|
||||||
static const ID kwds[1] = {idException};
|
static const ID kwds[1] = {idException};
|
||||||
VALUE exception;
|
VALUE exception;
|
||||||
if (rb_get_kwargs(opts, kwds, 0, 1, &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;
|
return default_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3562,7 +3568,7 @@ rb_f_float1(rb_execution_context_t *ec, VALUE obj, VALUE arg)
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_f_float(rb_execution_context_t *ec, VALUE obj, VALUE arg, VALUE opts)
|
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);
|
return rb_convert_to_float(arg, exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2210,7 +2210,7 @@ rb_execarg_addopt_rlimit(struct rb_execarg *eargp, int rtype, VALUE val)
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
int
|
||||||
rb_execarg_addopt(VALUE execarg_obj, VALUE key, VALUE val)
|
rb_execarg_addopt(VALUE execarg_obj, VALUE key, VALUE val)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue