[前][次][番号順一覧][スレッド一覧]

ruby-changes:70684

From: Nobuyoshi <ko1@a...>
Date: Sat, 1 Jan 2022 18:54:10 +0900 (JST)
Subject: [ruby-changes:70684] 069cca6f74 (master): Negative RBOOL usage

https://git.ruby-lang.org/ruby.git/commit/?id=069cca6f74

From 069cca6f7459da5cc502d0c51f60a9813c611b31 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sat, 1 Jan 2022 15:41:00 +0900
Subject: Negative RBOOL usage

---
 cont.c          | 2 +-
 dir.c           | 2 +-
 gc.c            | 4 ++--
 io.c            | 2 +-
 numeric.c       | 2 +-
 object.c        | 8 ++++----
 proc.c          | 2 +-
 vm_insnhelper.c | 4 ++--
 vm_method.c     | 2 +-
 9 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/cont.c b/cont.c
index 4b18ddda67a..96654733f8e 100644
--- a/cont.c
+++ b/cont.c
@@ -2483,7 +2483,7 @@ rb_fiber_reset_root_local_storage(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/cont.c#L2483
 VALUE
 rb_fiber_alive_p(VALUE fiber_value)
 {
-    return FIBER_TERMINATED_P(fiber_ptr(fiber_value)) ? Qfalse : Qtrue;
+    return RBOOL(!FIBER_TERMINATED_P(fiber_ptr(fiber_value)));
 }
 
 /*
diff --git a/dir.c b/dir.c
index 1a3ba820708..8bd03679f18 100644
--- a/dir.c
+++ b/dir.c
@@ -3323,7 +3323,7 @@ rb_dir_s_empty_p(VALUE obj, VALUE dirname) https://github.com/ruby/ruby/blob/trunk/dir.c#L3323
 	    al.dirattr = ATTR_DIR_ENTRYCOUNT;
 	    if (getattrlist(path, &al, attrbuf, sizeof(attrbuf), 0) == 0) {
 		if (attrbuf[0] >= 2 * sizeof(u_int32_t))
-		    return attrbuf[1] ? Qfalse : Qtrue;
+		    return RBOOL(attrbuf[1] == 0);
 		if (false_on_notdir) return Qfalse;
 	    }
 	    rb_sys_fail_path(orig);
diff --git a/gc.c b/gc.c
index bbc5c40e90a..0f44ff5c985 100644
--- a/gc.c
+++ b/gc.c
@@ -8600,7 +8600,7 @@ rb_copy_wb_protected_attribute(VALUE dest, VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L8600
 VALUE
 rb_obj_rgengc_writebarrier_protected_p(VALUE obj)
 {
-    return RVALUE_WB_UNPROTECTED(obj) ? Qfalse : Qtrue;
+    return RBOOL(!RVALUE_WB_UNPROTECTED(obj));
 }
 
 VALUE
@@ -12343,7 +12343,7 @@ wmap_aref(VALUE self, VALUE key) https://github.com/ruby/ruby/blob/trunk/gc.c#L12343
 static VALUE
 wmap_has_key(VALUE self, VALUE key)
 {
-    return wmap_lookup(self, key) == Qundef ? Qfalse : Qtrue;
+    return RBOOL(wmap_lookup(self, key) != Qundef);
 }
 
 /* Returns the number of referenced objects */
diff --git a/io.c b/io.c
index 3fab54e4067..67d865650c9 100644
--- a/io.c
+++ b/io.c
@@ -8933,7 +8933,7 @@ rb_io_autoclose_p(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L8933
 {
     rb_io_t *fptr = RFILE(io)->fptr;
     rb_io_check_closed(fptr);
-    return (fptr->mode & FMODE_PREP) ? Qfalse : Qtrue;
+    return RBOOL(!(fptr->mode & FMODE_PREP));
 }
 
 /*
diff --git a/numeric.c b/numeric.c
index 9d5695de237..3165556a7f7 100644
--- a/numeric.c
+++ b/numeric.c
@@ -3657,7 +3657,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/numeric.c#L3657
 int_anybits_p(VALUE num, VALUE mask)
 {
     mask = rb_to_int(mask);
-    return int_zero_p(rb_int_and(num, mask)) ? Qfalse : Qtrue;
+    return RBOOL(!int_zero_p(rb_int_and(num, mask)));
 }
 
 /*
diff --git a/object.c b/object.c
index a34d971606f..49315c566cd 100644
--- a/object.c
+++ b/object.c
@@ -204,7 +204,7 @@ VALUE rb_obj_hash(VALUE obj); https://github.com/ruby/ruby/blob/trunk/object.c#L204
 MJIT_FUNC_EXPORTED VALUE
 rb_obj_not(VALUE obj)
 {
-    return RTEST(obj) ? Qfalse : Qtrue;
+    return RBOOL(!RTEST(obj));
 }
 
 /**
@@ -221,7 +221,7 @@ MJIT_FUNC_EXPORTED VALUE https://github.com/ruby/ruby/blob/trunk/object.c#L221
 rb_obj_not_equal(VALUE obj1, VALUE obj2)
 {
     VALUE result = rb_funcall(obj1, id_eq, 1, obj2);
-    return RTEST(result) ? Qfalse : Qtrue;
+    return rb_obj_not(result);
 }
 
 VALUE
@@ -1295,7 +1295,7 @@ true_or(VALUE obj, VALUE obj2) https://github.com/ruby/ruby/blob/trunk/object.c#L1295
 static VALUE
 true_xor(VALUE obj, VALUE obj2)
 {
-    return RTEST(obj2)?Qfalse:Qtrue;
+    return rb_obj_not(obj2);
 }
 
 
@@ -1426,7 +1426,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/object.c#L1426
 rb_obj_not_match(VALUE obj1, VALUE obj2)
 {
     VALUE result = rb_funcall(obj1, id_match, 1, obj2);
-    return RTEST(result) ? Qfalse : Qtrue;
+    return rb_obj_not(result);
 }
 
 
diff --git a/proc.c b/proc.c
index 6cdd7bd836b..ab6cce8fb88 100644
--- a/proc.c
+++ b/proc.c
@@ -1604,7 +1604,7 @@ respond_to_missing_p(VALUE klass, VALUE obj, VALUE sym, int scope) https://github.com/ruby/ruby/blob/trunk/proc.c#L1604
 
     if (obj == Qundef) return 0;
     if (rb_method_basic_definition_p(klass, rmiss)) return 0;
-    return RTEST(rb_funcall(obj, rmiss, 2, sym, scope ? Qfalse : Qtrue));
+    return RTEST(rb_funcall(obj, rmiss, 2, sym, RBOOL(!scope)));
 }
 
 
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index e01d39de77a..271b347d3bc 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -5205,7 +5205,7 @@ vm_opt_neq(const rb_iseq_t *iseq, CALL_DATA cd, CALL_DATA cd_eq, VALUE recv, VAL https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L5205
         VALUE val = opt_equality(iseq, recv, obj, cd_eq);
 
 	if (val != Qundef) {
-	    return RTEST(val) ? Qfalse : Qtrue;
+	    return RBOOL(!RTEST(val));
 	}
     }
 
@@ -5538,7 +5538,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L5538
 vm_opt_not(const rb_iseq_t *iseq, CALL_DATA cd, VALUE recv)
 {
     if (vm_method_cfunc_is(iseq, cd, recv, rb_obj_not)) {
-	return RTEST(recv) ? Qfalse : Qtrue;
+	return RBOOL(!RTEST(recv));
     }
     else {
 	return Qundef;
diff --git a/vm_method.c b/vm_method.c
index 38d03fbe2ba..6867b5cf8c5 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -2678,7 +2678,7 @@ basic_obj_respond_to(rb_execution_context_t *ec, VALUE obj, ID id, int pub) https://github.com/ruby/ruby/blob/trunk/vm_method.c#L2678
 	return FALSE;
       case 0:
 	ret = basic_obj_respond_to_missing(ec, klass, obj, ID2SYM(id),
-					   pub ? Qfalse : Qtrue);
+					   RBOOL(!pub));
 	return RTEST(ret) && ret != Qundef;
       default:
 	return TRUE;
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]