Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using UNDEF_P macro #6721

Merged
merged 1 commit into from Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 9 additions & 9 deletions array.c
Expand Up @@ -4555,7 +4555,7 @@ take_items(VALUE obj, long n)
if (!NIL_P(result)) return rb_ary_subseq(result, 0, n);
result = rb_ary_new2(n);
args[0] = result; args[1] = (VALUE)n;
if (rb_check_block_call(obj, idEach, 0, 0, take_i, (VALUE)args) == Qundef)
if (UNDEF_P(rb_check_block_call(obj, idEach, 0, 0, take_i, (VALUE)args)))
rb_raise(rb_eTypeError, "wrong argument type %"PRIsVALUE" (must respond to :each)",
rb_obj_class(obj));
return result;
Expand Down Expand Up @@ -5048,7 +5048,7 @@ rb_ary_fill(int argc, VALUE *argv, VALUE ary)
ARY_SET_LEN(ary, end);
}

if (item == Qundef) {
if (UNDEF_P(item)) {
VALUE v;
long i;

Expand Down Expand Up @@ -5505,7 +5505,7 @@ rb_ary_cmp(VALUE ary1, VALUE ary2)
if (NIL_P(ary2)) return Qnil;
if (ary1 == ary2) return INT2FIX(0);
v = rb_exec_recursive_paired(recursive_cmp, ary1, ary2, ary2);
if (v != Qundef) return v;
if (!UNDEF_P(v)) return v;
len = RARRAY_LEN(ary1) - RARRAY_LEN(ary2);
if (len == 0) return INT2FIX(0);
if (len > 0) return INT2FIX(1);
Expand Down Expand Up @@ -6068,7 +6068,7 @@ rb_ary_max(int argc, VALUE *argv, VALUE ary)
if (rb_block_given_p()) {
for (i = 0; i < RARRAY_LEN(ary); i++) {
v = RARRAY_AREF(ary, i);
if (result == Qundef || rb_cmpint(rb_yield_values(2, v, result), v, result) > 0) {
if (UNDEF_P(result) || rb_cmpint(rb_yield_values(2, v, result), v, result) > 0) {
result = v;
}
}
Expand All @@ -6090,7 +6090,7 @@ rb_ary_max(int argc, VALUE *argv, VALUE ary)
}
}
}
if (result == Qundef) return Qnil;
if (UNDEF_P(result)) return Qnil;
return result;
}

Expand Down Expand Up @@ -6237,7 +6237,7 @@ rb_ary_min(int argc, VALUE *argv, VALUE ary)
if (rb_block_given_p()) {
for (i = 0; i < RARRAY_LEN(ary); i++) {
v = RARRAY_AREF(ary, i);
if (result == Qundef || rb_cmpint(rb_yield_values(2, v, result), v, result) < 0) {
if (UNDEF_P(result) || rb_cmpint(rb_yield_values(2, v, result), v, result) < 0) {
result = v;
}
}
Expand All @@ -6259,7 +6259,7 @@ rb_ary_min(int argc, VALUE *argv, VALUE ary)
}
}
}
if (result == Qundef) return Qnil;
if (UNDEF_P(result)) return Qnil;
return result;
}

Expand Down Expand Up @@ -8148,7 +8148,7 @@ finish_exact_sum(long n, VALUE r, VALUE v, int z)
{
if (n != 0)
v = rb_fix_plus(LONG2FIX(n), v);
if (r != Qundef) {
if (!UNDEF_P(r)) {
v = rb_rational_plus(r, v);
}
else if (!n && z) {
Expand Down Expand Up @@ -8227,7 +8227,7 @@ rb_ary_sum(int argc, VALUE *argv, VALUE ary)
else if (RB_BIGNUM_TYPE_P(e))
v = rb_big_plus(e, v);
else if (RB_TYPE_P(e, T_RATIONAL)) {
if (r == Qundef)
if (UNDEF_P(r))
r = e;
else
r = rb_rational_plus(r, e);
Expand Down
6 changes: 3 additions & 3 deletions class.c
Expand Up @@ -64,7 +64,7 @@ push_subclass_entry_to_list(VALUE super, VALUE klass)
void
rb_class_subclass_add(VALUE super, VALUE klass)
{
if (super && super != Qundef) {
if (super && !UNDEF_P(super)) {
rb_subclass_entry_t *entry = push_subclass_entry_to_list(super, klass);
RCLASS_SUBCLASS_ENTRY(klass) = entry;
}
Expand Down Expand Up @@ -277,7 +277,7 @@ rb_class_update_superclasses(VALUE klass)
VALUE super = RCLASS_SUPER(klass);

if (!RB_TYPE_P(klass, T_CLASS)) return;
if (super == Qundef) return;
if (UNDEF_P(super)) return;

// If the superclass array is already built
if (RCLASS_SUPERCLASSES(klass))
Expand Down Expand Up @@ -608,7 +608,7 @@ rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach)
arg.klass = clone;
rb_id_table_foreach(RCLASS_CONST_TBL(klass), clone_const_i, &arg);
}
if (attach != Qundef) {
if (!UNDEF_P(attach)) {
rb_singleton_class_attached(clone, attach);
}
RCLASS_M_TBL_INIT(clone);
Expand Down
2 changes: 1 addition & 1 deletion compar.c
Expand Up @@ -50,7 +50,7 @@ VALUE
rb_invcmp(VALUE x, VALUE y)
{
VALUE invcmp = rb_exec_recursive(invcmp_recursive, x, y);
if (invcmp == Qundef || NIL_P(invcmp)) {
if (UNDEF_P(invcmp) || NIL_P(invcmp)) {
return Qnil;
}
else {
Expand Down
4 changes: 2 additions & 2 deletions compile.c
Expand Up @@ -4820,7 +4820,7 @@ when_vals(rb_iseq_t *iseq, LINK_ANCHOR *const cond_seq, const NODE *vals,
const NODE *val = vals->nd_head;
VALUE lit = rb_node_case_when_optimizable_literal(val);

if (lit == Qundef) {
if (UNDEF_P(lit)) {
only_special_literals = 0;
}
else if (NIL_P(rb_hash_lookup(literals, lit))) {
Expand Down Expand Up @@ -7394,7 +7394,7 @@ compile_loop(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, in
ADD_LABEL(ret, end_label);
ADD_ADJUST_RESTORE(ret, adjust_label);

if (node->nd_state == Qundef) {
if (UNDEF_P(node->nd_state)) {
/* ADD_INSN(ret, line_node, putundef); */
COMPILE_ERROR(ERROR_ARGS "unsupported: putundef");
return COMPILE_NG;
Expand Down
8 changes: 4 additions & 4 deletions complex.c
Expand Up @@ -561,7 +561,7 @@ nucomp_f_complex(int argc, VALUE *argv, VALUE klass)
if (!NIL_P(opts)) {
raise = rb_opts_exception_p(opts, raise);
}
if (argc > 0 && CLASS_OF(a1) == rb_cComplex && a2 == Qundef) {
if (argc > 0 && CLASS_OF(a1) == rb_cComplex && UNDEF_P(a2)) {
return a1;
}
return nucomp_convert(rb_cComplex, a1, a2, raise);
Expand Down Expand Up @@ -2107,11 +2107,11 @@ nucomp_convert(VALUE klass, VALUE a1, VALUE a2, int raise)
}

if (RB_TYPE_P(a1, T_COMPLEX)) {
if (a2 == Qundef || (k_exact_zero_p(a2)))
if (UNDEF_P(a2) || (k_exact_zero_p(a2)))
return a1;
}

if (a2 == Qundef) {
if (UNDEF_P(a2)) {
if (k_numeric_p(a1) && !f_real_p(a1))
return a1;
/* should raise exception for consistency */
Expand All @@ -2133,7 +2133,7 @@ nucomp_convert(VALUE klass, VALUE a1, VALUE a2, int raise)
int argc;
VALUE argv2[2];
argv2[0] = a1;
if (a2 == Qundef) {
if (UNDEF_P(a2)) {
argv2[1] = Qnil;
argc = 1;
}
Expand Down
6 changes: 3 additions & 3 deletions cont.c
Expand Up @@ -1831,7 +1831,7 @@ rollback_ensure_stack(VALUE self,rb_ensure_list_t *current,rb_ensure_entry_t *ta
/* push ensure stack */
for (j = 0; j < i; j++) {
func = lookup_rollback_func(target[i - j - 1].e_proc);
if ((VALUE)func != Qundef) {
if (!UNDEF_P((VALUE)func)) {
(*func)(target[i - j - 1].data2);
}
}
Expand Down Expand Up @@ -2058,11 +2058,11 @@ rb_fiber_initialize_kw(int argc, VALUE* argv, VALUE self, int kw_splat)
argc = rb_scan_args_kw(kw_splat, argc, argv, ":", &options);
rb_get_kwargs(options, fiber_initialize_keywords, 0, 2, arguments);

if (arguments[0] != Qundef) {
if (!UNDEF_P(arguments[0])) {
blocking = arguments[0];
}

if (arguments[1] != Qundef) {
if (!UNDEF_P(arguments[1])) {
pool = arguments[1];
}
}
Expand Down
4 changes: 2 additions & 2 deletions dir.c
Expand Up @@ -2932,7 +2932,7 @@ dir_globs(VALUE args, VALUE base, int flags)
static VALUE
dir_glob_option_base(VALUE base)
{
if (base == Qundef || NIL_P(base)) {
if (UNDEF_P(base) || NIL_P(base)) {
return Qnil;
}
#if USE_OPENDIR_AT
Expand Down Expand Up @@ -3343,7 +3343,7 @@ rb_dir_s_empty_p(VALUE obj, VALUE dirname)

result = (VALUE)rb_thread_call_without_gvl(nogvl_dir_empty_p, (void *)path,
RUBY_UBF_IO, 0);
if (result == Qundef) {
if (UNDEF_P(result)) {
rb_sys_fail_path(orig);
}
return result;
Expand Down