[前][次][番号順一覧][スレッド一覧]

ruby-changes:33444

From: nobu <ko1@a...>
Date: Sun, 6 Apr 2014 08:52:59 +0900 (JST)
Subject: [ruby-changes:33444] nobu:r45523 (trunk): dln.c: non-ascii path on Windows

nobu	2014-04-06 08:52:52 +0900 (Sun, 06 Apr 2014)

  New Revision: 45523

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45523

  Log:
    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]

  Added directories:
    trunk/ext/-test-/win32/dln/empty/
  Added files:
    trunk/ext/-test-/win32/dln/empty/empty.c
    trunk/ext/-test-/win32/dln/empty/extconf.rb
  Modified files:
    trunk/ChangeLog
    trunk/dln.c
    trunk/test/-ext-/win32/test_dln.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45522)
+++ ChangeLog	(revision 45523)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Apr  6 08:52:50 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]
+
 Sat Apr  5 19:36:33 2014  Tadayoshi Funaba  <tadf@d...>
 
 	* ext/date/date_core.c (d_lite_cmp): should compare with #<.
Index: dln.c
===================================================================
--- dln.c	(revision 45522)
+++ dln.c	(revision 45523)
@@ -1256,20 +1256,25 @@ dln_load(const char *file) https://github.com/ruby/ruby/blob/trunk/dln.c#L1256
 
 #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: ext/-test-/win32/dln/empty/empty.c
===================================================================
--- ext/-test-/win32/dln/empty/empty.c	(revision 0)
+++ ext/-test-/win32/dln/empty/empty.c	(revision 45523)
@@ -0,0 +1,4 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/win32/dln/empty/empty.c#L1
+void
+Init_empty(void)
+{
+}

Property changes on: ext/-test-/win32/dln/empty/empty.c
___________________________________________________________________
Added: svn:eol-style
   + LF

Index: ext/-test-/win32/dln/empty/extconf.rb
===================================================================
--- ext/-test-/win32/dln/empty/extconf.rb	(revision 0)
+++ ext/-test-/win32/dln/empty/extconf.rb	(revision 45523)
@@ -0,0 +1,3 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/win32/dln/empty/extconf.rb#L1
+if $mingw or $mswin
+  create_makefile("-test-/win32/dln/empty")
+end

Property changes on: ext/-test-/win32/dln/empty/extconf.rb
___________________________________________________________________
Added: svn:eol-style
   + LF

Index: test/-ext-/win32/test_dln.rb
===================================================================
--- test/-ext-/win32/test_dln.rb	(revision 45522)
+++ test/-ext-/win32/test_dln.rb	(revision 45523)
@@ -1,4 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/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/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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]