[Win32utils-devel] win32-dir, unicode

Heesob Park phasis at gmail.com
Mon May 29 01:29:00 EDT 2006


2006/5/29, Daniel Berger <djberg96 at gmail.com>:
> Heesob Park wrote:
> > Hi,
> >
> > 2006/5/29, Daniel Berger <djberg96 at gmail.com>:
> > <snip>
> >> While I understand why this code works, I'm still not entirely clear why
> >> the previous code would cause the interpreter to segfault.  Bad pointer
> >> address?
> >>
> > Yes, Ruby's string is not just character array, it is actually a
> > structure and a tainted structure causes unexpected behaviour.
>
> Ah, right.
>
> >
> >> In any case, excellent work, thank you!
> >>
> > You are welcome.
> >
> >> Now I'm trying to work out a general approach for the windows-pr stuff.
> >>   Given a method like this:
> >>
> >> def GetFullPathName(file, buf, buf_size, part)
> >>    if $KCODE != 'NONE'
> >>       GetFullPathNameW.call(file, buf, buf_size, part)
> >>    else
> >>       GetFullPathName.call(file, buf, buf_size, part)
> >>    end
> >> end
> >>
> >> Should I modify it to try to do a best-guess?
> >>
> >> if $KCODE != 'NONE'
> >>    GetFullPathNameW.call(file, buf, buf_size/2, part)
> >> end
> >>
> >
> > Be careful, before calling GetFullPathNameW, the "file" must be UTF16 string.
> > I recommend all function call using W function, and if string is not
> > UTF16 then first convert it to UTF16 string.
> > $KCODE must be used to only determine the string is UTF8 string, not
> > determine to call wheter Ansi function or W function.
>
> What would you recommend then?  How should I determine within Ruby if
> the string being passed to a function is UTF16?  IsTextUnicode()?
> Something else?
>
The user might not call function with UTF16 by accident.
But the user who want call function with UTF16 string on purpose, use
utf16 flag.

> How would you define GetFullPathName within file.rb (from windows-pr)
> then, for example?
>
How about this?

def GetFullPathName(file, buf_size, buf, part, utf16 = false)
   file = multi_to_wide(file) unless utf16
   GetFullPathNameW.call(file, buf.size/2, buf, part)
end

Regards,

Park Heesob



More information about the win32utils-devel mailing list