From 361b3efe164bd753258c7a86aff5141f1fd3ecf6 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 30 Jan 2024 14:48:59 +0900 Subject: [PATCH] Use `UNDEF_P` --- complex.c | 4 +-- insns.def | 66 +++++++++++++++++++++++----------------------- internal/numeric.h | 2 +- proc.c | 4 +-- ractor.c | 2 +- variable.c | 2 +- vm_exec.h | 4 +-- vm_insnhelper.c | 2 +- weakmap.c | 4 +-- 9 files changed, 45 insertions(+), 45 deletions(-) diff --git a/complex.c b/complex.c index 943d9e4121..dc12ac8b1b 100644 --- a/complex.c +++ b/complex.c @@ -1067,7 +1067,7 @@ complex_pow_for_special_angle(VALUE self, VALUE other) dir = 3; } - if (x == Qundef) return x; + if (UNDEF_P(x)) return x; if (f_negative_p(x)) { x = f_negate(x); @@ -1139,7 +1139,7 @@ rb_complex_pow(VALUE self, VALUE other) } VALUE result = complex_pow_for_special_angle(self, other); - if (result != Qundef) return result; + if (!UNDEF_P(result)) return result; if (RB_TYPE_P(other, T_COMPLEX)) { VALUE r, theta, nr, ntheta; diff --git a/insns.def b/insns.def index e449419708..bcc8343841 100644 --- a/insns.def +++ b/insns.def @@ -737,7 +737,7 @@ definedivar // attr bool leaf = false; { val = Qnil; - if (vm_getivar(GET_SELF(), id, GET_ISEQ(), ic, NULL, FALSE, Qundef) != Qundef) { + if (!UNDEF_P(vm_getivar(GET_SELF(), id, GET_ISEQ(), ic, NULL, FALSE, Qundef))) { val = pushval; } } @@ -842,7 +842,7 @@ send val = vm_sendish(ec, GET_CFP(), cd, bh, mexp_search_method); JIT_EXEC(ec, val); - if (val == Qundef) { + if (UNDEF_P(val)) { RESTORE_REGS(); NEXT_INSN(); } @@ -862,7 +862,7 @@ opt_send_without_block val = vm_sendish(ec, GET_CFP(), cd, bh, mexp_search_method); JIT_EXEC(ec, val); - if (val == Qundef) { + if (UNDEF_P(val)) { RESTORE_REGS(); NEXT_INSN(); } @@ -878,7 +878,7 @@ objtostring { val = vm_objtostring(GET_ISEQ(), recv, cd); - if (val == Qundef) { + if (UNDEF_P(val)) { CALL_SIMPLE_METHOD(); } } @@ -891,7 +891,7 @@ opt_str_freeze { val = vm_opt_str_freeze(str, BOP_FREEZE, idFreeze); - if (val == Qundef) { + if (UNDEF_P(val)) { PUSH(rb_str_resurrect(str)); CALL_SIMPLE_METHOD(); } @@ -906,7 +906,7 @@ opt_nil_p { val = vm_opt_nil_p(GET_ISEQ(), cd, recv); - if (val == Qundef) { + if (UNDEF_P(val)) { CALL_SIMPLE_METHOD(); } } @@ -919,7 +919,7 @@ opt_str_uminus { val = vm_opt_str_freeze(str, BOP_UMINUS, idUMinus); - if (val == Qundef) { + if (UNDEF_P(val)) { PUSH(rb_str_resurrect(str)); CALL_SIMPLE_METHOD(); } @@ -966,7 +966,7 @@ invokesuper val = vm_sendish(ec, GET_CFP(), cd, bh, mexp_search_super); JIT_EXEC(ec, val); - if (val == Qundef) { + if (UNDEF_P(val)) { RESTORE_REGS(); NEXT_INSN(); } @@ -986,7 +986,7 @@ invokeblock val = vm_sendish(ec, GET_CFP(), cd, bh, mexp_search_invokeblock); JIT_EXEC(ec, val); - if (val == Qundef) { + if (UNDEF_P(val)) { RESTORE_REGS(); NEXT_INSN(); } @@ -1144,7 +1144,7 @@ opt_plus { val = vm_opt_plus(recv, obj); - if (val == Qundef) { + if (UNDEF_P(val)) { CALL_SIMPLE_METHOD(); } } @@ -1158,7 +1158,7 @@ opt_minus { val = vm_opt_minus(recv, obj); - if (val == Qundef) { + if (UNDEF_P(val)) { CALL_SIMPLE_METHOD(); } } @@ -1172,7 +1172,7 @@ opt_mult { val = vm_opt_mult(recv, obj); - if (val == Qundef) { + if (UNDEF_P(val)) { CALL_SIMPLE_METHOD(); } } @@ -1189,7 +1189,7 @@ opt_div { val = vm_opt_div(recv, obj); - if (val == Qundef) { + if (UNDEF_P(val)) { CALL_SIMPLE_METHOD(); } } @@ -1205,7 +1205,7 @@ opt_mod { val = vm_opt_mod(recv, obj); - if (val == Qundef) { + if (UNDEF_P(val)) { CALL_SIMPLE_METHOD(); } } @@ -1219,7 +1219,7 @@ opt_eq { val = opt_equality(GET_ISEQ(), recv, obj, cd); - if (val == Qundef) { + if (UNDEF_P(val)) { CALL_SIMPLE_METHOD(); } } @@ -1233,7 +1233,7 @@ opt_neq { val = vm_opt_neq(GET_ISEQ(), cd, cd_eq, recv, obj); - if (val == Qundef) { + if (UNDEF_P(val)) { CALL_SIMPLE_METHOD(); } } @@ -1247,7 +1247,7 @@ opt_lt { val = vm_opt_lt(recv, obj); - if (val == Qundef) { + if (UNDEF_P(val)) { CALL_SIMPLE_METHOD(); } } @@ -1261,7 +1261,7 @@ opt_le { val = vm_opt_le(recv, obj); - if (val == Qundef) { + if (UNDEF_P(val)) { CALL_SIMPLE_METHOD(); } } @@ -1275,7 +1275,7 @@ opt_gt { val = vm_opt_gt(recv, obj); - if (val == Qundef) { + if (UNDEF_P(val)) { CALL_SIMPLE_METHOD(); } } @@ -1289,7 +1289,7 @@ opt_ge { val = vm_opt_ge(recv, obj); - if (val == Qundef) { + if (UNDEF_P(val)) { CALL_SIMPLE_METHOD(); } } @@ -1307,7 +1307,7 @@ opt_ltlt { val = vm_opt_ltlt(recv, obj); - if (val == Qundef) { + if (UNDEF_P(val)) { CALL_SIMPLE_METHOD(); } } @@ -1321,7 +1321,7 @@ opt_and { val = vm_opt_and(recv, obj); - if (val == Qundef) { + if (UNDEF_P(val)) { CALL_SIMPLE_METHOD(); } } @@ -1335,7 +1335,7 @@ opt_or { val = vm_opt_or(recv, obj); - if (val == Qundef) { + if (UNDEF_P(val)) { CALL_SIMPLE_METHOD(); } } @@ -1354,7 +1354,7 @@ opt_aref { val = vm_opt_aref(recv, obj); - if (val == Qundef) { + if (UNDEF_P(val)) { CALL_SIMPLE_METHOD(); } } @@ -1371,7 +1371,7 @@ opt_aset { val = vm_opt_aset(recv, obj, set); - if (val == Qundef) { + if (UNDEF_P(val)) { CALL_SIMPLE_METHOD(); } } @@ -1387,7 +1387,7 @@ opt_aset_with { VALUE tmp = vm_opt_aset_with(recv, key, val); - if (tmp != Qundef) { + if (!UNDEF_P(tmp)) { val = tmp; } else { @@ -1408,7 +1408,7 @@ opt_aref_with { val = vm_opt_aref_with(recv, key); - if (val == Qundef) { + if (UNDEF_P(val)) { PUSH(rb_str_resurrect(key)); CALL_SIMPLE_METHOD(); } @@ -1423,7 +1423,7 @@ opt_length { val = vm_opt_length(recv, BOP_LENGTH); - if (val == Qundef) { + if (UNDEF_P(val)) { CALL_SIMPLE_METHOD(); } } @@ -1437,7 +1437,7 @@ opt_size { val = vm_opt_length(recv, BOP_SIZE); - if (val == Qundef) { + if (UNDEF_P(val)) { CALL_SIMPLE_METHOD(); } } @@ -1451,7 +1451,7 @@ opt_empty_p { val = vm_opt_empty_p(recv); - if (val == Qundef) { + if (UNDEF_P(val)) { CALL_SIMPLE_METHOD(); } } @@ -1465,7 +1465,7 @@ opt_succ { val = vm_opt_succ(recv); - if (val == Qundef) { + if (UNDEF_P(val)) { CALL_SIMPLE_METHOD(); } } @@ -1479,7 +1479,7 @@ opt_not { val = vm_opt_not(GET_ISEQ(), cd, recv); - if (val == Qundef) { + if (UNDEF_P(val)) { CALL_SIMPLE_METHOD(); } } @@ -1494,7 +1494,7 @@ opt_regexpmatch2 { val = vm_opt_regexpmatch2(obj2, obj1); - if (val == Qundef) { + if (UNDEF_P(val)) { CALL_SIMPLE_METHOD(); } } diff --git a/internal/numeric.h b/internal/numeric.h index f7b8d0ad2d..b9d51116cf 100644 --- a/internal/numeric.h +++ b/internal/numeric.h @@ -158,7 +158,7 @@ rb_num_compare_with_zero(VALUE num, ID mid) { VALUE zero = INT2FIX(0); VALUE r = rb_check_funcall(num, mid, 1, &zero); - if (r == Qundef) { + if (RB_UNDEF_P(r)) { rb_cmperr(num, zero); } return r; diff --git a/proc.c b/proc.c index 84409c09f9..34d2d4e71f 100644 --- a/proc.c +++ b/proc.c @@ -1690,7 +1690,7 @@ mnew_internal(const rb_method_entry_t *me, VALUE klass, VALUE iclass, method = TypedData_Make_Struct(mclass, struct METHOD, &method_data_type, data); - if (obj == Qundef) { + if (UNDEF_P(obj)) { RB_OBJ_WRITE(method, &data->recv, Qundef); RB_OBJ_WRITE(method, &data->klass, Qundef); } @@ -3126,7 +3126,7 @@ method_inspect(VALUE method) defined_class = RBASIC_CLASS(defined_class); } - if (data->recv == Qundef) { + if (UNDEF_P(data->recv)) { // UnboundMethod rb_str_buf_append(str, rb_inspect(defined_class)); } diff --git a/ractor.c b/ractor.c index f7b251a8dc..fbdca947af 100644 --- a/ractor.c +++ b/ractor.c @@ -1670,7 +1670,7 @@ ractor_selector__wait(VALUE selv, VALUE do_receivev, VALUE do_yieldv, VALUE yiel } // check recv_queue - if (do_receive && (ret_v = ractor_try_receive(ec, cr, rq)) != Qundef) { + if (do_receive && !UNDEF_P(ret_v = ractor_try_receive(ec, cr, rq))) { ret_r = ID2SYM(rb_intern("receive")); goto success; } diff --git a/variable.c b/variable.c index 5c92fe5093..afd17bb0d8 100644 --- a/variable.c +++ b/variable.c @@ -2252,7 +2252,7 @@ rb_obj_remove_instance_variable(VALUE obj, VALUE name) if (id) { VALUE val = rb_ivar_delete(obj, id, Qundef); - if (val != Qundef) return val; + if (!UNDEF_P(val)) return val; } rb_name_err_raise("instance variable %1$s not defined", diff --git a/vm_exec.h b/vm_exec.h index 11b89c30fc..c3b7d4e488 100644 --- a/vm_exec.h +++ b/vm_exec.h @@ -167,7 +167,7 @@ default: \ // Run the interpreter from the JIT #define VM_EXEC(ec, val) do { \ - if (val == Qundef) { \ + if (UNDEF_P(val)) { \ VM_ENV_FLAGS_SET(ec->cfp->ep, VM_FRAME_FLAG_FINISH); \ val = vm_exec(ec); \ } \ @@ -177,7 +177,7 @@ default: \ #define JIT_EXEC(ec, val) do { \ rb_jit_func_t func; \ /* don't run tailcalls since that breaks FINISH */ \ - if (val == Qundef && GET_CFP() != ec->cfp && (func = jit_compile(ec))) { \ + if (UNDEF_P(val) && GET_CFP() != ec->cfp && (func = jit_compile(ec))) { \ val = func(ec, ec->cfp); \ if (ec->tag->state) THROW_EXCEPTION(val); \ } \ diff --git a/vm_insnhelper.c b/vm_insnhelper.c index edce1fbe41..ac28300257 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1343,7 +1343,7 @@ vm_getivar(VALUE obj, ID id, const rb_iseq_t *iseq, IVC ic, const struct rb_call } - if (default_value != Qundef) { + if (!UNDEF_P(default_value)) { RUBY_ASSERT(!UNDEF_P(val)); } diff --git a/weakmap.c b/weakmap.c index 7125c1707a..155312f1d4 100644 --- a/weakmap.c +++ b/weakmap.c @@ -772,7 +772,7 @@ static VALUE wkmap_aref(VALUE self, VALUE key) { VALUE obj = wkmap_lookup(self, key); - return obj != Qundef ? obj : Qnil; + return !UNDEF_P(obj) ? obj : Qnil; } struct wkmap_aset_args { @@ -927,7 +927,7 @@ wkmap_getkey(VALUE self, VALUE key) static VALUE wkmap_has_key(VALUE self, VALUE key) { - return RBOOL(wkmap_lookup(self, key) != Qundef); + return RBOOL(!UNDEF_P(wkmap_lookup(self, key))); } /*