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

ruby-changes:60988

From: Nobuyoshi <ko1@a...>
Date: Sun, 3 May 2020 14:38:03 +0900 (JST)
Subject: [ruby-changes:60988] 8af098b40e (master): Show unreserved bits only

https://git.ruby-lang.org/ruby.git/commit/?id=8af098b40e

From 8af098b40ee3788f3d13f02298eeecfb52fa0c16 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sun, 3 May 2020 14:34:46 +0900
Subject: Show unreserved bits only

`RUBY_FL_SEEN_OBJ_ID` can be set by #object_id.

diff --git a/spec/ruby/optional/capi/ext/rbasic_spec.c b/spec/ruby/optional/capi/ext/rbasic_spec.c
index 6b141de..c08c821 100644
--- a/spec/ruby/optional/capi/ext/rbasic_spec.c
+++ b/spec/ruby/optional/capi/ext/rbasic_spec.c
@@ -5,6 +5,7 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/ext/rbasic_spec.c#L5
 extern "C" {
 #endif
 
+static const VALUE VISIBLE_BITS = FL_TAINT | FL_FREEZE | ~(FL_USER0 - 1);
 
 VALUE rbasic_spec_taint_flag(VALUE self) {
   return INT2FIX(RUBY_FL_TAINT);
@@ -14,18 +15,27 @@ VALUE rbasic_spec_freeze_flag(VALUE self) { https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/ext/rbasic_spec.c#L15
   return INT2FIX(RUBY_FL_FREEZE);
 }
 
+static VALUE spec_get_flags(const struct RBasic *b) {
+  VALUE flags = b->flags & VISIBLE_BITS;
+  return INT2FIX(flags);
+}
+
+static VALUE spec_set_flags(struct RBasic *b, VALUE flags) {
+  flags &= VISIBLE_BITS;
+  b->flags = (b->flags & ~VISIBLE_BITS) | flags;
+  return INT2FIX(flags);
+}
+
 VALUE rbasic_spec_get_flags(VALUE self, VALUE val) {
-  return INT2FIX(RBASIC(val)->flags);
+  return spec_get_flags(RBASIC(val));
 }
 
 VALUE rbasic_spec_set_flags(VALUE self, VALUE val, VALUE flags) {
-  RBASIC(val)->flags = FIX2INT(flags);
-  return INT2FIX(RBASIC(val)->flags);
+  return spec_set_flags(RBASIC(val), FIX2INT(flags));
 }
 
 VALUE rbasic_spec_copy_flags(VALUE self, VALUE to, VALUE from) {
-  RBASIC(to)->flags = RBASIC(from)->flags;
-  return INT2FIX(RBASIC(to)->flags);
+  return spec_set_flags(RBASIC(to), RBASIC(from)->flags);
 }
 
 VALUE rbasic_spec_get_klass(VALUE self, VALUE val) {
@@ -33,17 +43,15 @@ VALUE rbasic_spec_get_klass(VALUE self, VALUE val) { https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/ext/rbasic_spec.c#L43
 }
 
 VALUE rbasic_rdata_spec_get_flags(VALUE self, VALUE structure) {
-  return INT2FIX(RDATA(structure)->basic.flags);
+  return spec_get_flags(&RDATA(structure)->basic);
 }
 
 VALUE rbasic_rdata_spec_set_flags(VALUE self, VALUE structure, VALUE flags) {
-  RDATA(structure)->basic.flags = FIX2INT(flags);
-  return INT2FIX(RDATA(structure)->basic.flags);
+  return spec_set_flags(&RDATA(structure)->basic, FIX2INT(flags));
 }
 
 VALUE rbasic_rdata_spec_copy_flags(VALUE self, VALUE to, VALUE from) {
-  RDATA(to)->basic.flags = RDATA(from)->basic.flags;
-  return INT2FIX(RDATA(to)->basic.flags);
+  return spec_set_flags(&RDATA(to)->basic, RDATA(from)->basic.flags);
 }
 
 VALUE rbasic_rdata_spec_get_klass(VALUE self, VALUE structure) {
diff --git a/spec/ruby/optional/capi/shared/rbasic.rb b/spec/ruby/optional/capi/shared/rbasic.rb
index c58fa0c..4076112 100644
--- a/spec/ruby/optional/capi/shared/rbasic.rb
+++ b/spec/ruby/optional/capi/shared/rbasic.rb
@@ -57,7 +57,6 @@ describe :rbasic, shared: true do https://github.com/ruby/ruby/blob/trunk/spec/ruby/optional/capi/shared/rbasic.rb#L57
   it "supports user flags" do
     obj, _ = @data.call
     initial = @specs.get_flags(obj)
-    initial.should_not == 0
     @specs.set_flags(obj, 1 << 14 | 1 << 16 | initial).should == 1 << 14 | 1 << 16 | initial
     @specs.get_flags(obj).should == 1 << 14 | 1 << 16 | initial
     @specs.set_flags(obj, initial).should == initial
-- 
cgit v0.10.2


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

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