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

ruby-changes:18485

From: nobu <ko1@a...>
Date: Mon, 10 Jan 2011 22:46:56 +0900 (JST)
Subject: [ruby-changes:18485] Ruby:r30508 (trunk): * include/ruby/defines.h (CASEFOLD_FILESYSTEM): HFS+ is case

nobu	2011-01-10 22:46:47 +0900 (Mon, 10 Jan 2011)

  New Revision: 30508

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

  Log:
    * include/ruby/defines.h (CASEFOLD_FILESYSTEM): HFS+ is case
      insensitive.
    * load.c (loaded_feature_path, rb_feature_p, load_lock): on a
      case-insensitive filesystem, loaded features search should
      ignore case.  [ruby-core:34297]

  Modified files:
    trunk/ChangeLog
    trunk/include/ruby/defines.h
    trunk/load.c
    trunk/test/ruby/test_require.rb

Index: include/ruby/defines.h
===================================================================
--- include/ruby/defines.h	(revision 30507)
+++ include/ruby/defines.h	(revision 30508)
@@ -296,7 +296,7 @@
 #endif
 
 #ifndef CASEFOLD_FILESYSTEM
-# if defined DOSISH
+# if defined DOSISH || defined __APPLE__
 #   define CASEFOLD_FILESYSTEM 1
 # else
 #   define CASEFOLD_FILESYSTEM 0
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 30507)
+++ ChangeLog	(revision 30508)
@@ -1,3 +1,12 @@
+Mon Jan 10 22:46:43 2011  Nobuyoshi Nakada  <nobu@r...>
+
+	* include/ruby/defines.h (CASEFOLD_FILESYSTEM): HFS+ is case
+	  insensitive.
+
+	* load.c (loaded_feature_path, rb_feature_p, load_lock): on a
+	  case-insensitive filesystem, loaded features search should
+	  ignore case.  [ruby-core:34297]
+
 Mon Jan 10 21:34:12 2011  Nobuyoshi Nakada  <nobu@r...>
 
 	* common.mk (showflags): show LD commands.
Index: load.c
===================================================================
--- load.c	(revision 30507)
+++ load.c	(revision 30508)
@@ -9,12 +9,20 @@
 
 VALUE ruby_dln_librefs;
 
-#define IS_RBEXT(e) (strcmp((e), ".rb") == 0)
-#define IS_SOEXT(e) (strcmp((e), ".so") == 0 || strcmp((e), ".o") == 0)
+#if CASEFOLD_FILESYSTEM
+#define fncomp strcasecmp
+#define fnncomp strncasecmp
+#else
+#define fncomp strcmp
+#define fnncomp strncmp
+#endif
+
+#define IS_RBEXT(e) (fncomp((e), ".rb") == 0)
+#define IS_SOEXT(e) (fncomp((e), ".so") == 0 || fncomp((e), ".o") == 0)
 #ifdef DLEXT2
-#define IS_DLEXT(e) (strcmp((e), DLEXT) == 0 || strcmp((e), DLEXT2) == 0)
+#define IS_DLEXT(e) (fncomp((e), DLEXT) == 0 || fncomp((e), DLEXT2) == 0)
 #else
-#define IS_DLEXT(e) (strcmp((e), DLEXT) == 0)
+#define IS_DLEXT(e) (fncomp((e), DLEXT) == 0)
 #endif
 
 
@@ -88,8 +96,8 @@
 	long n = RSTRING_LEN(p);
 
 	if (vlen < n + len + 1) continue;
-	if (n && (strncmp(name, s, n) || name[n] != '/')) continue;
-	if (strncmp(name + n + 1, feature, len)) continue;
+	if (n && (fnncomp(name, s, n) || name[n] != '/')) continue;
+	if (fnncomp(name + n + 1, feature, len)) continue;
 	if (name[n+len+1] && name[n+len+1] != '.') continue;
 	switch (type) {
 	  case 's':
@@ -151,7 +159,7 @@
 	v = RARRAY_PTR(features)[i];
 	f = StringValuePtr(v);
 	if ((n = RSTRING_LEN(v)) < len) continue;
-	if (strncmp(f, feature, len) != 0) {
+	if (fnncomp(f, feature, len) != 0) {
 	    if (expanded) continue;
 	    if (!load_path) load_path = rb_get_expanded_load_path();
 	    if (!(p = loaded_feature_path(f, n, feature, len, type, load_path)))
@@ -390,7 +398,8 @@
     if (!loading_tbl || !st_lookup(loading_tbl, (st_data_t)ftptr, &data)) {
 	/* loading ruby library should be serialized. */
 	if (!loading_tbl) {
-	    GET_VM()->loading_table = loading_tbl = st_init_strtable();
+	    GET_VM()->loading_table = loading_tbl =
+		(CASEFOLD_FILESYSTEM ? st_init_strcasetable() : st_init_strtable());
 	}
 	/* partial state */
 	ftptr = ruby_strdup(ftptr);
Index: test/ruby/test_require.rb
===================================================================
--- test/ruby/test_require.rb	(revision 30507)
+++ test/ruby/test_require.rb	(revision 30508)
@@ -322,4 +322,20 @@
                       [], /\$LOADED_FEATURES is frozen; cannot append feature \(RuntimeError\)$/,
                       bug3756)
   end
+
+  def test_case_insensitive
+    load_path = $:.dup
+    loaded = $".dup
+    path = File.expand_path(__FILE__)
+    $:.unshift(File.dirname(path))
+    $".push(path) unless $".include?(path)
+    bug4255 = '[ruby-core:34297]'
+    assert_equal(false, $bug4255 ||= false, bug4255)
+    $bug4255 = true
+    f = File.basename(__FILE__, ".*").upcase
+    assert_equal(false, require(f))
+  ensure
+    $:.replace(load_path)
+    $".replace(loaded)
+  end if File.identical?(__FILE__, __FILE__.upcase)
 end

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

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