From cfc1c5037d40bc313a81b168c32a6d393f9978d2 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 14 Feb 2014 09:35:38 +0100 Subject: [PATCH] Mark strings as UTF-8 when passing them to Perl --- xs/src/Config.cpp | 8 ++++---- xs/xsp/Config.xsp | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/xs/src/Config.cpp b/xs/src/Config.cpp index b2783e35..a4e2def8 100644 --- a/xs/src/Config.cpp +++ b/xs/src/Config.cpp @@ -111,12 +111,12 @@ ConfigBase::get(t_config_option_key opt_key) { return newRV_noinc((SV*)av); } else if (ConfigOptionString* optv = dynamic_cast(opt)) { // we don't serialize() because that would escape newlines - return newSVpvn(optv->value.c_str(), optv->value.length()); + return newSVpvn_utf8(optv->value.c_str(), optv->value.length(), true); } else if (ConfigOptionStrings* optv = dynamic_cast(opt)) { AV* av = newAV(); av_fill(av, optv->values.size()-1); for (std::vector::iterator it = optv->values.begin(); it != optv->values.end(); ++it) - av_store(av, it - optv->values.begin(), newSVpvn(it->c_str(), it->length())); + av_store(av, it - optv->values.begin(), newSVpvn_utf8(it->c_str(), it->length(), true)); return newRV_noinc((SV*)av); } else if (ConfigOptionPoint* optv = dynamic_cast(opt)) { return optv->point.to_SV_pureperl(); @@ -136,7 +136,7 @@ ConfigBase::get(t_config_option_key opt_key) { return newRV_noinc((SV*)av); } else { std::string serialized = opt->serialize(); - return newSVpvn(serialized.c_str(), serialized.length()); + return newSVpvn_utf8(serialized.c_str(), serialized.length(), true); } } @@ -152,7 +152,7 @@ ConfigBase::get_at(t_config_option_key opt_key, size_t i) { } else if (ConfigOptionStrings* optv = dynamic_cast(opt)) { // we don't serialize() because that would escape newlines std::string val = optv->get_at(i); - return newSVpvn(val.c_str(), val.length()); + return newSVpvn_utf8(val.c_str(), val.length(), true); } else if (ConfigOptionPoints* optv = dynamic_cast(opt)) { return optv->get_at(i).to_SV_pureperl(); } else if (ConfigOptionBools* optv = dynamic_cast(opt)) { diff --git a/xs/xsp/Config.xsp b/xs/xsp/Config.xsp index 3e1b07cd..7afc97d6 100644 --- a/xs/xsp/Config.xsp +++ b/xs/xsp/Config.xsp @@ -147,12 +147,12 @@ print_config_def() throw "Unknown option type"; } (void)hv_stores( hv, "type", newSVpv(opt_type, 0) ); - (void)hv_stores( hv, "label", newSVpvn(optdef->label.c_str(), optdef->label.length()) ); + (void)hv_stores( hv, "label", newSVpvn_utf8(optdef->label.c_str(), optdef->label.length(), true) ); if (!optdef->full_label.empty()) - (void)hv_stores( hv, "full_label", newSVpvn(optdef->full_label.c_str(), optdef->full_label.length()) ); + (void)hv_stores( hv, "full_label", newSVpvn_utf8(optdef->full_label.c_str(), optdef->full_label.length(), true) ); (void)hv_stores( hv, "category", newSVpvn(optdef->category.c_str(), optdef->category.length()) ); - (void)hv_stores( hv, "tooltip", newSVpvn(optdef->tooltip.c_str(), optdef->tooltip.length()) ); - (void)hv_stores( hv, "sidetext", newSVpvn(optdef->sidetext.c_str(), optdef->sidetext.length()) ); + (void)hv_stores( hv, "tooltip", newSVpvn_utf8(optdef->tooltip.c_str(), optdef->tooltip.length(), true) ); + (void)hv_stores( hv, "sidetext", newSVpvn_utf8(optdef->sidetext.c_str(), optdef->sidetext.length(), true) ); (void)hv_stores( hv, "cli", newSVpvn(optdef->cli.c_str(), optdef->cli.length()) ); (void)hv_stores( hv, "scope", newSVpvn(optdef->scope.c_str(), optdef->scope.length()) ); (void)hv_stores( hv, "ratio_over", newSVpvn(optdef->ratio_over.c_str(), optdef->ratio_over.length()) ); @@ -196,7 +196,7 @@ print_config_def() AV* av = newAV(); av_fill(av, optdef->enum_labels.size()-1); for (std::vector::iterator it = optdef->enum_labels.begin(); it != optdef->enum_labels.end(); ++it) - av_store(av, it - optdef->enum_labels.begin(), newSVpvn(it->c_str(), it->length())); + av_store(av, it - optdef->enum_labels.begin(), newSVpvn_utf8(it->c_str(), it->length(), true)); (void)hv_stores( hv, "labels", newRV_noinc((SV*)av) ); }