Skip to content

Commit

Permalink
Showing 5 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions spec/ruby/optional/capi/ext/rubyspec.h
Original file line number Diff line number Diff line change
@@ -606,6 +606,7 @@
#define HAVE_RB_IS_CLASS_ID 1
#define HAVE_RB_IS_CONST_ID 1
#define HAVE_RB_IS_INSTANCE_ID 1
#define HAVE_RB_SYM2STR 1

/* Thread */
#define HAVE_RB_THREAD_ALONE 1
10 changes: 10 additions & 0 deletions spec/ruby/optional/capi/ext/symbol_spec.c
Original file line number Diff line number Diff line change
@@ -81,6 +81,12 @@ VALUE symbol_spec_rb_is_instance_id(VALUE self, VALUE sym) {
}
#endif

#ifdef HAVE_RB_SYM2STR
VALUE symbol_spec_rb_sym2str(VALUE self, VALUE sym) {
return rb_sym2str(sym);
}
#endif

void Init_symbol_spec() {
VALUE cls;
cls = rb_define_class("CApiSymbolSpecs", rb_cObject);
@@ -121,6 +127,10 @@ void Init_symbol_spec() {
#ifdef HAVE_RB_IS_INSTANCE_ID
rb_define_method(cls, "rb_is_instance_id", symbol_spec_rb_is_instance_id, 1);
#endif

#ifdef HAVE_RB_SYM2STR
rb_define_method(cls, "rb_sym2str", symbol_spec_rb_sym2str, 1);
#endif
}

#ifdef __cplusplus
6 changes: 6 additions & 0 deletions spec/ruby/optional/capi/symbol_spec.rb
Original file line number Diff line number Diff line change
@@ -104,4 +104,10 @@
@s.rb_is_class_id(:foo).should == false
end
end

describe "rb_sym2str" do
it "converts a Symbol to a String" do
@s.rb_sym2str(:bacon).should == "bacon"
end
end
end
4 changes: 4 additions & 0 deletions vm/capi/symbol.cpp
Original file line number Diff line number Diff line change
@@ -40,4 +40,8 @@ extern "C" {
Object* p = reinterpret_cast<Symbol*>(sym)->is_cvar_p(env->state());
return CBOOL(p) ? Qtrue : Qfalse;
}

VALUE rb_sym2str(VALUE sym) {
return rb_id2str(SYM2ID(sym));
}
}
2 changes: 2 additions & 0 deletions vm/include/capi/ruby/ruby.h
Original file line number Diff line number Diff line change
@@ -1585,6 +1585,8 @@ struct RTypedData {
ID rb_intern_str(VALUE string);
#define HAVE_RB_INTERN_STR 1

VALUE rb_sym2str(VALUE sym);

/** Coerce x and y and perform 'x func y' */
VALUE rb_num_coerce_bin(VALUE x, VALUE y, ID func);

0 comments on commit b7f4f94

Please sign in to comment.