From 0066d95fd6b679a90ba8e62d17e535127e3a4860 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 9 Nov 2014 03:09:40 +0000 Subject: [PATCH] win32/registry.rb: slice in WCHARs * ext/win32/lib/win32/registry.rb (Win32::Registry::API#Enum{Value,Key): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48333 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ ext/win32/lib/win32/registry.rb | 11 +++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7467888294..337d411010 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Nov 9 12:09:38 2014 Nobuyoshi Nakada + + * ext/win32/lib/win32/registry.rb (Win32::Registry::API#Enum{Value,Key): + ditto. + Sun Nov 9 11:48:40 2014 Tanaka Akira * test/net/http: Examine webrick log. diff --git a/ext/win32/lib/win32/registry.rb b/ext/win32/lib/win32/registry.rb index 74cc77dc9f..b14bd48fcf 100644 --- a/ext/win32/lib/win32/registry.rb +++ b/ext/win32/lib/win32/registry.rb @@ -66,6 +66,7 @@ For detail, see the MSDN[http://msdn.microsoft.com/library/en-us/sysinfo/base/pr WCHAR = Encoding::UTF_16LE WCHAR_NUL = "\0".encode(WCHAR).freeze + WCHAR_CR = "\r".encode(WCHAR).freeze WCHAR_SIZE = WCHAR_NUL.bytesize LOCALE = Encoding.find(Encoding.locale_charmap) @@ -175,8 +176,10 @@ For detail, see the MSDN[http://msdn.microsoft.com/library/en-us/sysinfo/base/pr @code = code msg = WCHAR_NUL * 1024 len = FormatMessageW.call(0x1200, 0, code, 0, msg, 1024, 0) - msg = msg[0, len].encode(LOCALE) - super msg.tr("\r".encode(msg.encoding), '').chomp + msg = msg.byteslice(0, len * WCHAR_SIZE) + msg.delete!(WCHAR_CR) + msg.chomp! + super msg.encode(LOCALE) end attr_reader :code end @@ -290,7 +293,7 @@ For detail, see the MSDN[http://msdn.microsoft.com/library/en-us/sysinfo/base/pr name = WCHAR_NUL * Constants::MAX_KEY_LENGTH size = packdw(Constants::MAX_KEY_LENGTH) check RegEnumValueW.call(hkey, index, name, size, 0, 0, 0, 0) - name[0, unpackdw(size)] + name.byteslice(0, unpackdw(size) * WCHAR_SIZE) end def EnumKey(hkey, index) @@ -298,7 +301,7 @@ For detail, see the MSDN[http://msdn.microsoft.com/library/en-us/sysinfo/base/pr size = packdw(Constants::MAX_KEY_LENGTH) wtime = ' ' * 8 check RegEnumKeyExW.call(hkey, index, name, size, 0, 0, 0, wtime) - [ name[0, unpackdw(size)], unpackqw(wtime) ] + [ name.byteslice(0, unpackdw(size) * WCHAR_SIZE), unpackqw(wtime) ] end def QueryValue(hkey, name)