[前][次][番号順一覧][スレッド一覧]

ruby-changes:29792

From: usa <ko1@a...>
Date: Tue, 9 Jul 2013 09:50:00 +0900 (JST)
Subject: [ruby-changes:29792] usa:r41844 (trunk): * ext/dl/win32/lib/win32/registry.rb (Win32::Registry.expand_environ):

usa	2013-07-09 09:49:44 +0900 (Tue, 09 Jul 2013)

  New Revision: 41844

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41844

  Log:
    * ext/dl/win32/lib/win32/registry.rb (Win32::Registry.expand_environ):
      use suitable encoding for the string.  fixed a test-all error of
      r41838.
    
    * ext/fiddle/win32/lib/win32/registry.rb: same changes of r41838 and
      this revision of dl's win32/registry.rb.

  Modified files:
    trunk/ChangeLog
    trunk/ext/dl/win32/lib/win32/registry.rb
    trunk/ext/fiddle/win32/lib/win32/registry.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41843)
+++ ChangeLog	(revision 41844)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Jul  9 09:46:53 2013  NAKAMURA Usaku  <usa@r...>
+
+	* ext/dl/win32/lib/win32/registry.rb (Win32::Registry.expand_environ):
+	  use suitable encoding for the string.  fixed a test-all error of
+	  r41838.
+
+	* ext/fiddle/win32/lib/win32/registry.rb: same changes of r41838 and
+	  this revision of dl's win32/registry.rb.
+
 Tue Jul  9 07:39:45 2013  Eric Hodel  <drbrain@s...>
 
 	* lib/rubygems:  Update to RubyGems 2.0.4.  See
Index: ext/dl/win32/lib/win32/registry.rb
===================================================================
--- ext/dl/win32/lib/win32/registry.rb	(revision 41843)
+++ ext/dl/win32/lib/win32/registry.rb	(revision 41844)
@@ -340,7 +340,7 @@ For detail, see the MSDN[http://msdn.mic https://github.com/ruby/ruby/blob/trunk/ext/dl/win32/lib/win32/registry.rb#L340
     # For detail, see expandEnvironmentStrings[http://msdn.microsoft.com/library/en-us/sysinfo/base/expandenvironmentstrings.asp] \Win32 \API.
     #
     def self.expand_environ(str)
-      str.gsub(/%([^%]+)%/) { ENV[$1] || ENV[$1.upcase] || $& }
+      str.gsub(Regexp.compile("%([^%]+)%".encode(str.encoding))) { ENV[$1] || ENV[$1.upcase] || $& }
     end
 
     @@type2name = { }
Index: ext/fiddle/win32/lib/win32/registry.rb
===================================================================
--- ext/fiddle/win32/lib/win32/registry.rb	(revision 41843)
+++ ext/fiddle/win32/lib/win32/registry.rb	(revision 41844)
@@ -63,6 +63,10 @@ For detail, see the MSDN[http://msdn.mic https://github.com/ruby/ruby/blob/trunk/ext/fiddle/win32/lib/win32/registry.rb#L63
 
 =end rdoc
 
+  WCHAR = Encoding::UTF_16LE
+  WCHAR_SPACE = "\0".encode(WCHAR).freeze
+  LOCALE = Encoding.find(Encoding.locale_charmap)
+
   class Registry
 
     #
@@ -164,12 +168,12 @@ For detail, see the MSDN[http://msdn.mic https://github.com/ruby/ruby/blob/trunk/ext/fiddle/win32/lib/win32/registry.rb#L168
         extend Fiddle::Importer
         dlload "kernel32.dll"
       end
-      FormatMessageA = Kernel32.extern "int FormatMessageA(int, void *, int, int, void *, int, void *)", :stdcall
+      FormatMessageW = Kernel32.extern "int FormatMessageW(int, void *, int, int, void *, int, void *)", :stdcall
       def initialize(code)
         @code = code
-        msg = "\0".force_encoding(Encoding::ASCII_8BIT) * 1024
-        len = FormatMessageA.call(0x1200, 0, code, 0, msg, 1024, 0)
-        msg = msg[0, len].force_encoding(Encoding.find(Encoding.locale_charmap))
+        msg = WCHAR_SPACE * 1024
+        len = FormatMessageW.call(0x1200, 0, code, 0, msg, 1024, 0)
+        msg = msg[0, len].encode
         super msg.tr("\r", '').chomp
       end
       attr_reader :code
@@ -209,12 +213,12 @@ For detail, see the MSDN[http://msdn.mic https://github.com/ruby/ruby/blob/trunk/ext/fiddle/win32/lib/win32/registry.rb#L213
       extend Fiddle::Importer
       dlload "advapi32.dll"
       [
-        "long RegOpenKeyExA(void *, void *, long, long, void *)",
-        "long RegCreateKeyExA(void *, void *, long, long, long, long, void *, void *, void *)",
-        "long RegEnumValueA(void *, long, void *, void *, void *, void *, void *, void *)",
-        "long RegEnumKeyExA(void *, long, void *, void *, void *, void *, void *, void *)",
-        "long RegQueryValueExA(void *, void *, void *, void *, void *, void *)",
-        "long RegSetValueExA(void *, void *, long, long, void *, long)",
+        "long RegOpenKeyExW(void *, void *, long, long, void *)",
+        "long RegCreateKeyExW(void *, void *, long, long, long, long, void *, void *, void *)",
+        "long RegEnumValueW(void *, long, void *, void *, void *, void *, void *, void *)",
+        "long RegEnumKeyExW(void *, long, void *, void *, void *, void *, void *, void *)",
+        "long RegQueryValueExW(void *, void *, void *, void *, void *, void *)",
+        "long RegSetValueExW(void *, void *, long, long, void *, long)",
         "long RegDeleteValue(void *, void *)",
         "long RegDeleteKey(void *, void *)",
         "long RegFlushKey(void *)",
@@ -251,52 +255,58 @@ For detail, see the MSDN[http://msdn.mic https://github.com/ruby/ruby/blob/trunk/ext/fiddle/win32/lib/win32/registry.rb#L255
 
       def OpenKey(hkey, name, opt, desired)
         result = packdw(0)
-        check RegOpenKeyExA.call(hkey, name, opt, desired, result)
+        check RegOpenKeyExW.call(hkey, name.encode(WCHAR), opt, desired, result)
         unpackdw(result)
       end
 
       def CreateKey(hkey, name, opt, desired)
         result = packdw(0)
         disp = packdw(0)
-        check RegCreateKeyExA.call(hkey, name, 0, 0, opt, desired,
+        check RegCreateKeyExW.call(hkey, name.encode(WCHAR), 0, 0, opt, desired,
                                    0, result, disp)
         [ unpackdw(result), unpackdw(disp) ]
       end
 
       def EnumValue(hkey, index)
-        name = ' ' * Constants::MAX_KEY_LENGTH
+        name = WCHAR_SPACE * Constants::MAX_KEY_LENGTH
         size = packdw(Constants::MAX_KEY_LENGTH)
-        check RegEnumValueA.call(hkey, index, name, size, 0, 0, 0, 0)
-        name[0, unpackdw(size)]
+        check RegEnumValueW.call(hkey, index, name, size, 0, 0, 0, 0)
+        name[0, unpackdw(size)].encode
       end
 
       def EnumKey(hkey, index)
-        name = ' ' * Constants::MAX_KEY_LENGTH
+        name = WCHAR_SPACE * Constants::MAX_KEY_LENGTH
         size = packdw(Constants::MAX_KEY_LENGTH)
         wtime = ' ' * 8
-        check RegEnumKeyExA.call(hkey, index, name, size, 0, 0, 0, wtime)
-        [ name[0, unpackdw(size)], unpackqw(wtime) ]
+        check RegEnumKeyExW.call(hkey, index, name, size, 0, 0, 0, wtime)
+        [ name[0, unpackdw(size)].encode, unpackqw(wtime) ]
       end
 
       def QueryValue(hkey, name)
         type = packdw(0)
         size = packdw(0)
-        check RegQueryValueExA.call(hkey, name, 0, type, 0, size)
-        data = ' ' * unpackdw(size)
-        check RegQueryValueExA.call(hkey, name, 0, type, data, size)
-        [ unpackdw(type), data[0, unpackdw(size)] ]
+        name = name.encode(WCHAR)
+        check RegQueryValueExW.call(hkey, name, 0, type, 0, size)
+        data = WCHAR_SPACE * unpackdw(size)
+        check RegQueryValueExW.call(hkey, name, 0, type, data, size)
+        [ unpackdw(type), data[0, unpackdw(size)].encode ]
       end
 
       def SetValue(hkey, name, type, data, size)
-        check RegSetValueExA.call(hkey, name, 0, type, data, size)
+        case type
+        when REG_SZ, REG_EXPAND_SZ, REG_MULTI_SZ
+          data = data.encode(WCHAR)
+          size ||= data.size + 1
+        end
+        check RegSetValueExW.call(hkey, name.encode(WCHAR), 0, type, data, size)
       end
 
       def DeleteValue(hkey, name)
-        check RegDeleteValue.call(hkey, name)
+        check RegDeleteValue.call(hkey, name.encode(WCHAR))
       end
 
       def DeleteKey(hkey, name)
-        check RegDeleteKey.call(hkey, name)
+        check RegDeleteKey.call(hkey, name.encode(WCHAR))
       end
 
       def FlushKey(hkey)
@@ -330,7 +340,7 @@ For detail, see the MSDN[http://msdn.mic https://github.com/ruby/ruby/blob/trunk/ext/fiddle/win32/lib/win32/registry.rb#L340
     # For detail, see expandEnvironmentStrings[http://msdn.microsoft.com/library/en-us/sysinfo/base/expandenvironmentstrings.asp] \Win32 \API.
     #
     def self.expand_environ(str)
-      str.gsub(/%([^%]+)%/) { ENV[$1] || ENV[$1.upcase] || $& }
+      str.gsub(Regexp.compile("%([^%]+)%".encode(str.encoding))) { ENV[$1] || ENV[$1.upcase] || $& }
     end
 
     @@type2name = { }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]