develooper 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:
Karthik Rajagopalan 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-1339514971-1418.113536-15-0@perl.org
Hi,

On Tue Jun 12 08:13:09 2012, bulk88. wrote:
> 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. 

That was mistake on my part not to pass WC_NO_BEST_FIT_CHARS in acutal 
conversion call from UTF-16 to ACP. I will revise the patch and sent it 
now.

BTW, I don't think the win32 code would really work if UTF-8 is 
internally used for conversion. I see we use lot of calls toUpper, 
tolower which would not really work with utf-8 directly. So it is good 
if ACP is used.

-Karthik


>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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About