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

ruby-changes:15027

From: shugo <ko1@a...>
Date: Sat, 13 Mar 2010 10:35:09 +0900 (JST)
Subject: [ruby-changes:15027] Ruby:r26902 (trunk): * load.c (rb_get_expanded_load_path): does not expand paths if all

shugo	2010-03-13 10:34:38 +0900 (Sat, 13 Mar 2010)

  New Revision: 26902

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

  Log:
    * load.c (rb_get_expanded_load_path): does not expand paths if all
      the items in $: are absolute paths.  [ruby-core:28113]

  Modified files:
    trunk/ChangeLog
    trunk/file.c
    trunk/include/ruby/intern.h
    trunk/load.c

Index: include/ruby/intern.h
===================================================================
--- include/ruby/intern.h	(revision 26901)
+++ include/ruby/intern.h	(revision 26902)
@@ -366,6 +366,7 @@
 char *rb_path_last_separator(const char *);
 char *rb_path_end(const char *);
 VALUE rb_file_directory_p(VALUE,VALUE);
+int rb_is_absolute_path(const char *);
 /* gc.c */
 void ruby_set_stack_size(size_t);
 NORETURN(void rb_memerror(void));
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 26901)
+++ ChangeLog	(revision 26902)
@@ -1,3 +1,8 @@
+Sat Mar 13 10:16:32 2010  Shugo Maeda  <shugo@r...>
+
+	* load.c (rb_get_expanded_load_path): does not expand paths if all
+	  the items in $: are absolute paths.  [ruby-core:28113]
+
 Sat Mar 13 10:03:52 2010  Hidetoshi NAGAI  <nagai@a...>
 
 	* ext/tk/extconf.rb: fix [Bug #2840] Tk doesn't built in mingw.
Index: load.c
===================================================================
--- load.c	(revision 26901)
+++ load.c	(revision 26902)
@@ -37,10 +37,21 @@
 rb_get_expanded_load_path(void)
 {
     VALUE load_path = rb_get_load_path();
-    VALUE ary = rb_ary_new2(RARRAY_LEN(load_path));
+    VALUE ary;
     long i;
 
     for (i = 0; i < RARRAY_LEN(load_path); ++i) {
+	VALUE str = RARRAY_PTR(load_path)[i];
+	if (TYPE(str) != T_STRING)
+	    RB_GC_GUARD(str) = rb_get_path(str);
+	if (!rb_is_absolute_path(RSTRING_PTR(str)))
+	    goto relative_path_found;
+    }
+    return load_path;
+
+  relative_path_found:
+    ary = rb_ary_new2(RARRAY_LEN(load_path));
+    for (i = 0; i < RARRAY_LEN(load_path); ++i) {
 	VALUE path = rb_file_expand_path(RARRAY_PTR(load_path)[i], Qnil);
 	rb_str_freeze(path);
 	rb_ary_push(ary, path);
Index: file.c
===================================================================
--- file.c	(revision 26901)
+++ file.c	(revision 26902)
@@ -2687,8 +2687,6 @@
     (void)(extenc || (extenc = rb_default_external_encoding())),\
     rb_enc_associate(result, extenc))
 
-static int is_absolute_path(const char*);
-
 VALUE
 rb_home_dir(const char *user, VALUE result)
 {
@@ -2802,7 +2800,7 @@
 	}
     }
 #endif
-    else if (!is_absolute_path(s)) {
+    else if (!rb_is_absolute_path(s)) {
 	if (!NIL_P(dname)) {
 	    file_expand_path(dname, Qnil, abs_mode, result);
 	    BUFINIT();
@@ -4704,8 +4702,8 @@
     rb_define_const(rb_mFConst, name, value);
 }
 
-static int
-is_absolute_path(const char *path)
+int
+rb_is_absolute_path(const char *path)
 {
 #ifdef DOSISH_DRIVE_LETTER
     if (has_drive_letter(path) && isdirsep(path[2])) return 1;
@@ -4735,7 +4733,7 @@
     const char *p0 = StringValueCStr(path);
     char *p = 0, *s;
 
-    if (!is_absolute_path(p0)) {
+    if (!rb_is_absolute_path(p0)) {
 	char *buf = my_getcwd();
 	VALUE newpath;
 
@@ -4872,7 +4870,7 @@
 	expanded = 1;
     }
 
-    if (expanded || is_absolute_path(f) || is_explicit_relative(f)) {
+    if (expanded || rb_is_absolute_path(f) || is_explicit_relative(f)) {
 	if (safe_level >= 1 && !fpath_check(fname)) {
 	    rb_raise(rb_eSecurityError, "loading from unsafe path %s", f);
 	}
@@ -4943,7 +4941,7 @@
 	expanded = 1;
     }
 
-    if (expanded || is_absolute_path(f) || is_explicit_relative(f)) {
+    if (expanded || rb_is_absolute_path(f) || is_explicit_relative(f)) {
 	if (safe_level >= 1 && !fpath_check(path)) {
 	    rb_raise(rb_eSecurityError, "loading from unsafe path %s", f);
 	}

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

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