ruby-changes:68230
From: S.H <ko1@a...>
Date: Sun, 3 Oct 2021 22:35:03 +0900 (JST)
Subject: [ruby-changes:68230] dc9112cf10 (master): Using NIL_P macro instead of `== Qnil`
https://git.ruby-lang.org/ruby.git/commit/?id=dc9112cf10 From dc9112cf10e63b5272e9469d080d5d1ced30276e Mon Sep 17 00:00:00 2001 From: "S.H" <gamelinks007@g...> Date: Sun, 3 Oct 2021 22:34:45 +0900 Subject: Using NIL_P macro instead of `== Qnil` --- array.c | 6 +++--- compile.c | 2 +- dir.c | 2 +- enum.c | 4 ++-- error.c | 2 +- gc.c | 8 ++++---- io.c | 2 +- iseq.c | 8 ++++---- marshal.c | 2 +- range.c | 4 ++-- re.c | 10 +++++----- struct.c | 4 ++-- thread.c | 2 +- transcode.c | 4 ++-- vm.c | 14 +++++++------- vm_args.c | 2 +- vm_backtrace.c | 6 +++--- vm_insnhelper.c | 4 ++-- 18 files changed, 43 insertions(+), 43 deletions(-) diff --git a/array.c b/array.c index 63d63aa17f..3e949cfa79 100644 --- a/array.c +++ b/array.c @@ -3466,7 +3466,7 @@ rb_ary_bsearch_index(VALUE ary) https://github.com/ruby/ruby/blob/trunk/array.c#L3466 satisfied = 1; smaller = 1; } - else if (v == Qfalse || v == Qnil) { + else if (!RTEST(v)) { smaller = 0; } else if (rb_obj_is_kind_of(v, rb_cNumeric)) { @@ -6479,7 +6479,7 @@ rb_ary_cycle_size(VALUE self, VALUE args, VALUE eobj) https://github.com/ruby/ruby/blob/trunk/array.c#L6479 n = RARRAY_AREF(args, 0); } if (RARRAY_LEN(self) == 0) return INT2FIX(0); - if (n == Qnil) return DBL2NUM(HUGE_VAL); + if (NIL_P(n)) return DBL2NUM(HUGE_VAL); mul = NUM2LONG(n); if (mul <= 0) return INT2FIX(0); n = LONG2FIX(mul); @@ -7344,7 +7344,7 @@ rb_ary_drop(VALUE ary, VALUE n) https://github.com/ruby/ruby/blob/trunk/array.c#L7344 } result = rb_ary_subseq(ary, pos, RARRAY_LEN(ary)); - if (result == Qnil) result = rb_ary_new(); + if (NIL_P(result)) result = rb_ary_new(); return result; } diff --git a/compile.c b/compile.c index 268bd8b6a6..9d34ccbf05 100644 --- a/compile.c +++ b/compile.c @@ -9934,7 +9934,7 @@ iseq_build_from_ary_exception(rb_iseq_t *iseq, struct st_table *labels_table, https://github.com/ruby/ruby/blob/trunk/compile.c#L9934 rb_raise(rb_eSyntaxError, "wrong exception entry"); } type = get_exception_sym2type(RARRAY_AREF(v, 0)); - if (RARRAY_AREF(v, 1) == Qnil) { + if (NIL_P(RARRAY_AREF(v, 1))) { eiseq = NULL; } else { diff --git a/dir.c b/dir.c index 32bce9f2b6..4e552d772a 100644 --- a/dir.c +++ b/dir.c @@ -989,7 +989,7 @@ chdir_yield(VALUE v) https://github.com/ruby/ruby/blob/trunk/dir.c#L989 dir_chdir(args->new_path); args->done = TRUE; chdir_blocking++; - if (chdir_thread == Qnil) + if (NIL_P(chdir_thread)) chdir_thread = rb_thread_current(); return rb_yield(args->new_path); } diff --git a/enum.c b/enum.c index 7528eb88c0..b1a21b62eb 100644 --- a/enum.c +++ b/enum.c @@ -2921,7 +2921,7 @@ enum_each_slice_size(VALUE obj, VALUE args, VALUE eobj) https://github.com/ruby/ruby/blob/trunk/enum.c#L2921 if (slice_size <= 0) rb_raise(rb_eArgError, "invalid slice size"); size = enum_size(obj, 0, 0); - if (size == Qnil) return Qnil; + if (NIL_P(size)) return Qnil; if (RB_FLOAT_TYPE_P(size) && RTEST(rb_funcall(size, infinite_p, 0))) { return size; } @@ -3003,7 +3003,7 @@ enum_each_cons_size(VALUE obj, VALUE args, VALUE eobj) https://github.com/ruby/ruby/blob/trunk/enum.c#L3003 if (cons_size <= 0) rb_raise(rb_eArgError, "invalid size"); size = enum_size(obj, 0, 0); - if (size == Qnil) return Qnil; + if (NIL_P(size)) return Qnil; n = add_int(size, 1 - cons_size); return (OPTIMIZED_CMP(n, zero, cmp_opt) == -1) ? zero : n; diff --git a/error.c b/error.c index 84902204d2..65bf1721a2 100644 --- a/error.c +++ b/error.c @@ -1986,7 +1986,7 @@ name_err_mesg_to_str(VALUE obj) https://github.com/ruby/ruby/blob/trunk/error.c#L1986 break; default: d = rb_protect(name_err_mesg_receiver_name, obj, &state); - if (state || d == Qundef || d == Qnil) + if (state || d == Qundef || NIL_P(d)) d = rb_protect(rb_inspect, obj, &state); if (state) { rb_set_errinfo(Qnil); diff --git a/gc.c b/gc.c index 8a49a6453e..76a5df27a6 100644 --- a/gc.c +++ b/gc.c @@ -4354,7 +4354,7 @@ id2ref(VALUE objid) https://github.com/ruby/ruby/blob/trunk/gc.c#L4354 ptr = NUM2PTR(objid); if (ptr == Qtrue) return Qtrue; if (ptr == Qfalse) return Qfalse; - if (ptr == Qnil) return Qnil; + if (NIL_P(ptr)) return Qnil; if (FIXNUM_P(ptr)) return (VALUE)ptr; if (FLONUM_P(ptr)) return (VALUE)ptr; @@ -4802,7 +4802,7 @@ count_objects(int argc, VALUE *argv, VALUE os) https://github.com/ruby/ruby/blob/trunk/gc.c#L4802 total += page->total_slots; } - if (hash == Qnil) { + if (NIL_P(hash)) { hash = rb_hash_new(); } else if (!RHASH_EMPTY_P(hash)) { @@ -8784,7 +8784,7 @@ rb_gc_register_mark_object(VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L8784 VALUE ary_ary = GET_VM()->mark_object_ary; VALUE ary = rb_ary_last(0, 0, ary_ary); - if (ary == Qnil || RARRAY_LEN(ary) >= MARK_OBJECT_ARY_BUCKET_SIZE) { + if (NIL_P(ary) || RARRAY_LEN(ary) >= MARK_OBJECT_ARY_BUCKET_SIZE) { ary = rb_ary_tmp_new(MARK_OBJECT_ARY_BUCKET_SIZE); rb_ary_push(ary_ary, ary); } @@ -10383,7 +10383,7 @@ gc_info_decode(rb_objspace_t *objspace, const VALUE hash_or_key, const unsigned https://github.com/ruby/ruby/blob/trunk/gc.c#L10383 rb_raise(rb_eTypeError, "non-hash or symbol given"); } - if (sym_major_by == Qnil) { + if (NIL_P(sym_major_by)) { #define S(s) sym_##s = ID2SYM(rb_intern_const(#s)) S(major_by); S(gc_by); diff --git a/io.c b/io.c index 0e11b8ad9a..5ad2b6474c 100644 --- a/io.c +++ b/io.c @@ -10634,7 +10634,7 @@ rb_io_s_pipe(int argc, VALUE *argv, VALUE klass) https://github.com/ruby/ruby/blob/trunk/io.c#L10634 extract_binmode(opt, &fmode); - if ((fmode & FMODE_BINMODE) && v1 == Qnil) { + if ((fmode & FMODE_BINMODE) && NIL_P(v1)) { rb_io_ascii8bit_binmode(r); rb_io_ascii8bit_binmode(w); } diff --git a/iseq.c b/iseq.c index d3bd4a22f3..e04642fd92 100644 --- a/iseq.c +++ b/iseq.c @@ -503,7 +503,7 @@ rb_iseq_pathobj_new(VALUE path, VALUE realpath) https://github.com/ruby/ruby/blob/trunk/iseq.c#L503 { VALUE pathobj; VM_ASSERT(RB_TYPE_P(path, T_STRING)); - VM_ASSERT(realpath == Qnil || RB_TYPE_P(realpath, T_STRING)); + VM_ASSERT(NIL_P(realpath) || RB_TYPE_P(realpath, T_STRING)); if (path == realpath || (!NIL_P(realpath) && rb_str_cmp(path, realpath) == 0)) { @@ -759,7 +759,7 @@ rb_iseq_make_compile_option(rb_compile_option_t *option, VALUE opt) https://github.com/ruby/ruby/blob/trunk/iseq.c#L759 static void make_compile_option(rb_compile_option_t *option, VALUE opt) { - if (opt == Qnil) { + if (NIL_P(opt)) { *option = COMPILE_OPTION_DEFAULT; } else if (opt == Qfalse) { @@ -2413,7 +2413,7 @@ iseq_iterate_children(const rb_iseq_t *iseq, void (*iter_func)(const rb_iseq_t * https://github.com/ruby/ruby/blob/trunk/iseq.c#L2413 UNALIGNED_MEMBER_PTR(body->catch_table, entries[i]); child = entry->iseq; if (child) { - if (rb_hash_aref(all_children, (VALUE)child) == Qnil) { + if (NIL_P(rb_hash_aref(all_children, (VALUE)child))) { rb_hash_aset(all_children, (VALUE)child, Qtrue); (*iter_func)(child, data); } @@ -2432,7 +2432,7 @@ iseq_iterate_children(const rb_iseq_t *iseq, void (*iter_func)(const rb_iseq_t * https://github.com/ruby/ruby/blob/trunk/iseq.c#L2432 case TS_ISEQ: child = (const rb_iseq_t *)code[i+j+1]; if (child) { - if (rb_hash_aref(all_children, (VALUE)child) == Qnil) { + if (NIL_P(rb_hash_aref(all_children, (VALUE)child))) { rb_hash_aset(all_children, (VALUE)child, Qtrue); (*iter_func)(child, data); } diff --git a/marshal.c b/marshal.c index acaa27a419..d8fcf56685 100644 --- a/marshal.c +++ b/marshal.c @@ -777,7 +777,7 @@ w_object(VALUE obj, struct dump_arg *arg, int limit) https://github.com/ruby/ruby/blob/trunk/marshal.c#L777 return; } - if (obj == Qnil) { + if (NIL_P(obj)) { w_byte(TYPE_NIL, arg); } else if (obj == Qtrue) { diff --git a/range.c b/range.c index 6f44e82600..31f734181d 100644 --- a/range.c +++ b/range.c @@ -642,7 +642,7 @@ bsearch_integer_range(VALUE beg, VALUE end, int excl) https://github.com/ruby/ruby/blob/trunk/range.c#L642 satisfied = val; \ smaller = 1; \ } \ - else if (v == Qfalse || v == Qnil) { \ + else if (!RTEST(v)) { \ smaller = 0; \ } \ else if (rb_obj_is_kind_of(v, rb_cNumeric)) { \ @@ -1952,7 +1952,7 @@ r_cover_range_p(VALUE range, VALUE beg, VALUE end, VALUE val) https://github.com/ruby/ruby/blob/trunk/range.c#L1952 } val_max = rb_rescue2(r_call_max, val, 0, Qnil, rb_eTypeError, (VALUE)0); - if (val_max == Qnil) return FALSE; + if (NIL_P(val_max)) return FALSE; return r_less(end, val_max) >= 0; } diff --git a/re.c b/re.c index 58e43f9c29..cccedc9869 100644 --- a/re.c +++ b/re.c @@ -1557,7 +1557,7 @@ rb_reg_prepare_re0(VALUE re, VALUE str, onig_errmsg_buffer err) https://github.com/ruby/ruby/blob/trunk/re.c#L1557 pattern, pattern + RREGEXP_SRC_LEN(re), enc, &fixed_enc, err); - if (unescaped == Qnil) { + if (NIL_P(unescaped)) { rb_raise(rb_eArgError, "regexp preprocess failed: %s", err); } @@ -2357,7 +2357,7 @@ match_inspect(VALUE match) https://github.com/ruby/ruby/blob/trunk/re.c#L2357 rb_str_buf_cat2(str, ":"); } v = rb_reg_nth_match(i, match); - if (v == Qnil) + if (NIL_P(v)) rb_str_buf_cat2(str, "nil"); else rb_str_buf_append(str, rb_s (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/