1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Show unreserved bits only

`RUBY_FL_SEEN_OBJ_ID` can be set by #object_id.
This commit is contained in:
Nobuyoshi Nakada 2020-05-03 14:34:46 +09:00
parent cc6afff006
commit 8af098b40e
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6
2 changed files with 18 additions and 11 deletions

View file

@ -5,6 +5,7 @@
extern "C" { extern "C" {
#endif #endif
static const VALUE VISIBLE_BITS = FL_TAINT | FL_FREEZE | ~(FL_USER0 - 1);
VALUE rbasic_spec_taint_flag(VALUE self) { VALUE rbasic_spec_taint_flag(VALUE self) {
return INT2FIX(RUBY_FL_TAINT); return INT2FIX(RUBY_FL_TAINT);
@ -14,18 +15,27 @@ VALUE rbasic_spec_freeze_flag(VALUE self) {
return INT2FIX(RUBY_FL_FREEZE); 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) { 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) { VALUE rbasic_spec_set_flags(VALUE self, VALUE val, VALUE flags) {
RBASIC(val)->flags = FIX2INT(flags); return spec_set_flags(RBASIC(val), FIX2INT(flags));
return INT2FIX(RBASIC(val)->flags);
} }
VALUE rbasic_spec_copy_flags(VALUE self, VALUE to, VALUE from) { VALUE rbasic_spec_copy_flags(VALUE self, VALUE to, VALUE from) {
RBASIC(to)->flags = RBASIC(from)->flags; return spec_set_flags(RBASIC(to), RBASIC(from)->flags);
return INT2FIX(RBASIC(to)->flags);
} }
VALUE rbasic_spec_get_klass(VALUE self, VALUE val) { 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) { 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) { VALUE rbasic_rdata_spec_set_flags(VALUE self, VALUE structure, VALUE flags) {
RDATA(structure)->basic.flags = FIX2INT(flags); return spec_set_flags(&RDATA(structure)->basic, FIX2INT(flags));
return INT2FIX(RDATA(structure)->basic.flags);
} }
VALUE rbasic_rdata_spec_copy_flags(VALUE self, VALUE to, VALUE from) { VALUE rbasic_rdata_spec_copy_flags(VALUE self, VALUE to, VALUE from) {
RDATA(to)->basic.flags = RDATA(from)->basic.flags; return spec_set_flags(&RDATA(to)->basic, RDATA(from)->basic.flags);
return INT2FIX(RDATA(to)->basic.flags);
} }
VALUE rbasic_rdata_spec_get_klass(VALUE self, VALUE structure) { VALUE rbasic_rdata_spec_get_klass(VALUE self, VALUE structure) {

View file

@ -57,7 +57,6 @@ describe :rbasic, shared: true do
it "supports user flags" do it "supports user flags" do
obj, _ = @data.call obj, _ = @data.call
initial = @specs.get_flags(obj) 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.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.get_flags(obj).should == 1 << 14 | 1 << 16 | initial
@specs.set_flags(obj, initial).should == initial @specs.set_flags(obj, initial).should == initial