Make sure all Ruby strings are created as UTF-8

This commit is contained in:
Struma 2021-03-02 03:26:51 -05:00 committed by Roza
parent 244421bac6
commit db919e9f29
6 changed files with 27 additions and 27 deletions

View file

@ -169,7 +169,7 @@ static void mriBindingInit() {
_rb_define_module_function(rb_mKernel, "msgbox", mriPrint);
_rb_define_module_function(rb_mKernel, "msgbox_p", mriP);
rb_define_global_const("RGSS_VERSION", rb_str_new_cstr("3.0.1"));
rb_define_global_const("RGSS_VERSION", rb_utf8_str_new_cstr("3.0.1"));
} else {
_rb_define_module_function(rb_mKernel, "print", mriPrint);
_rb_define_module_function(rb_mKernel, "p", mriP);
@ -210,7 +210,7 @@ static void mriBindingInit() {
/* Load global constants */
rb_gv_set("MKXP", Qtrue);
rb_const_set(mod, rb_intern("VERSION"), rb_str_new_cstr(MACRO_STRINGIFY(MKXPZ_VERSION)));
rb_const_set(mod, rb_intern("VERSION"), rb_utf8_str_new_cstr(MACRO_STRINGIFY(MKXPZ_VERSION)));
VALUE debug = rb_bool_new(shState->config().editor.debug);
if (rgssVer == 1)
@ -276,7 +276,7 @@ RB_METHOD(mkxpDataDirectory) {
const char *s = path.empty() ? "." : path.c_str();
std::string s_nml = shState->fileSystem().normalize(s, 1, 1);
VALUE ret = rb_str_new_cstr(s_nml.c_str());
VALUE ret = rb_utf8_str_new_cstr(s_nml.c_str());
return ret;
}
@ -299,7 +299,7 @@ RB_METHOD(mkxpDesensitize) {
rb_scan_args(argc, argv, "1", &filename);
SafeStringValue(filename);
return rb_str_new_cstr(
return rb_utf8_str_new_cstr(
shState->fileSystem().desensitize(RSTRING_PTR(filename)));
}
@ -333,25 +333,25 @@ RB_METHOD(mkxpMouseInWindow) {
RB_METHOD(mkxpPlatform) {
RB_UNUSED_PARAM;
return rb_str_new_cstr(SDL_GetPlatform());
return rb_utf8_str_new_cstr(SDL_GetPlatform());
}
RB_METHOD(mkxpUserLanguage) {
RB_UNUSED_PARAM;
return rb_str_new_cstr(mkxp_sys::getSystemLanguage().c_str());
return rb_utf8_str_new_cstr(mkxp_sys::getSystemLanguage().c_str());
}
RB_METHOD(mkxpUserName) {
RB_UNUSED_PARAM;
return rb_str_new_cstr(mkxp_sys::getUserName().c_str());
return rb_utf8_str_new_cstr(mkxp_sys::getUserName().c_str());
}
RB_METHOD(mkxpGameTitle) {
RB_UNUSED_PARAM;
return rb_str_new_cstr(shState->config().game.title.c_str());
return rb_utf8_str_new_cstr(shState->config().game.title.c_str());
}
RB_METHOD(mkxpPowerState) {
@ -516,7 +516,7 @@ RB_METHOD(_kernelCaller) {
return trace;
/* RMXP does this, not sure if specific or 1.8 related */
VALUE args[] = {rb_str_new_cstr(":in `<main>'"), rb_str_new_cstr("")};
VALUE args[] = {rb_utf8_str_new_cstr(":in `<main>'"), rb_utf8_str_new_cstr("")};
rb_funcall2(rb_ary_entry(trace, len - 1), rb_intern("gsub!"), 2, args);
return trace;
@ -567,7 +567,7 @@ struct BacktraceData {
bool evalScript(VALUE string, const char *filename)
{
int state;
evalString(string, rb_str_new_cstr(filename), &state);
evalString(string, rb_utf8_str_new_cstr(filename), &state);
if (state) return false;
return true;
}
@ -654,7 +654,7 @@ static void runRMXPScripts(BacktraceData &btData) {
break;
}
rb_ary_store(script, 3, rb_str_new_cstr(decodeBuffer.c_str()));
rb_ary_store(script, 3, rb_utf8_str_new_cstr(decodeBuffer.c_str()));
}
// Can be force-disabled similarly to framerate options
@ -882,7 +882,7 @@ static void mriBindingExecute() {
}
#ifndef WORKDIR_CURRENT
else {
rb_ary_push(lpaths, rb_str_new_cstr(mkxp_fs::getCurrentDirectory().c_str()));
rb_ary_push(lpaths, rb_utf8_str_new_cstr(mkxp_fs::getCurrentDirectory().c_str()));
}
#endif

View file

@ -169,7 +169,7 @@ return Data_Wrap_Struct(klass, 0, free, 0); \
#define DEF_ALLOCFUNC(type) DEF_ALLOCFUNC_CUSTOMFREE(type, freeInstance<type>)
#if RAPI_MINOR < 9
#define rb_str_new_cstr rb_str_new2
#define rb_utf8_str_new_cstr rb_str_new2
#endif
#define PRIsVALUE "s"

View file

@ -252,12 +252,12 @@ void fontBindingInit() {
VALUE defNamesObj;
if (defNames.size() == 1) {
defNamesObj = rb_str_new_cstr(defNames[0].c_str());
defNamesObj = rb_utf8_str_new_cstr(defNames[0].c_str());
} else {
defNamesObj = rb_ary_new2(defNames.size());
for (size_t i = 0; i < defNames.size(); ++i)
rb_ary_push(defNamesObj, rb_str_new_cstr(defNames[i].c_str()));
rb_ary_push(defNamesObj, rb_utf8_str_new_cstr(defNames[i].c_str()));
}
rb_iv_set(klass, "default_name", defNamesObj);

View file

@ -15,8 +15,8 @@
VALUE stringMap2hash(mkxp_net::StringMap &map) {
VALUE ret = rb_hash_new();
for (auto const &item : map) {
VALUE key = rb_str_new_cstr(item.first.c_str());
VALUE val = rb_str_new_cstr(item.second.c_str());
VALUE key = rb_utf8_str_new_cstr(item.first.c_str());
VALUE val = rb_utf8_str_new_cstr(item.second.c_str());
rb_hash_aset(ret, key, val);
}
return ret;
@ -56,7 +56,7 @@ RB_METHOD(httpGet) {
auto res = req.get();
ret = rb_hash_new();
rb_hash_aset(ret, ID2SYM(rb_intern("status")), INT2NUM(res.status()));
rb_hash_aset(ret, ID2SYM(rb_intern("body")), rb_str_new_cstr(res.body().c_str()));
rb_hash_aset(ret, ID2SYM(rb_intern("body")), rb_utf8_str_new_cstr(res.body().c_str()));
rb_hash_aset(ret, ID2SYM(rb_intern("headers")), stringMap2hash(res.headers()));
} catch (Exception &e) {
raiseRbExc(e);
@ -85,7 +85,7 @@ RB_METHOD(httpPost) {
auto res = req.post(postData);
ret = rb_hash_new();
rb_hash_aset(ret, ID2SYM(rb_intern("status")), INT2NUM(res.status()));
rb_hash_aset(ret, ID2SYM(rb_intern("body")), rb_str_new_cstr(res.body().c_str()));
rb_hash_aset(ret, ID2SYM(rb_intern("body")), rb_utf8_str_new_cstr(res.body().c_str()));
rb_hash_aset(ret, ID2SYM(rb_intern("headers")), stringMap2hash(res.headers()));
} catch (Exception &e) {
raiseRbExc(e);
@ -114,7 +114,7 @@ RB_METHOD(httpPostBody) {
auto res = req.post(RSTRING_PTR(body), RSTRING_PTR(ctype));
ret = rb_hash_new();
rb_hash_aset(ret, ID2SYM(rb_intern("status")), INT2NUM(res.status()));
rb_hash_aset(ret, ID2SYM(rb_intern("body")), rb_str_new_cstr(res.body().c_str()));
rb_hash_aset(ret, ID2SYM(rb_intern("body")), rb_utf8_str_new_cstr(res.body().c_str()));
rb_hash_aset(ret, ID2SYM(rb_intern("headers")), stringMap2hash(res.headers()));
} catch (Exception &e) {
raiseRbExc(e);
@ -131,7 +131,7 @@ VALUE json2rb(json5pp::value const &v) {
return rb_float_new(v.as_number());
if (v.is_string())
return rb_str_new_cstr(v.as_string().c_str());
return rb_utf8_str_new_cstr(v.as_string().c_str());
if (v.is_boolean())
return rb_bool_new(v.as_boolean());
@ -152,7 +152,7 @@ VALUE json2rb(json5pp::value const &v) {
auto &o = v.as_object();
VALUE ret = rb_hash_new();
for (auto const &pair : o) {
rb_hash_aset(ret, rb_str_new_cstr(pair.first.c_str()), json2rb(pair.second));
rb_hash_aset(ret, rb_utf8_str_new_cstr(pair.first.c_str()), json2rb(pair.second));
}
return ret;
}
@ -233,7 +233,7 @@ RB_METHOD(httpJsonStringify) {
rb_scan_args(argc, argv, "1", &obj);
json5pp::value v = rb2json(obj);
return rb_str_new_cstr(v.stringify().c_str());
return rb_utf8_str_new_cstr(v.stringify().c_str());
}
void httpBindingInit() {

View file

@ -281,7 +281,7 @@ RB_METHOD(inputJoystickInfo) {
VALUE ret = rb_hash_new();
rb_hash_aset(ret, M_SYMBOL("name"),
rb_str_new_cstr(shState->input().getJoystickName()));
rb_utf8_str_new_cstr(shState->input().getJoystickName()));
VALUE power;
@ -324,7 +324,7 @@ RB_METHOD(inputSetMode) {
RB_METHOD(inputGets) {
RB_UNUSED_PARAM;
VALUE ret = rb_str_new_cstr(shState->input().getText());
VALUE ret = rb_utf8_str_new_cstr(shState->input().getText());
shState->input().clearText();
return ret;
@ -334,7 +334,7 @@ RB_METHOD(inputGetClipboard) {
RB_UNUSED_PARAM;
VALUE ret;
try {
ret = rb_str_new_cstr(shState->input().getClipboardText());
ret = rb_utf8_str_new_cstr(shState->input().getClipboardText());
} catch (const Exception &e) {
raiseRbExc(e);
}

View file

@ -262,7 +262,7 @@ RB_METHOD(MiniFFI_call) {
return MVAL2RB(ret);
case _T_POINTER:
return rb_str_new_cstr((char *)ret);
return rb_utf8_str_new_cstr((char *)ret);
case _T_BOOL:
return rb_bool_new(ret);