Use type checking `mrb_to_str` instead of converting `mrb_str_to_str`.
MODIFY
include/mruby/string.h
include/mruby/string.h
@@ -352,6 +352,7 @@ MRB_API double mrb_str_to_dbl(mrb_state *mrb, mrb_value str, mrb_bool badcheck);
/*
* Returns a converted string type.
+ * For type checking, non converting `mrb_to_str` is recommended.
*/
MRB_API mrb_value mrb_str_to_str(mrb_state *mrb, mrb_value str);

MODIFY
mrbgems/mruby-sprintf/src/sprintf.c
mrbgems/mruby-sprintf/src/sprintf.c
@@ -552,7 +552,7 @@ mrb_str_format(mrb_state *mrb, mrb_int argc, const mrb_value *argv, mrb_value fm
++argc;
--argv;
- fmt = mrb_str_to_str(mrb, fmt);
+ mrb_to_str(mrb, fmt);
p = RSTRING_PTR(fmt);
end = p + RSTRING_LEN(fmt);
blen = 0;

MODIFY
mrbgems/mruby-struct/src/struct.c
mrbgems/mruby-struct/src/struct.c
@@ -213,7 +213,7 @@ make_struct(mrb_state *mrb, mrb_value name, mrb_value members, struct RClass *kl
}
else {
/* old style: should we warn? */
- name = mrb_str_to_str(mrb, name);
+ mrb_to_str(mrb, name);
id = mrb_obj_to_sym(mrb, name);
if (!is_const_id(mrb, mrb_sym2name_len(mrb, id, NULL))) {
mrb_name_error(mrb, id, "identifier %S needs to be constant", name);

MODIFY
src/error.c
src/error.c
@@ -28,7 +28,7 @@ mrb_exc_new(mrb_state *mrb, struct RClass *c, const char *ptr, size_t len)
MRB_API mrb_value
mrb_exc_new_str(mrb_state *mrb, struct RClass* c, mrb_value str)
{
- str = mrb_str_to_str(mrb, str);
+ mrb_to_str(mrb, str);
return mrb_obj_new(mrb, c, 1, &str);
}

MODIFY
src/string.c
src/string.c
@@ -748,9 +748,7 @@ mrb_str_to_cstr(mrb_state *mrb, mrb_value str0)
MRB_API void
mrb_str_concat(mrb_state *mrb, mrb_value self, mrb_value other)
{
- if (!mrb_string_p(other)) {
other = mrb_str_to_str(mrb, other);
- }
mrb_str_cat_str(mrb, self, other);
}
@@ -993,15 +991,15 @@ mrb_str_to_str(mrb_state *mrb, mrb_value str)
MRB_API const char*
mrb_string_value_ptr(mrb_state *mrb, mrb_value ptr)
{
- mrb_value str = mrb_str_to_str(mrb, ptr);
- return RSTRING_PTR(str);
+ mrb_to_str(mrb, ptr);
+ return RSTRING_PTR(ptr);
}
MRB_API mrb_int
mrb_string_value_len(mrb_state *mrb, mrb_value ptr)
{
- mrb_value str = mrb_str_to_str(mrb, ptr);
- return RSTRING_LEN(str);
+ mrb_to_str(mrb, ptr);
+ return RSTRING_LEN(ptr);
}
void
@@ -2183,7 +2181,7 @@ mrb_cstr_to_inum(mrb_state *mrb, const char *str, int base, int badcheck)
MRB_API const char*
mrb_string_value_cstr(mrb_state *mrb, mrb_value *ptr)
{
- mrb_value str = mrb_str_to_str(mrb, *ptr);
+ mrb_value str = mrb_to_str(mrb, *ptr);
struct RString *ps = mrb_str_ptr(str);
mrb_int len = mrb_str_strlen(mrb, ps);
char *p = RSTR_PTR(ps);
@@ -2313,7 +2311,7 @@ mrb_str_to_dbl(mrb_state *mrb, mrb_value str, mrb_bool badcheck)
char *s;
mrb_int len;
- str = mrb_str_to_str(mrb, str);
+ mrb_to_str(mrb, str);
s = RSTRING_PTR(str);
len = RSTRING_LEN(str);
if (s) {
@@ -2600,7 +2598,7 @@ mrb_str_cat_str(mrb_state *mrb, mrb_value str, mrb_value str2)
MRB_API mrb_value
mrb_str_append(mrb_state *mrb, mrb_value str1, mrb_value str2)
{
- str2 = mrb_str_to_str(mrb, str2);
+ mrb_to_str(mrb, str2);
return mrb_str_cat_str(mrb, str1, str2);
}

Use type checking `mrb_to_str` instead of converting `mrb_str_to_str`.