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

make Rbx API compatible #2

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions ext/iconv/iconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ rb_sprintf(const char *format, ...)
}
#endif

#define rb_sys_fail_str(s) rb_iconv_sys_fail_str(s)
#define rb_sys_fail(s) rb_iconv_sys_fail(s)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you moved these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dynamic library loader didn't find the rb_sys_fail_str definition, because it was defined after the usage.

I put the lines up and worked.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will put it close from function calls.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rb_iconv_sys_fail_str uses rb_sys_fail_str, so this is incorrect.
This should check whether rb_sys_fail_str exists or not, and define it if not exist.

/*
* Document-class: Iconv
*
Expand Down Expand Up @@ -217,16 +220,27 @@ map_charset(VALUE *code)
VALUE val = StringValue(*code);

if (RHASH_SIZE(charset_map)) {
#ifdef RBX_CAPI_RUBY_H /* If Rubinius defined */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can always use rb_hash_aref; so remove ifdef and RHASH_TBL.
(RHASH_TBL is faster than rb_hash_aref, but this code doesn't need speed)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this at 3503301

VALUE data;
VALUE key = rb_funcall2(val, rb_intern("downcase"), 0, 0);
StringValuePtr(key);
data = rb_hash_aref(charset_map, key);
if(!NIL_P(data)) {
*code = (VALUE)data;
}
#else
st_data_t data;
VALUE key = rb_funcall2(val, rb_intern("downcase"), 0, 0);
StringValuePtr(key);
if (st_lookup(RHASH_TBL(charset_map), key, &data)) {
*code = (VALUE)data;
}
#endif
}
return StringValuePtr(*code);
}


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this empty line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I will fix it.

NORETURN(static void rb_iconv_sys_fail_str(VALUE msg));
static void
rb_iconv_sys_fail_str(VALUE msg)
Expand All @@ -237,7 +251,6 @@ rb_iconv_sys_fail_str(VALUE msg)
rb_sys_fail_str(msg);
}

#define rb_sys_fail_str(s) rb_iconv_sys_fail_str(s)

NORETURN(static void rb_iconv_sys_fail(const char *s));
static void
Expand All @@ -246,7 +259,6 @@ rb_iconv_sys_fail(const char *s)
rb_iconv_sys_fail_str(rb_str_new_cstr(s));
}

#define rb_sys_fail(s) rb_iconv_sys_fail(s)

static iconv_t
iconv_create(VALUE to, VALUE from, struct rb_iconv_opt_t *opt, int *idx)
Expand Down