diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-05-03 14:34:46 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-05-03 14:36:56 +0900 |
commit | 8af098b40ee3788f3d13f02298eeecfb52fa0c16 (patch) | |
tree | 32bd09f472459fc13137c305d5e33d8595357f37 | |
parent | cc6afff006760768feed4d2646a9af1dede4fca6 (diff) | |
download | ruby-8af098b40ee3788f3d13f02298eeecfb52fa0c16.tar.gz |
Show unreserved bits only
`RUBY_FL_SEEN_OBJ_ID` can be set by #object_id.
-rw-r--r-- | spec/ruby/optional/capi/ext/rbasic_spec.c | 28 | ||||
-rw-r--r-- | spec/ruby/optional/capi/shared/rbasic.rb | 1 |
2 files changed, 18 insertions, 11 deletions
diff --git a/spec/ruby/optional/capi/ext/rbasic_spec.c b/spec/ruby/optional/capi/ext/rbasic_spec.c index 6b141de587..c08c821a38 100644 --- a/spec/ruby/optional/capi/ext/rbasic_spec.c +++ b/spec/ruby/optional/capi/ext/rbasic_spec.c @@ -5,6 +5,7 @@ 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) { 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) { } 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 c58fa0c787..40761122ef 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 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 |