Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use rb_sym2str() to retrieve String object #687

Merged
merged 1 commit into from Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/oj/custom.c
Expand Up @@ -833,7 +833,7 @@ static void dump_struct(VALUE obj, int depth, Out out, bool as_ok) {
v = rb_struct_aref(obj, INT2FIX(i));
#endif
if (ma != Qnil) {
volatile VALUE s = rb_sym_to_s(rb_ary_entry(ma, i));
volatile VALUE s = rb_sym2str(rb_ary_entry(ma, i));

name = RSTRING_PTR(s);
len = (int)RSTRING_LEN(s);
Expand Down
5 changes: 1 addition & 4 deletions ext/oj/dump.c
Expand Up @@ -717,10 +717,7 @@ void oj_dump_str(VALUE obj, int depth, Out out, bool as_ok) {
}

void oj_dump_sym(VALUE obj, int depth, Out out, bool as_ok) {
// This causes a memory leak in 2.5.1. Maybe in other versions as well.
// const char *sym = rb_id2name(SYM2ID(obj));

volatile VALUE s = rb_sym_to_s(obj);
volatile VALUE s = rb_sym2str(obj);

oj_dump_cstr(RSTRING_PTR(s), (int)RSTRING_LEN(s), 0, 0, out);
}
Expand Down
4 changes: 2 additions & 2 deletions ext/oj/dump_object.c
Expand Up @@ -208,7 +208,7 @@ static void dump_str(VALUE obj, int depth, Out out, bool as_ok) {
}

static void dump_sym(VALUE obj, int depth, Out out, bool as_ok) {
volatile VALUE s = rb_sym_to_s(obj);
volatile VALUE s = rb_sym2str(obj);

oj_dump_cstr(RSTRING_PTR(s), (int)RSTRING_LEN(s), 1, 0, out);
}
Expand Down Expand Up @@ -694,7 +694,7 @@ static void dump_struct(VALUE obj, int depth, Out out, bool as_ok) {

*out->cur++ = '[';
for (i = 0; i < cnt; i++) {
volatile VALUE s = rb_sym_to_s(rb_ary_entry(ma, i));
volatile VALUE s = rb_sym2str(rb_ary_entry(ma, i));

name = RSTRING_PTR(s);
len = (int)RSTRING_LEN(s);
Expand Down
4 changes: 2 additions & 2 deletions ext/oj/parser.c
Expand Up @@ -1217,7 +1217,7 @@ static VALUE parser_new(VALUE self, VALUE mode) {

switch (rb_type(mode)) {
case RUBY_T_SYMBOL:
mode = rb_sym_to_s(mode);
mode = rb_sym2str(mode);
// fall through
case RUBY_T_STRING: ms = RSTRING_PTR(mode); break;
default:
Expand Down Expand Up @@ -1290,7 +1290,7 @@ static VALUE parser_missing(int argc, VALUE *argv, VALUE self) {
#endif
switch (rb_type(rkey)) {
case RUBY_T_SYMBOL:
rkey = rb_sym_to_s(rkey);
rkey = rb_sym2str(rkey);
// fall through
case RUBY_T_STRING: key = rb_string_value_ptr(&rkey); break;
default: rb_raise(rb_eArgError, "option method must be a symbol or string");
Expand Down
2 changes: 1 addition & 1 deletion ext/oj/rails.c
Expand Up @@ -157,7 +157,7 @@ static void dump_struct(VALUE obj, int depth, Out out, bool as_ok) {
assure_size(out, 2);
*out->cur++ = '{';
for (i = 0; i < cnt; i++) {
volatile VALUE s = rb_sym_to_s(rb_ary_entry(ma, i));
volatile VALUE s = rb_sym2str(rb_ary_entry(ma, i));

name = RSTRING_PTR(s);
len = (int)RSTRING_LEN(s);
Expand Down
4 changes: 2 additions & 2 deletions ext/oj/usual.c
Expand Up @@ -903,7 +903,7 @@ static VALUE opt_decimal_set(ojParser p, VALUE value) {
switch (rb_type(value)) {
case T_STRING: mode = RSTRING_PTR(value); break;
case T_SYMBOL:
s = rb_sym_to_s(value);
s = rb_sym2str(value);
mode = RSTRING_PTR(s);
break;
default:
Expand Down Expand Up @@ -1020,7 +1020,7 @@ static VALUE opt_missing_class_set(ojParser p, VALUE value) {
switch (rb_type(value)) {
case T_STRING: mode = RSTRING_PTR(value); break;
case T_SYMBOL:
s = rb_sym_to_s(value);
s = rb_sym2str(value);
mode = RSTRING_PTR(s);
break;
default:
Expand Down