diff --git a/bignum.c b/bignum.c index 52f62b8331..7adf55d1f0 100644 --- a/bignum.c +++ b/bignum.c @@ -5387,18 +5387,14 @@ rb_integer_float_eq(VALUE x, VALUE y) if (FIXNUM_P(x)) { #if SIZEOF_LONG * CHAR_BIT < DBL_MANT_DIG /* assume FLT_RADIX == 2 */ double xd = (double)FIX2LONG(x); - if (xd != yd) - return Qfalse; - return Qtrue; + return RBOOL(xd == yd); #else long xn, yn; if (yi < LONG_MIN || LONG_MAX_as_double <= yi) return Qfalse; xn = FIX2LONG(x); yn = (long)yi; - if (xn != yn) - return Qfalse; - return Qtrue; + return RBOOL(xn == yn); #endif } y = rb_dbl2big(yi); @@ -5527,8 +5523,7 @@ rb_big_eq(VALUE x, VALUE y) } if (BIGNUM_SIGN(x) != BIGNUM_SIGN(y)) return Qfalse; if (BIGNUM_LEN(x) != BIGNUM_LEN(y)) return Qfalse; - if (MEMCMP(BDIGITS(x),BDIGITS(y),BDIGIT,BIGNUM_LEN(y)) != 0) return Qfalse; - return Qtrue; + return RBOOL(MEMCMP(BDIGITS(x),BDIGITS(y),BDIGIT,BIGNUM_LEN(y)) == 0); } VALUE @@ -5537,8 +5532,7 @@ rb_big_eql(VALUE x, VALUE y) if (!RB_BIGNUM_TYPE_P(y)) return Qfalse; if (BIGNUM_SIGN(x) != BIGNUM_SIGN(y)) return Qfalse; if (BIGNUM_LEN(x) != BIGNUM_LEN(y)) return Qfalse; - if (MEMCMP(BDIGITS(x),BDIGITS(y),BDIGIT,BIGNUM_LEN(y)) != 0) return Qfalse; - return Qtrue; + return RBOOL(MEMCMP(BDIGITS(x),BDIGITS(y),BDIGIT,BIGNUM_LEN(y)) == 0); } VALUE @@ -6821,10 +6815,7 @@ rb_big_bit_length(VALUE big) VALUE rb_big_odd_p(VALUE num) { - if (BIGNUM_LEN(num) != 0 && BDIGITS(num)[0] & 1) { - return Qtrue; - } - return Qfalse; + return RBOOL(BIGNUM_LEN(num) != 0 && BDIGITS(num)[0] & 1); } VALUE diff --git a/compar.c b/compar.c index 7974017e2b..e9d1ac41f9 100644 --- a/compar.c +++ b/compar.c @@ -84,8 +84,7 @@ cmp_equal(VALUE x, VALUE y) c = rb_exec_recursive_paired_outer(cmp_eq_recursive, x, y, y); if (NIL_P(c)) return Qfalse; - if (rb_cmpint(c, x, y) == 0) return Qtrue; - return Qfalse; + return RBOOL(rb_cmpint(c, x, y) == 0); } static int diff --git a/complex.c b/complex.c index ec77aeb588..ea3c137461 100644 --- a/complex.c +++ b/complex.c @@ -1451,10 +1451,7 @@ rb_complex_finite_p(VALUE self) { get_dat1(self); - if (f_finite_p(dat->real) && f_finite_p(dat->imag)) { - return Qtrue; - } - return Qfalse; + return RBOOL(f_finite_p(dat->real) && f_finite_p(dat->imag)); } /* diff --git a/error.c b/error.c index b589384303..84902204d2 100644 --- a/error.c +++ b/error.c @@ -1548,9 +1548,7 @@ exc_equal(VALUE exc, VALUE obj) if (!rb_equal(rb_attr_get(exc, id_mesg), mesg)) return Qfalse; - if (!rb_equal(exc_backtrace(exc), backtrace)) - return Qfalse; - return Qtrue; + return rb_equal(exc_backtrace(exc), backtrace); } /* @@ -1638,10 +1636,7 @@ exit_success_p(VALUE exc) if (NIL_P(status_val)) return Qtrue; status = NUM2INT(status_val); - if (WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS) - return Qtrue; - - return Qfalse; + return RBOOL(WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS); } static VALUE diff --git a/file.c b/file.c index f5d01fda2a..98b9d50446 100644 --- a/file.c +++ b/file.c @@ -2019,8 +2019,7 @@ rb_file_file_p(VALUE obj, VALUE fname) struct stat st; if (rb_stat(fname, &st) < 0) return Qfalse; - if (S_ISREG(st.st_mode)) return Qtrue; - return Qfalse; + return RBOOL(S_ISREG(st.st_mode)); } /* @@ -2039,8 +2038,7 @@ rb_file_zero_p(VALUE obj, VALUE fname) struct stat st; if (rb_stat(fname, &st) < 0) return Qfalse; - if (st.st_size == 0) return Qtrue; - return Qfalse; + return RBOOL(st.st_size == 0); } /* @@ -2080,8 +2078,7 @@ rb_file_owned_p(VALUE obj, VALUE fname) struct stat st; if (rb_stat(fname, &st) < 0) return Qfalse; - if (st.st_uid == geteuid()) return Qtrue; - return Qfalse; + return RBOOL(st.st_uid == geteuid()); } static VALUE @@ -2090,8 +2087,7 @@ rb_file_rowned_p(VALUE obj, VALUE fname) struct stat st; if (rb_stat(fname, &st) < 0) return Qfalse; - if (st.st_uid == getuid()) return Qtrue; - return Qfalse; + return RBOOL(st.st_uid == getuid()); } /* @@ -2124,8 +2120,7 @@ check3rdbyte(VALUE fname, int mode) struct stat st; if (rb_stat(fname, &st) < 0) return Qfalse; - if (st.st_mode & mode) return Qtrue; - return Qfalse; + return RBOOL(st.st_mode & mode); } #endif diff --git a/numeric.c b/numeric.c index 39c2bd7b82..3b481b3869 100644 --- a/numeric.c +++ b/numeric.c @@ -755,18 +755,10 @@ static VALUE int_zero_p(VALUE num) { if (FIXNUM_P(num)) { - if (FIXNUM_ZERO_P(num)) { - return Qtrue; - } + return RBOOL(FIXNUM_ZERO_P(num)); } - else { - assert(RB_BIGNUM_TYPE_P(num)); - if (rb_bigzero_p(num)) { - /* this should not happen usually */ - return Qtrue; - } - } - return Qfalse; + assert(RB_BIGNUM_TYPE_P(num)); + return RBOOL(rb_bigzero_p(num)); } VALUE @@ -1368,7 +1360,7 @@ rb_float_equal(VALUE x, VALUE y) #if MSC_VERSION_BEFORE(1300) if (isnan(a)) return Qfalse; #endif - return (a == b)?Qtrue:Qfalse; + return RBOOL(a == b); } #define flo_eq rb_float_equal @@ -1491,7 +1483,7 @@ rb_float_gt(VALUE x, VALUE y) #if MSC_VERSION_BEFORE(1300) if (isnan(a)) return Qfalse; #endif - return (a > b)?Qtrue:Qfalse; + return RBOOL(a > b); } /* @@ -1528,7 +1520,7 @@ flo_ge(VALUE x, VALUE y) #if MSC_VERSION_BEFORE(1300) if (isnan(a)) return Qfalse; #endif - return (a >= b)?Qtrue:Qfalse; + return RBOOL(a >= b); } /* @@ -1565,7 +1557,7 @@ flo_lt(VALUE x, VALUE y) #if MSC_VERSION_BEFORE(1300) if (isnan(a)) return Qfalse; #endif - return (a < b)?Qtrue:Qfalse; + return RBOOL(a < b); } /* @@ -1602,7 +1594,7 @@ flo_le(VALUE x, VALUE y) #if MSC_VERSION_BEFORE(1300) if (isnan(a)) return Qfalse; #endif - return (a <= b)?Qtrue:Qfalse; + return RBOOL(a <= b); } /* @@ -1627,8 +1619,7 @@ rb_float_eql(VALUE x, VALUE y) #if MSC_VERSION_BEFORE(1300) if (isnan(a) || isnan(b)) return Qfalse; #endif - if (a == b) - return Qtrue; + return RBOOL(a == b); } return Qfalse; } @@ -4094,8 +4085,7 @@ static VALUE fix_gt(VALUE x, VALUE y) { if (FIXNUM_P(y)) { - if (FIX2LONG(x) > FIX2LONG(y)) return Qtrue; - return Qfalse; + return RBOOL(FIX2LONG(x) > FIX2LONG(y)); } else if (RB_BIGNUM_TYPE_P(y)) { return RBOOL(rb_big_cmp(y, x) == INT2FIX(-1)); @@ -4133,8 +4123,7 @@ static VALUE fix_ge(VALUE x, VALUE y) { if (FIXNUM_P(y)) { - if (FIX2LONG(x) >= FIX2LONG(y)) return Qtrue; - return Qfalse; + return RBOOL(FIX2LONG(x) >= FIX2LONG(y)); } else if (RB_BIGNUM_TYPE_P(y)) { return RBOOL(rb_big_cmp(y, x) != INT2FIX(+1)); @@ -4172,8 +4161,7 @@ static VALUE fix_lt(VALUE x, VALUE y) { if (FIXNUM_P(y)) { - if (FIX2LONG(x) < FIX2LONG(y)) return Qtrue; - return Qfalse; + return RBOOL(FIX2LONG(x) < FIX2LONG(y)); } else if (RB_BIGNUM_TYPE_P(y)) { return RBOOL(rb_big_cmp(y, x) == INT2FIX(+1)); @@ -4211,8 +4199,7 @@ static VALUE fix_le(VALUE x, VALUE y) { if (FIXNUM_P(y)) { - if (FIX2LONG(x) <= FIX2LONG(y)) return Qtrue; - return Qfalse; + return RBOOL(FIX2LONG(x) <= FIX2LONG(y)); } else if (RB_BIGNUM_TYPE_P(y)) { return RBOOL(rb_big_cmp(y, x) != INT2FIX(-1)); diff --git a/re.c b/re.c index 2afa824cad..5c5b53dddc 100644 --- a/re.c +++ b/re.c @@ -1724,8 +1724,7 @@ rb_reg_nth_defined(int nth, VALUE match) nth += regs->num_regs; if (nth <= 0) return Qnil; } - if (BEG(nth) == -1) return Qfalse; - return Qtrue; + return RBOOL(BEG(nth) != -1); } VALUE @@ -3053,10 +3052,7 @@ rb_reg_equal(VALUE re1, VALUE re2) if (RREGEXP_PTR(re1)->options != RREGEXP_PTR(re2)->options) return Qfalse; if (RREGEXP_SRC_LEN(re1) != RREGEXP_SRC_LEN(re2)) return Qfalse; if (ENCODING_GET(re1) != ENCODING_GET(re2)) return Qfalse; - if (memcmp(RREGEXP_SRC_PTR(re1), RREGEXP_SRC_PTR(re2), RREGEXP_SRC_LEN(re1)) == 0) { - return Qtrue; - } - return Qfalse; + return RBOOL(memcmp(RREGEXP_SRC_PTR(re1), RREGEXP_SRC_PTR(re2), RREGEXP_SRC_LEN(re1)) == 0); } /* diff --git a/string.c b/string.c index a0cf94ca9f..267efd407c 100644 --- a/string.c +++ b/string.c @@ -4630,8 +4630,7 @@ rb_str_include_range_p(VALUE beg, VALUE end, VALUE val, VALUE exclusive) if (ISASCII(b) && ISASCII(e) && ISASCII(v)) { if (b <= v && v < e) return Qtrue; - if (!RTEST(exclusive) && v == e) return Qtrue; - return Qfalse; + return RBOOL(!RTEST(exclusive) && v == e); } } } diff --git a/thread.c b/thread.c index 7e1c1a65bb..9008467206 100644 --- a/thread.c +++ b/thread.c @@ -3370,13 +3370,7 @@ rb_thread_stop_p(VALUE thread) if (rb_threadptr_dead(th)) { return Qtrue; } - else if (th->status == THREAD_STOPPED || - th->status == THREAD_STOPPED_FOREVER) { - return Qtrue; - } - else { - return Qfalse; - } + return RBOOL(th->status == THREAD_STOPPED || th->status == THREAD_STOPPED_FOREVER); } /* @@ -3770,12 +3764,7 @@ rb_thread_key_p(VALUE self, VALUE key) if (!id || local_storage == NULL) { return Qfalse; } - else if (rb_id_table_lookup(local_storage, id, &val)) { - return Qtrue; - } - else { - return Qfalse; - } + return RBOOL(rb_id_table_lookup(local_storage, id, &val)); } static enum rb_id_table_iterator_result diff --git a/variable.c b/variable.c index 0e442241ea..aa1fdd022e 100644 --- a/variable.c +++ b/variable.c @@ -783,8 +783,7 @@ MJIT_FUNC_EXPORTED VALUE rb_gvar_defined(ID id) { struct rb_global_entry *entry = rb_global_entry(id); - if (entry->var->getter == rb_gvar_undef_getter) return Qfalse; - return Qtrue; + return RBOOL(entry->var->getter != rb_gvar_undef_getter); } rb_gvar_getter_t * @@ -1099,10 +1098,7 @@ generic_ivar_defined(VALUE obj, ID id) if (!iv_index_tbl_lookup(iv_index_tbl, id, &index)) return Qfalse; if (!gen_ivtbl_get(obj, id, &ivtbl)) return Qfalse; - if ((index < ivtbl->numiv) && (ivtbl->ivptr[index] != Qundef)) - return Qtrue; - - return Qfalse; + return RBOOL((index < ivtbl->numiv) && (ivtbl->ivptr[index] != Qundef)); } static int