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

ruby-changes:36846

From: nobu <ko1@a...>
Date: Tue, 23 Dec 2014 16:03:52 +0900 (JST)
Subject: [ruby-changes:36846] nobu:r48927 (trunk): registry.rb: try en_US message

nobu	2014-12-23 16:03:37 +0900 (Tue, 23 Dec 2014)

  New Revision: 48927

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

  Log:
    registry.rb: try en_US message
    
    * ext/win32/lib/win32/registry.rb (Win32::Registry::Error#initialize):
      try en_US message if the default message cannot be encoded to
      locale.  [ruby-core:65295] [Bug #10300]

  Modified files:
    trunk/ChangeLog
    trunk/ext/win32/lib/win32/registry.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48926)
+++ ChangeLog	(revision 48927)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Dec 23 16:03:35 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/win32/lib/win32/registry.rb (Win32::Registry::Error#initialize):
+	  try en_US message if the default message cannot be encoded to
+	  locale.  [ruby-core:65295] [Bug #10300]
+
 Tue Dec 23 11:42:14 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* ext/openssl/ossl_cipher.c (ossl_cipher_update_long): update huge
Index: ext/win32/lib/win32/registry.rb
===================================================================
--- ext/win32/lib/win32/registry.rb	(revision 48926)
+++ ext/win32/lib/win32/registry.rb	(revision 48927)
@@ -175,11 +175,19 @@ For detail, see the MSDN[http://msdn.mic https://github.com/ruby/ruby/blob/trunk/ext/win32/lib/win32/registry.rb#L175
       def initialize(code)
         @code = code
         msg = WCHAR_NUL * 1024
-        len = FormatMessageW.call(0x1200, 0, code, 0, msg, 1024, 0)
-        msg = msg.byteslice(0, len * WCHAR_SIZE)
-        msg.delete!(WCHAR_CR)
-        msg.chomp!
-        super msg.encode(LOCALE)
+        lang = 0
+        begin
+          len = FormatMessageW.call(0x1200, 0, code, lang, msg, 1024, 0)
+          msg = msg.byteslice(0, len * WCHAR_SIZE)
+          msg.delete!(WCHAR_CR)
+          msg.chomp!
+          msg.encode!(LOCALE)
+        rescue EncodingError
+          raise unless lang == 0
+          lang = 0x0409         # en_US
+          retry
+        end
+        super msg
       end
       attr_reader :code
     end

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

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