Front page | perl.perl5.porters |
Postings from June 2012
[perl #113536] GetEnvironmentStrings() mess up the values for non-ascii strings
Thread Previous
|
Thread Next
From:
bulk88 via RT
Date:
June 13, 2012 02:37
Subject:
[perl #113536] GetEnvironmentStrings() mess up the values for non-ascii strings
Message ID:
rt-3.6.HEAD-5009-1339513988-507.113536-15-0@perl.org
On Mon Jun 11 12:57:53 2012, kartlee05 wrote:
> I now have your comments incorporated in my attached patch. Please go-
> through it and let me know your opinion.
>
> -Karthik
>
>
__________________________
+ /* Convert the string from UTF-16 encoding to UTF-8 encoding */
+ WideCharToMultiByte(CP_ACP, 0, lpWStr, wenvstrings_len, lpStr,
aenvstrings_len, 0, 0);
__________________________
I didn't run your code, but you didn't convert to UTF8. You converted to
legacy high ASCII, and the conversion was done with character
approximation since the 2nd WCTMB didn't get the no best fit flag and
since you didn't pass the UTF8 CP, the function will fail if no best fit
is passed. I'll post a known good perl to UTF16 windows converter for
comparison (its from Win32 module), but its an apples oranges comparison.
________________________________
SV *
wstr_to_sv(pTHX_ WCHAR *wstr)
{
int wlen = (int)wcslen(wstr)+1;
BOOL use_default = FALSE;
int len = WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, wstr,
wlen, NULL, 0, NULL, NULL);
SV *sv = sv_2mortal(newSV(len));
len = WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, wstr, wlen,
SvPVX(sv), len, NULL, &use_default);
if (use_default) {
len = WideCharToMultiByte(CP_UTF8, 0, wstr, wlen, NULL, 0, NULL,
NULL);
sv_grow(sv, len);
len = WideCharToMultiByte(CP_UTF8, 0, wstr, wlen, SvPVX(sv),
len, NULL, NULL);
SvUTF8_on(sv);
}
/* Shouldn't really ever fail since we ask for the required length
first, but who knows... */
if (len) {
SvPOK_on(sv);
SvCUR_set(sv, len-1);
}
return sv;
}
______________________________________
---
via perlbug: queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=113536
Thread Previous
|
Thread Next