win32/registry.rb: size in bytes

* ext/win32/lib/win32/registry.rb (Win32::Registry#write): data size
  is in bytes, not chars.  terminators should be placed automatically.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43031 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-09-24 07:41:17 +00:00
Родитель 79e880c90d
Коммит 360c66732c
2 изменённых файлов: 11 добавлений и 3 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Tue Sep 24 16:41:15 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/win32/lib/win32/registry.rb (Win32::Registry#write): data size
is in bytes, not chars. terminators should be placed automatically.
Tue Sep 24 16:39:36 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/win32/lib/win32/registry.rb (Win32::Registry#each_value): encode

Просмотреть файл

@ -725,11 +725,14 @@ For detail, see the MSDN[http://msdn.microsoft.com/library/en-us/sysinfo/base/pr
# method returns.
#
def write(name, type, data)
termsize = 0
case type
when REG_SZ, REG_EXPAND_SZ
data = data.to_s + "\0"
data = data.encode(WCHAR)
termsize = WCHAR_SIZE
when REG_MULTI_SZ
data = data.to_a.join("\0") + "\0\0"
data = data.to_a.map {|s| s.encode(WCHAR)}.join(WCHAR_NUL) << WCHAR_NUL
termsize = WCHAR_SIZE
when REG_BINARY
data = data.to_s
when REG_DWORD
@ -741,7 +744,7 @@ For detail, see the MSDN[http://msdn.microsoft.com/library/en-us/sysinfo/base/pr
else
raise TypeError, "Unsupported type #{type}"
end
API.SetValue(@hkey, name, type, data, data.length)
API.SetValue(@hkey, name, type, data, data.bytesize + termsize)
end
#