[Win32utils-devel] win32-dir, unicode

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


2006/5/29, Daniel Berger <djberg96 at gmail.com>:
> 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.

> 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.
Because Ruby interpreter cannot handle UTF16 code file, the user has
no chance to use UTF16 string in real world in the ruby code.

Sample code is like this:

     from = multi_to_wide(from)
     to = multi_to_wide(to)
     if GetFullPathNameW.call(from, from_path.size, from_path, 0) == 0
        raise StandardError, 'GetFullPathName() failed: ' + get_last_error
     if GetFullPathNameW.call(to, to_path.size, to_path, 0) == 0
        raise StandardError, 'GetFullPathName() failed: ' + get_last_error

> Or do you think that's the user's job?
I think the user would'nt care about file name is unicode or ansi string.


Park Heesob

More information about the win32utils-devel mailing list