ruby-changes:67020
From: S.H <ko1@a...>
Date: Mon, 2 Aug 2021 12:07:07 +0900 (JST)
Subject: [ruby-changes:67020] 378e8cdad6 (master): Using RBOOL macro
https://git.ruby-lang.org/ruby.git/commit/?id=378e8cdad6 From 378e8cdad69e6ba995a024da2957719789f0679e Mon Sep 17 00:00:00 2001 From: "S.H" <gamelinks007@g...> Date: Mon, 2 Aug 2021 12:06:44 +0900 Subject: Using RBOOL macro --- array.c | 4 +--- compar.c | 12 ++++-------- cont.c | 9 ++------- encoding.c | 4 ++-- error.c | 8 +++----- file.c | 2 -- gc.c | 10 +++++----- hash.c | 21 +++++--------------- internal.h | 2 ++ io.c | 19 +++++++----------- load.c | 2 +- numeric.c | 45 ++++++++++++++++++------------------------- object.c | 24 +++++++++-------------- proc.c | 18 ++++------------- range.c | 11 +++-------- re.c | 8 ++------ string.c | 13 +++++-------- thread.c | 34 ++++++++++---------------------- thread_sync.c | 25 +++++++----------------- time.c | 7 +++---- vm.c | 18 +++++------------ vm_backtrace.c | 7 +------ vm_eval.c | 7 +------ vm_insnhelper.c | 60 +++++++++++++++++++-------------------------------------- vm_method.c | 8 +++----- vm_trace.c | 6 +++--- 26 files changed, 127 insertions(+), 257 deletions(-) diff --git a/array.c b/array.c index 36f712b..bd323cd 100644 --- a/array.c +++ b/array.c @@ -2668,9 +2668,7 @@ rb_ary_length(VALUE ary) https://github.com/ruby/ruby/blob/trunk/array.c#L2668 static VALUE rb_ary_empty_p(VALUE ary) { - if (RARRAY_LEN(ary) == 0) - return Qtrue; - return Qfalse; + return RBOOL(RARRAY_LEN(ary) == 0); } VALUE diff --git a/compar.c b/compar.c index 0de3185..7974017 100644 --- a/compar.c +++ b/compar.c @@ -105,8 +105,7 @@ cmpint(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/compar.c#L105 static VALUE cmp_gt(VALUE x, VALUE y) { - if (cmpint(x, y) > 0) return Qtrue; - return Qfalse; + return RBOOL(cmpint(x, y) > 0); } /* @@ -120,8 +119,7 @@ cmp_gt(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/compar.c#L119 static VALUE cmp_ge(VALUE x, VALUE y) { - if (cmpint(x, y) >= 0) return Qtrue; - return Qfalse; + return RBOOL(cmpint(x, y) >= 0); } /* @@ -135,8 +133,7 @@ cmp_ge(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/compar.c#L133 static VALUE cmp_lt(VALUE x, VALUE y) { - if (cmpint(x, y) < 0) return Qtrue; - return Qfalse; + return RBOOL(cmpint(x, y) < 0); } /* @@ -150,8 +147,7 @@ cmp_lt(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/compar.c#L147 static VALUE cmp_le(VALUE x, VALUE y) { - if (cmpint(x, y) <= 0) return Qtrue; - return Qfalse; + return RBOOL(cmpint(x, y) <= 0); } /* diff --git a/cont.c b/cont.c index 22c5ce5..099f85a 100644 --- a/cont.c +++ b/cont.c @@ -1085,12 +1085,7 @@ fiber_memsize(const void *ptr) https://github.com/ruby/ruby/blob/trunk/cont.c#L1085 VALUE rb_obj_is_fiber(VALUE obj) { - if (rb_typeddata_is_kind_of(obj, &fiber_data_type)) { - return Qtrue; - } - else { - return Qfalse; - } + return RBOOL(rb_typeddata_is_kind_of(obj, &fiber_data_type)); } static void @@ -2351,7 +2346,7 @@ rb_fiber_transfer(VALUE fiber_value, int argc, const VALUE *argv) https://github.com/ruby/ruby/blob/trunk/cont.c#L2346 VALUE rb_fiber_blocking_p(VALUE fiber) { - return (fiber_ptr(fiber)->blocking == 0) ? Qfalse : Qtrue; + return RBOOL(fiber_ptr(fiber)->blocking != 0); } /* diff --git a/encoding.c b/encoding.c index 32d5a34..0f3f7f2 100644 --- a/encoding.c +++ b/encoding.c @@ -662,7 +662,7 @@ rb_encdb_dummy(const char *name) https://github.com/ruby/ruby/blob/trunk/encoding.c#L662 static VALUE enc_dummy_p(VALUE enc) { - return ENC_DUMMY_P(must_encoding(enc)) ? Qtrue : Qfalse; + return RBOOL(ENC_DUMMY_P(must_encoding(enc))); } /* @@ -678,7 +678,7 @@ enc_dummy_p(VALUE enc) https://github.com/ruby/ruby/blob/trunk/encoding.c#L678 static VALUE enc_ascii_compatible_p(VALUE enc) { - return rb_enc_asciicompat(must_encoding(enc)) ? Qtrue : Qfalse; + return RBOOL(rb_enc_asciicompat(must_encoding(enc))); } /* diff --git a/error.c b/error.c index 1f3f4ed..5ac0f09 100644 --- a/error.c +++ b/error.c @@ -217,9 +217,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/error.c#L217 rb_warning_s_aref(VALUE mod, VALUE category) { rb_warning_category_t cat = rb_warning_category_from_name(category); - if (rb_warning_category_enabled_p(cat)) - return Qtrue; - return Qfalse; + return RBOOL(rb_warning_category_enabled_p(cat)); } /* @@ -1231,7 +1229,7 @@ rb_get_message(VALUE exc) https://github.com/ruby/ruby/blob/trunk/error.c#L1229 static VALUE exc_s_to_tty_p(VALUE self) { - return rb_stderr_tty_p() ? Qtrue : Qfalse; + return RBOOL(rb_stderr_tty_p()); } /* @@ -1802,7 +1800,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/error.c#L1800 nometh_err_init_attr(VALUE exc, VALUE args, int priv) { rb_ivar_set(exc, id_args, args); - rb_ivar_set(exc, id_private_call_p, priv ? Qtrue : Qfalse); + rb_ivar_set(exc, id_private_call_p, RBOOL(priv)); return exc; } diff --git a/file.c b/file.c index 0afee42..4ea8de6 100644 --- a/file.c +++ b/file.c @@ -171,8 +171,6 @@ int flock(int, int); https://github.com/ruby/ruby/blob/trunk/file.c#L171 #include "ruby/thread.h" #include "ruby/util.h" -#define RBOOL(v) ((v) ? Qtrue : Qfalse) - VALUE rb_cFile; VALUE rb_mFileTest; VALUE rb_cStat; diff --git a/gc.c b/gc.c index f6ea4fc..ab7532b 100644 --- a/gc.c +++ b/gc.c @@ -8600,7 +8600,7 @@ rb_obj_rgengc_writebarrier_protected_p(VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L8600 VALUE rb_obj_rgengc_promoted_p(VALUE obj) { - return OBJ_PROMOTED(obj) ? Qtrue : Qfalse; + return RBOOL(OBJ_PROMOTED(obj)); } size_t @@ -10645,7 +10645,7 @@ rb_objspace_gc_enable(rb_objspace_t *objspace) https://github.com/ruby/ruby/blob/trunk/gc.c#L10645 int old = dont_gc_val(); dont_gc_off(); - return old ? Qtrue : Qfalse; + return RBOOL(old); } static VALUE @@ -10666,7 +10666,7 @@ gc_disable_no_rest(rb_objspace_t *objspace) https://github.com/ruby/ruby/blob/trunk/gc.c#L10666 { int old = dont_gc_val(); dont_gc_on(); - return old ? Qtrue : Qfalse; + return RBOOL(old); } VALUE @@ -10718,7 +10718,7 @@ gc_set_auto_compact(rb_execution_context_t *ec, VALUE _, VALUE v) https://github.com/ruby/ruby/blob/trunk/gc.c#L10718 static VALUE gc_get_auto_compact(rb_execution_context_t *ec, VALUE _) { - return ruby_enable_autocompact ? Qtrue : Qfalse; + return RBOOL(ruby_enable_autocompact); } static int @@ -12858,7 +12858,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/gc.c#L12858 gc_profile_enable_get(VALUE self) { rb_objspace_t *objspace = &rb_objspace; - return objspace->profile.run ? Qtrue : Qfalse; + return RBOOL(objspace->profile.run); } /* diff --git a/hash.c b/hash.c index 32f1364..ca44118 100644 --- a/hash.c +++ b/hash.c @@ -1956,7 +1956,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/hash.c#L1956 rb_hash_s_ruby2_keywords_hash_p(VALUE dummy, VALUE hash) { Check_Type(hash, T_HASH); - return (RHASH(hash)->basic.flags & RHASH_PASS_AS_KEYWORDS) ? Qtrue : Qfalse; + return RBOOL(RHASH(hash)->basic.flags & RHASH_PASS_AS_KEYWORDS); } /* @@ -3029,7 +3029,7 @@ rb_hash_size_num(VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L3029 static VALUE rb_hash_empty_p(VALUE hash) { - return RHASH_EMPTY_P(hash) ? Qtrue : Qfalse; + return RBOOL(RHASH_EMPTY_P(hash)); } static int @@ -3667,12 +3667,7 @@ rb_hash_values(VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L3667 MJIT_FUNC_EXPORTED VALUE rb_hash_has_key(VALUE hash, VALUE key) { - if (hash_stlike_lookup(hash, key, NULL)) { - return Qtrue; - } - else { - return Qfalse; - } + return RBOOL(hash_stlike_lookup(hash, key, NULL)); } static int @@ -4446,12 +4441,7 @@ rb_hash_compare_by_id(VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L4441 MJIT_FUNC_EXPORTED VALUE rb_hash_compare_by_id_p(VALUE hash) { - if (RHASH_ST_TABLE_P(hash) && RHASH_ST_TABLE(hash)->type == &identhash) { - return Qtrue; - } - else { - return Qfalse; - } + return RBOOL(RHASH_ST_TABLE_P(hash) && RHASH_ST_TABLE(hash)->type == &identhash); } VALUE @@ -6053,8 +6043,7 @@ env_has_key(VALUE env, VALUE key) https://github.com/ruby/ruby/blob/trunk/hash.c#L6043 const char *s; s = env_name(key); - if (getenv(s)) return Qtrue; - return Qfalse; + return RBOOL(getenv(s)); } /* diff --git a/internal.h b/internal.h index c3b3a79..883459b 100644 --- a/internal.h +++ b/internal.h @@ -104,4 +104,6 @@ RUBY_SYMBOL_EXPORT_END https://github.com/ruby/ruby/blob/trunk/internal.h#L104 // but breakpoint is set in run.gdb, so `make gdb` can stop here. #define bp() ruby_debug_breakpoint() +#define RBOOL(v) ((v) ? Qtrue : Qfalse) + #endif /* RUBY_INTERNAL_H */ diff --git a/io.c b/io.c index 16f2526..c446658 100644 --- a/io.c +++ b/io.c @@ -2375,13 +2375,10 @@ rb_io_eof(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L2375 READ_CHECK(fptr); #if RUBY_CRLF_ENVIRONMENT if (!NEED_READCONV(fptr) && NEED_NEWLINE_DECORATOR_ON_READ(fptr)) { - return eof(fptr->fd) ? Qtrue : Qfalse; + return RBOOL(eof(fptr->fd));; } #endif - if (io_fillbuf(fptr) < 0) { - return Qtrue; - } - return Qfalse; + return RBOOL(io_fillbuf(fptr) < 0); } /* @@ -2404,7 +2401,7 @@ rb_io_sync(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L2401 io = GetWriteIO(io); GetOpenFile(io, fptr); - return (fptr->mode & FMODE_SYNC) ? Qtrue : Qfalse; + return RBOOL(fptr->mode & FMODE_SYNC); } #ifdef HAVE_FSYNC @@ -4589,9 +4586,7 @@ rb_io_isatty(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L4586 rb_io_t *fptr; GetOpenFile(io, fptr); - if (isatty(fptr->fd) == 0) - return Qfalse; - return Qtrue; + return RBOOL(isatty(fptr->fd) != 0); } (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/