Skip to content

Commit d0657d2

Browse files
committed
JRUBY-4910: Fix multi-byte arg processing for inproc JVM (Masayuki Onjo)
1 parent 66bec0d commit d0657d2

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

jvmlauncher.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,29 @@ bool JvmLauncher::isVersionString(const char *str) {
206206
return *end == '\0';
207207
}
208208

209-
bool JvmLauncher::startInProcJvm(const char *mainClassName, std::list<std::string> args, std::list<std::string> options) {
209+
bool JvmLauncher::startInProcJvm(const char *mainClassName, std::list<std::string> mbcs_args, std::list<std::string> mbcs_options) {
210+
211+
std::list<std::string> args;
212+
for (std::list<std::string>::iterator it = mbcs_args.begin(); it != mbcs_args.end(); ++it) {
213+
wchar_t wstr[2048];
214+
UINT cp = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
215+
MultiByteToWideChar(cp, 0, it->c_str(), -1, wstr, sizeof(wstr) / sizeof(wchar_t));
216+
int mb_size = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
217+
char *mbstr = (char*)malloc(mb_size);
218+
WideCharToMultiByte(CP_UTF8, 0, wstr, -1, mbstr, mb_size, NULL, NULL);
219+
args.push_back(mbstr);
220+
}
221+
222+
std::list<std::string> options;
223+
for (std::list<std::string>::iterator it = mbcs_options.begin(); it != mbcs_options.end(); ++it) {
224+
wchar_t wstr[2048];
225+
UINT cp = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
226+
MultiByteToWideChar(cp, 0, it->c_str(), -1, wstr, sizeof(wstr) / sizeof(wchar_t));
227+
int mb_size = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
228+
char *mbstr = (char*)malloc(mb_size);
229+
WideCharToMultiByte(CP_UTF8, 0, wstr, -1, mbstr, mb_size, NULL, NULL);
230+
options.push_back(mbstr);
231+
}
210232

211233
class Jvm {
212234
public:

0 commit comments

Comments
 (0)