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

ruby-changes:2356

From: ko1@a...
Date: 9 Nov 2007 12:57:13 +0900
Subject: [ruby-changes:2356] nobu - Ruby:r13847 (trunk): * eval_load.c (loaded_feature_path): check with type of given feature.

nobu	2007-11-09 12:56:38 +0900 (Fri, 09 Nov 2007)

  New Revision: 13847

  Modified files:
    trunk/ChangeLog
    trunk/eval_load.c

  Log:
    * eval_load.c (loaded_feature_path): check with type of given feature.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/eval_load.c?r1=13847&r2=13846
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=13847&r2=13846

Index: eval_load.c
===================================================================
--- eval_load.c	(revision 13846)
+++ eval_load.c	(revision 13847)
@@ -6,6 +6,7 @@
 
 VALUE ruby_dln_librefs;
 
+#define IS_RBEXT(e) (strcmp(e, ".rb") == 0)
 #define IS_SOEXT(e) (strcmp(e, ".so") == 0 || strcmp(e, ".o") == 0)
 #ifdef DLEXT2
 #define IS_DLEXT(e) (strcmp(e, DLEXT) == 0 || strcmp(e, DLEXT2) == 0)
@@ -50,7 +51,7 @@
 
 static VALUE
 loaded_feature_path(const char *name, long vlen, const char *feature, long len,
-		    VALUE load_path)
+		    int type, VALUE load_path)
 {
     long i;
 
@@ -63,7 +64,16 @@
 	if (n && (strncmp(name, s, n) || name[n] != '/')) continue;
 	if (strncmp(name + n + 1, feature, len)) continue;
 	if (name[n+len+1] && name[n+len+1] != '.') continue;
-	return p;
+	switch (type) {
+	  case 's':
+	    if (IS_DLEXT(&name[n+len+1])) return p;
+	    break;
+	  case 'r':
+	    if (IS_RBEXT(&name[n+len+1])) return p;
+	    break;
+	  default:
+	    return p;
+	}
     }
     return 0;
 }
@@ -71,6 +81,7 @@
 struct loaded_feature_searching {
     const char *name;
     long len;
+    int type;
     VALUE load_path;
     const char *result;
 };
@@ -80,7 +91,8 @@
 {
     const char *s = (const char *)v;
     struct loaded_feature_searching *fp = (struct loaded_feature_searching *)f;
-    VALUE p = loaded_feature_path(s, strlen(s), fp->name, fp->len, fp->load_path);
+    VALUE p = loaded_feature_path(s, strlen(s), fp->name, fp->len,
+				  fp->type, fp->load_path);
     if (!p) return ST_CONTINUE;
     fp->result = s;
     return ST_STOP;
@@ -93,14 +105,17 @@
     const char *f, *e;
     long i, len, elen, n;
     st_table *loading_tbl;
+    int type;
 
     if (ext) {
 	len = ext - feature;
 	elen = strlen(ext);
+	type = rb ? 'r' : 's';
     }
     else {
 	len = strlen(feature);
 	elen = 0;
+	type = 0;
     }
     features = get_loaded_features();
     for (i = 0; i < RARRAY_LEN(features); ++i) {
@@ -110,7 +125,7 @@
 	if (strncmp(f, feature, len) != 0) {
 	    if (expanded) continue;
 	    if (!load_path) load_path = get_load_path();
-	    if (!(p = loaded_feature_path(f, n, feature, len, load_path)))
+	    if (!(p = loaded_feature_path(f, n, feature, len, type, load_path)))
 		continue;
 	    f += RSTRING_LEN(p) + 1;
 	}
@@ -122,7 +137,7 @@
 	if ((!rb || !ext) && (IS_SOEXT(e) || IS_DLEXT(e))) {
 	    return 's';
 	}
-	if ((rb || !ext) && (strcmp(e, ".rb") == 0)) {
+	if ((rb || !ext) && (IS_RBEXT(e))) {
 	    return 'r';
 	}
     }
@@ -132,6 +147,7 @@
 	    struct loaded_feature_searching fs;
 	    fs.name = feature;
 	    fs.len = len;
+	    fs.type = type;
 	    fs.load_path = load_path ? load_path : get_load_path();
 	    fs.result = 0;
 	    st_foreach(loading_tbl, loaded_feature_path_i, (st_data_t)&fs);
@@ -140,7 +156,7 @@
 	if (st_lookup(loading_tbl, (st_data_t)feature, 0)) {
 	  loading:
 	    if (!ext) return 'u';
-	    return strcmp(ext, ".rb") ? 's' : 'r';
+	    return !IS_RBEXT(ext) ? 's' : 'r';
 	}
 	else {
 	    char *buf;
@@ -165,7 +181,7 @@
     const char *ext = strrchr(feature, '.');
 
     if (ext && !strchr(ext, '/')) {
-	if (strcmp(".rb", ext) == 0) {
+	if (IS_RBEXT(ext)) {
 	    if (rb_feature_p(feature, ext, Qtrue, Qfalse)) return Qtrue;
 	    return Qfalse;
 	}
@@ -381,7 +397,7 @@
     *path = 0;
     ext = strrchr(ftptr = RSTRING_PTR(fname), '.');
     if (ext && !strchr(ext, '/')) {
-	if (strcmp(".rb", ext) == 0) {
+	if (IS_RBEXT(ext)) {
 	    if (rb_feature_p(ftptr, ext, Qtrue, Qfalse))
 		return 'r';
 	    if ((tmp = rb_find_file(fname)) != 0) {
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 13846)
+++ ChangeLog	(revision 13847)
@@ -1,3 +1,7 @@
+Fri Nov  9 12:56:36 2007  Nobuyoshi Nakada  <nobu@r...>
+
+	* eval_load.c (loaded_feature_path): check with type of given feature.
+
 Fri Nov  9 10:43:55 2007  Nobuyoshi Nakada  <nobu@r...>
 
 	* eval.c (send_internal): use self in the previous frame to check for

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

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