ruby-changes:34369
From: nagachika <ko1@a...>
Date: Tue, 17 Jun 2014 00:43:08 +0900 (JST)
Subject: [ruby-changes:34369] nagachika:r46450 (ruby_2_1): merge revision(s) r45521, r45523, r45551: [Backport #9699]
nagachika 2014-06-17 00:42:56 +0900 (Tue, 17 Jun 2014) New Revision: 46450 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46450 Log: merge revision(s) r45521,r45523,r45551: [Backport #9699] win32.c: wchar conversion * win32/win32.c (rb_w32_wstr_to_mbstr, rb_w32_mbstr_to_wstr): make WCHAR/mb conversion functions public. * dln.c (dln_load): use wchar version to load a library in non-ascii path on Windows. based on the patch by Bugra Barin <bugrabarin AT hotmail.com> in [ruby-core:61845]. [Bug #9699] Added directories: branches/ruby_2_1/ext/-test-/win32/dln/empty/ Modified directories: branches/ruby_2_1/ Modified files: branches/ruby_2_1/ChangeLog branches/ruby_2_1/dln.c branches/ruby_2_1/include/ruby/win32.h branches/ruby_2_1/test/-ext-/win32/test_dln.rb branches/ruby_2_1/version.h branches/ruby_2_1/win32/win32.c Index: ruby_2_1/include/ruby/win32.h =================================================================== --- ruby_2_1/include/ruby/win32.h (revision 46449) +++ ruby_2_1/include/ruby/win32.h (revision 46450) @@ -772,6 +772,8 @@ int rb_w32_wait_events_blocking(HANDLE https://github.com/ruby/ruby/blob/trunk/ruby_2_1/include/ruby/win32.h#L772 int rb_w32_time_subtract(struct timeval *rest, const struct timeval *wait); int rb_w32_wrap_io_handle(HANDLE, int); int rb_w32_unwrap_io_handle(int); +WCHAR *rb_w32_mbstr_to_wstr(UINT, const char *, int, long *); +char *rb_w32_wstr_to_mbstr(UINT, const WCHAR *, int, long *); /* == ***CAUTION*** Index: ruby_2_1/ChangeLog =================================================================== --- ruby_2_1/ChangeLog (revision 46449) +++ ruby_2_1/ChangeLog (revision 46450) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1 +Tue Jun 17 00:37:15 2014 Bugra Barin <bugrabarin@h...> + + * dln.c (dln_load): use wchar version to load a library in + non-ascii path on Windows. based on the patch by Bugra Barin + <bugrabarin AT hotmail.com> in [ruby-core:61845]. [Bug #9699] + Tue Jun 17 00:26:59 2014 Nobuyoshi Nakada <nobu@r...> * process.c (obj2uid, obj2gid): now getpwnam_r() and getgrnam_r() Index: ruby_2_1/win32/win32.c =================================================================== --- ruby_2_1/win32/win32.c (revision 46449) +++ ruby_2_1/win32/win32.c (revision 46450) @@ -1197,8 +1197,8 @@ is_batch(const char *cmd) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/win32/win32.c#L1197 } static UINT filecp(void); -static WCHAR *mbstr_to_wstr(UINT, const char *, int, long *); -static char *wstr_to_mbstr(UINT, const WCHAR *, int, long *); +#define mbstr_to_wstr rb_w32_mbstr_to_wstr +#define wstr_to_mbstr rb_w32_wstr_to_mbstr #define acp_to_wstr(str, plen) mbstr_to_wstr(CP_ACP, str, -1, plen) #define wstr_to_acp(str, plen) wstr_to_mbstr(CP_ACP, str, -1, plen) #define filecp_to_wstr(str, plen) mbstr_to_wstr(filecp(), str, -1, plen) @@ -1952,8 +1952,8 @@ filecp(void) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/win32/win32.c#L1952 } /* License: Ruby's */ -static char * -wstr_to_mbstr(UINT cp, const WCHAR *wstr, int clen, long *plen) +char * +rb_w32_wstr_to_mbstr(UINT cp, const WCHAR *wstr, int clen, long *plen) { char *ptr; int len = WideCharToMultiByte(cp, 0, wstr, clen, NULL, 0, NULL, NULL); @@ -1968,8 +1968,8 @@ wstr_to_mbstr(UINT cp, const WCHAR *wstr https://github.com/ruby/ruby/blob/trunk/ruby_2_1/win32/win32.c#L1968 } /* License: Ruby's */ -static WCHAR * -mbstr_to_wstr(UINT cp, const char *str, int clen, long *plen) +WCHAR * +rb_w32_mbstr_to_wstr(UINT cp, const char *str, int clen, long *plen) { WCHAR *ptr; int len = MultiByteToWideChar(cp, 0, str, clen, NULL, 0); Index: ruby_2_1/dln.c =================================================================== --- ruby_2_1/dln.c (revision 46449) +++ ruby_2_1/dln.c (revision 46450) @@ -1255,20 +1255,25 @@ dln_load(const char *file) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/dln.c#L1255 #if defined _WIN32 && !defined __CYGWIN__ HINSTANCE handle; - char winfile[MAXPATHLEN]; + WCHAR *winfile; char message[1024]; void (*init_fct)(); char *buf; - if (strlen(file) >= MAXPATHLEN) dln_loaderror("filename too long"); - /* Load the file as an object one */ init_funcname(&buf, file); - strlcpy(winfile, file, sizeof(winfile)); + /* Convert the file path to wide char */ + winfile = rb_w32_mbstr_to_wstr(CP_UTF8, file, -1, NULL); + if (!winfile) { + dln_memerror(); + } /* Load file */ - if ((handle = LoadLibrary(winfile)) == NULL) { + handle = LoadLibraryW(winfile); + free(winfile); + + if (!handle) { error = dln_strerror(); goto failed; } Index: ruby_2_1/ext/-test-/win32/dln/empty/empty.c =================================================================== --- ruby_2_1/ext/-test-/win32/dln/empty/empty.c (revision 0) +++ ruby_2_1/ext/-test-/win32/dln/empty/empty.c (revision 46450) @@ -0,0 +1,4 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ext/-test-/win32/dln/empty/empty.c#L1 +void +Init_empty(void) +{ +} Property changes on: ruby_2_1/ext/-test-/win32/dln/empty/empty.c ___________________________________________________________________ Added: svn:eol-style + LF Index: ruby_2_1/ext/-test-/win32/dln/empty/extconf.rb =================================================================== --- ruby_2_1/ext/-test-/win32/dln/empty/extconf.rb (revision 0) +++ ruby_2_1/ext/-test-/win32/dln/empty/extconf.rb (revision 46450) @@ -0,0 +1,3 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ext/-test-/win32/dln/empty/extconf.rb#L1 +if $mingw or $mswin + create_makefile("-test-/win32/dln/empty") +end Property changes on: ruby_2_1/ext/-test-/win32/dln/empty/extconf.rb ___________________________________________________________________ Added: svn:eol-style + LF Index: ruby_2_1/version.h =================================================================== --- ruby_2_1/version.h (revision 46449) +++ ruby_2_1/version.h (revision 46450) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1 #define RUBY_VERSION "2.1.2" #define RUBY_RELEASE_DATE "2014-06-17" -#define RUBY_PATCHLEVEL 130 +#define RUBY_PATCHLEVEL 131 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 6 Index: ruby_2_1/test/-ext-/win32/test_dln.rb =================================================================== --- ruby_2_1/test/-ext-/win32/test_dln.rb (revision 46449) +++ ruby_2_1/test/-ext-/win32/test_dln.rb (revision 46450) @@ -1,4 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/-ext-/win32/test_dln.rb#L1 require 'test/unit' +require 'tmpdir' +require 'rbconfig' require_relative '../../ruby/envutil' module Bug @@ -8,6 +10,26 @@ module Bug https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/-ext-/win32/test_dln.rb#L10 bug = '[Bug #6303]' assert_in_out_err(['-r-test-/win32/dln', '-eexit'], '', [], [], bug, timeout: 10) end + + def test_nonascii_load + bug9699 = '[ruby-core:61845] [Bug #9699]' + so = "-test-/win32/dln/empty." + RbConfig::CONFIG["DLEXT"] + so = $:.find {|d| d = ::File.join(d, so); break d if ::File.exist?(d)} + assert_not_nil(so) + Dir.mkdir(dir = ::File.join(testdir = Dir.mktmpdir("test"), "\u{30c6 30b9 30c8}")) + ::File.copy_stream(so, ::File.join(dir, ::File.basename(so))) + assert_separately(['-', bug9699, testdir, ::File.basename(so)], <<-'end;') + bug, dir, so = *ARGV + assert_nothing_raised(LoadError, bug) do + require ::File.join(dir, "\u{30c6 30b9 30c8}", so) + end + end; + ensure + ::File.unlink(::File.join(dir, ::File.basename(so))) rescue nil + Dir.rmdir(dir) rescue nil + Dir.rmdir(testdir) rescue nil + end + end end end if /mswin|mingw/ =~ RUBY_PLATFORM Property changes on: ruby_2_1 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r45521,45523,45551 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/