Skip to content

Commit

Permalink
Taint flags has been deprecated in 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Jan 27, 2021
1 parent a67afaa commit b409a34
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
9 changes: 8 additions & 1 deletion spec/ruby/optional/capi/ext/object_spec.c
Expand Up @@ -15,9 +15,12 @@ static VALUE object_spec_FL_ABLE(VALUE self, VALUE obj) {

static int object_spec_FL_TEST_flag(VALUE flag_string) {
char *flag_cstr = StringValueCStr(flag_string);
#ifndef RUBY_VERSION_IS_3_1
if (strcmp(flag_cstr, "FL_TAINT") == 0) {
return FL_TAINT;
} else if (strcmp(flag_cstr, "FL_FREEZE") == 0) {
}
#endif
if (strcmp(flag_cstr, "FL_FREEZE") == 0) {
return FL_FREEZE;
}
return 0;
Expand All @@ -27,6 +30,7 @@ static VALUE object_spec_FL_TEST(VALUE self, VALUE obj, VALUE flag) {
return INT2FIX(FL_TEST(obj, object_spec_FL_TEST_flag(flag)));
}

#ifndef RUBY_VERSION_IS_3_1
static VALUE object_spec_OBJ_TAINT(VALUE self, VALUE obj) {
OBJ_TAINT(obj);
return Qnil;
Expand All @@ -40,6 +44,7 @@ static VALUE object_spec_OBJ_INFECT(VALUE self, VALUE host, VALUE source) {
OBJ_INFECT(host, source);
return Qnil;
}
#endif

static VALUE object_spec_rb_any_to_s(VALUE self, VALUE obj) {
return rb_any_to_s(obj);
Expand Down Expand Up @@ -388,9 +393,11 @@ void Init_object_spec(void) {
VALUE cls = rb_define_class("CApiObjectSpecs", rb_cObject);
rb_define_method(cls, "FL_ABLE", object_spec_FL_ABLE, 1);
rb_define_method(cls, "FL_TEST", object_spec_FL_TEST, 2);
#ifndef RUBY_VERSION_IS_3_1
rb_define_method(cls, "OBJ_TAINT", object_spec_OBJ_TAINT, 1);
rb_define_method(cls, "OBJ_TAINTED", object_spec_OBJ_TAINTED, 1);
rb_define_method(cls, "OBJ_INFECT", object_spec_OBJ_INFECT, 2);
#endif
rb_define_method(cls, "rb_any_to_s", object_spec_rb_any_to_s, 1);
rb_define_method(cls, "rb_attr_get", so_attr_get, 2);
rb_define_method(cls, "rb_obj_instance_variables", object_spec_rb_obj_instance_variables, 1);
Expand Down
4 changes: 4 additions & 0 deletions spec/ruby/optional/capi/ext/rbasic_spec.c
Expand Up @@ -22,9 +22,11 @@ static const VALUE VISIBLE_BITS = FL_FREEZE | ~(FL_USER0 - 1);
#endif


#ifndef RUBY_VERSION_IS_3_1
VALUE rbasic_spec_taint_flag(VALUE self) {
return VALUE2NUM(RUBY_FL_TAINT);
}
#endif

VALUE rbasic_spec_freeze_flag(VALUE self) {
return VALUE2NUM(RUBY_FL_FREEZE);
Expand Down Expand Up @@ -75,7 +77,9 @@ VALUE rbasic_rdata_spec_get_klass(VALUE self, VALUE structure) {

void Init_rbasic_spec(void) {
VALUE cls = rb_define_class("CApiRBasicSpecs", rb_cObject);
#ifndef RUBY_VERSION_IS_3_1
rb_define_method(cls, "taint_flag", rbasic_spec_taint_flag, 0);
#endif
rb_define_method(cls, "freeze_flag", rbasic_spec_freeze_flag, 0);
rb_define_method(cls, "get_flags", rbasic_spec_get_flags, 1);
rb_define_method(cls, "set_flags", rbasic_spec_set_flags, 2);
Expand Down
4 changes: 4 additions & 0 deletions spec/ruby/optional/capi/ext/rubyspec.h
Expand Up @@ -22,6 +22,10 @@
(RUBY_VERSION_MAJOR == (major) && RUBY_VERSION_MINOR < (minor)) || \
(RUBY_VERSION_MAJOR == (major) && RUBY_VERSION_MINOR == (minor) && RUBY_VERSION_TEENY < (teeny)))

#if RUBY_VERSION_MAJOR > 3 || (RUBY_VERSION_MAJOR == 3 && RUBY_VERSION_MINOR >= 1)
#define RUBY_VERSION_IS_3_1
#endif

#if RUBY_VERSION_MAJOR > 3 || (RUBY_VERSION_MAJOR == 3 && RUBY_VERSION_MINOR >= 0)
#define RUBY_VERSION_IS_3_0
#endif
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/optional/capi/shared/rbasic.rb
Expand Up @@ -2,7 +2,7 @@

before :all do
specs = CApiRBasicSpecs.new
@taint = specs.taint_flag
@taint = ruby_version_is(''...'3.1') ? specs.taint_flag : 0
@freeze = specs.freeze_flag
end

Expand Down

0 comments on commit b409a34

Please sign in to comment.