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
This commit is contained in:
nobu 2014-04-05 23:52:52 +00:00
Родитель acfd09ed83
Коммит a237db5cbc
5 изменённых файлов: 45 добавлений и 5 удалений

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

@ -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 #<.

15
dln.c
Просмотреть файл

@ -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;
}

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

@ -0,0 +1,4 @@
void
Init_empty(void)
{
}

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

@ -0,0 +1,3 @@
if $mingw or $mswin
create_makefile("-test-/win32/dln/empty")
end

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

@ -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