diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-04-05 23:52:52 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-04-05 23:52:52 +0000 |
commit | a237db5cbc3e3093330c20b26a97320262ee7b16 (patch) | |
tree | dc1794798e74212781ace6bb38408ca1be9ac604 | |
parent | acfd09ed83bd9ee347870eac99f75d2579162e4c (diff) |
dln.c: non-ascii path on Windows
* 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]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45523 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | dln.c | 15 | ||||
-rw-r--r-- | ext/-test-/win32/dln/empty/empty.c | 4 | ||||
-rw-r--r-- | ext/-test-/win32/dln/empty/extconf.rb | 3 | ||||
-rw-r--r-- | test/-ext-/win32/test_dln.rb | 22 |
5 files changed, 45 insertions, 5 deletions
@@ -1,3 +1,9 @@ +Sun Apr 6 08:52:50 2014 Bugra Barin <bugrabarin@hotmail.com> + + * 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] + Sat Apr 5 19:36:33 2014 Tadayoshi Funaba <tadf@dotrb.org> * ext/date/date_core.c (d_lite_cmp): should compare with #<. @@ -1256,20 +1256,25 @@ dln_load(const char *file) #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; } diff --git a/ext/-test-/win32/dln/empty/empty.c b/ext/-test-/win32/dln/empty/empty.c new file mode 100644 index 0000000000..c4f94f1644 --- /dev/null +++ b/ext/-test-/win32/dln/empty/empty.c @@ -0,0 +1,4 @@ +void +Init_empty(void) +{ +} diff --git a/ext/-test-/win32/dln/empty/extconf.rb b/ext/-test-/win32/dln/empty/extconf.rb new file mode 100644 index 0000000000..a4efed90c9 --- /dev/null +++ b/ext/-test-/win32/dln/empty/extconf.rb @@ -0,0 +1,3 @@ +if $mingw or $mswin + create_makefile("-test-/win32/dln/empty") +end diff --git a/test/-ext-/win32/test_dln.rb b/test/-ext-/win32/test_dln.rb index 7c5fe61f59..40c1f533b0 100644 --- a/test/-ext-/win32/test_dln.rb +++ b/test/-ext-/win32/test_dln.rb @@ -1,4 +1,6 @@ require 'test/unit' +require 'tmpdir' +require 'rbconfig' require_relative '../../ruby/envutil' module Bug @@ -8,6 +10,26 @@ module Bug 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 |