Kendall Gifford
2010-Feb-02 19:39 UTC
[Win32utils-devel] win32-dir broken (and windows-pr''s limits.rb issues warnings) in ruby 1.9
Hi everyone, I''m pretty new to the win32-utils project: looks pretty cool! Anyhow, for my development I''m using ruby 1.9.1 (p243) on Windows XP Pro, SP3 (I download the ruby installer project''s zip and development kit). I installed the win32-dir gem (which pulled in windows-pr too) and I''m trying to use a few of the constants it adds to the Dir class. However, on my first try on a very simple program, I got and error. I then literally simplified my test script to: ---- D:\dir_test.rb # Test win32-dir gem... require ''win32/dir'' # # just see if the parser can handle this gem at all; no actual code in file... # ---- executing this yielded the following error and warning: D:\>ruby dir_test.rb D:/ruby/lib/ruby/gems/1.9.1/gems/windows-pr-1.0.8/lib/windows/limits.rb:17: warning: variable $KCODE is no longer effective D:/ruby/lib/ruby/gems/1.9.1/gems/win32-dir-0.3.5/lib/win32/dir.rb:38:in `block in <class:Dir>'': undefined method `split'' for :CSIDL_DESKTOP:Symbol (NoMethodError) from D:/ruby/lib/ruby/gems/1.9.1/gems/win32-dir-0.3.5/lib/win32/dir.rb:36:in `each'' from D:/ruby/lib/ruby/gems/1.9.1/gems/win32-dir-0.3.5/lib/win32/dir.rb:36:in `<class:Dir>'' from D:/ruby/lib/ruby/gems/1.9.1/gems/win32-dir-0.3.5/lib/win32/dir.rb:13:in `<top (required)>'' from dir_test.rb:2:in `require'' from dir_test.rb:2:in `<main>'' The error in win32-dir''s dir.rb file was an easy fix. I just changed: dir.rb:38: nconst = constant.split(''CSIDL_'').last to: dir.rb:38: nconst = constant.to_s.split(''CSIDL_'').last This makes the extra to_s redundant in ruby 1.8 but is needed for 1.9. However, the $KCODE warning from above isn''t as simple for me. I see what the problem is, windows-pr gem''s limits.rb file (line 17 on gem version 1.0.8) uses $KCODE in a condition. The idea is to have a larger value set for MAXPATH if using ''UTF8'' encoding, otherwise set MAXPATH to 256. Since $KCODE isn''t used in 1.9 it is (I''m guessing) nil (at least in my case) so it will always issue the warning and set MAXPATH to 256. Now, my simple code will likely still work but I''d like to resolve the warning (I''m OCD) and have it work the "right" way for 1.8 <---> 1.9 compatibility. So, I guess this is a "feature request" as it were. So, is Window''s MAXPATH constant based on whether you use the ANSI vs. their UNICODE version of an API call generally or is it more complicated than that? Do win32-utils delegate to the ANSI ("A") or UNICODE ("W") version of an API call based on the $KCODE value globally? I''ll dig into some code and try to answer my own question but, if someone just knows this stuff well off the top of their head, I''d appreciate the help. I''ve done a fair amount of C-based Win32 coding in the past and would like to help with these various projects (to do my part); especially to get everything working smoothly on 1.9. Anyhow, thanks everyone for your hard work making these gems! -- Kendall Gifford zettabyte at gmail.com
Daniel Berger
2010-Feb-04 01:22 UTC
[Win32utils-devel] win32-dir broken (and windows-pr''s limits.rb issues warnings) in ruby 1.9
On Tue, Feb 2, 2010 at 12:39 PM, Kendall Gifford <zettabyte at gmail.com> wrote:> Hi everyone, I''m pretty new to the win32-utils project: looks pretty cool!Thanks!> Anyhow, for my development I''m using ruby 1.9.1 (p243) on Windows XP > Pro, SP3 (I download the ruby installer project''s zip and development > kit). > > I installed the win32-dir gem (which pulled in windows-pr too) and I''m > trying to use a few of the constants it adds to the Dir class. > However, on my first try on a very simple program, I got and error.<snip> Thanks, I''ll look into it and try to get a fix out soon.> However, the $KCODE warning from above isn''t as simple for me. I see > what the problem is, windows-pr gem''s limits.rb file (line 17 on gem > version 1.0.8) uses $KCODE in a condition. The idea is to have a > larger value set for MAXPATH if using ''UTF8'' encoding, otherwise set > MAXPATH to 256. Since $KCODE isn''t used in 1.9 it is (I''m guessing) > nil (at least in my case) so it will always issue the warning and set > MAXPATH to 256. > > Now, my simple code will likely still work but I''d like to resolve the > warning (I''m OCD) and have it work the "right" way for 1.8 <---> 1.9 > compatibility. So, I guess this is a "feature request" as it were.Ok.> So, is Window''s MAXPATH constant based on whether you use the ANSI vs. > their UNICODE version of an API call generally or is it more > complicated than that? Do win32-utils delegate to the ANSI ("A") or > UNICODE ("W") version of an API call based on the $KCODE value > globally? I''ll dig into some code and try to answer my own question > but, if someone just knows this stuff well off the top of their head, > I''d appreciate the help. I''ve done a fair amount of C-based Win32 > coding in the past and would like to help with these various projects > (to do my part); especially to get everything working smoothly on 1.9. > > Anyhow, thanks everyone for your hard work making these gems!It used to be that the wide character function would be used if $KCODE was set, but it caused too much confusion in practice. By default, it will use the ansi version. The MAXPATH value currently does look at $KCODE. Obviously, this will not work for 1.9. I''ll have to check encoding or something. I don''t use 1.9 in practice, so that''s why these errors creep up from time to time. Thanks for the report. Regards, Dan