[#23332] to_str再考 — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです

15 messages 2004/04/05

[#23380] [SEGV] make test-all (bccwin32 ruby1.9.0) — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp>

山本です。

17 messages 2004/04/15
[#23400] Re: [SEGV] make test-all (bccwin32 ruby1.9.0) — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/04/16

山本です。落ちる場所がわかりました。

[#23402] Re: [SEGV] make test-all (bccwin32 ruby1.9.0) — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/04/16

山本です。

[#23403] Re: [SEGV] make test-all (bccwin32 ruby1.9.0) — nobu.nakada@... 2004/04/16

なかだです。

[#23405] Re: [SEGV] make test-all (bccwin32 ruby1.9.0) — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/04/16

山本です。

[#23407] Re: [SEGV] make test-all (bccwin32 ruby1.9.0) — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp> 2004/04/16

山本です。

[ruby-dev:23364] Re: memory leak ? in Dir.glob with block

From: "H.Yamamoto" <ocean@...2.ccsnet.ne.jp>
Date: 2004-04-10 03:06:44 UTC
List: ruby-dev #23364
山本です。

応急処置ですが、修正してみました。

/////////////////////////////////////////////////////////////////////
// main branch

Index: dir.c
===================================================================
RCS file: /ruby/ruby/dir.c,v
retrieving revision 1.116
diff -u -w -b -p -r1.116 dir.c
--- dir.c	9 Apr 2004 08:06:01 -0000	1.116
+++ dir.c	10 Apr 2004 02:44:43 -0000
@@ -1325,7 +1325,7 @@ glob_helper(path, dirsep, exist, isdir, 
     return status;
 }
 
-static void
+static int
 rb_glob2(path, flags, func, arg)
     const char *path;
     int flags;
@@ -1362,7 +1362,7 @@ rb_glob2(path, flags, func, arg)
 
     free(buf);
 
-    if (status) rb_jump_tag(status);
+    return status;
 }
 
 void
@@ -1371,7 +1371,8 @@ rb_glob(path, func, arg)
     void (*func) _((const char*, VALUE));
     VALUE arg;
 {
-    rb_glob2(path, 0, func, arg);
+    int status = rb_glob2(path, 0, func, arg);
+    if (status) rb_jump_tag(status);
 }
 
 static void
@@ -1389,16 +1390,16 @@ push_pattern(path, ary)
     }
 }
 
-static void
+static int
 push_globs(ary, s, flags)
     VALUE ary;
     const char *s;
     int flags;
 {
-    rb_glob2(s, flags, push_pattern, ary);
+    return rb_glob2(s, flags, push_pattern, ary);
 }
 
-static void
+static int
 push_braces(ary, s, flags)
     VALUE ary;
     const char *s;
@@ -1408,6 +1409,7 @@ push_braces(ary, s, flags)
     const char *p, *t;
     const char *lbrace, *rbrace;
     int nest = 0;
+    int status = 0;
 
     p = s;
     lbrace = rbrace = 0;
@@ -1441,13 +1443,16 @@ push_braces(ary, s, flags)
 	    }
 	    memcpy(b, t, p-t);
 	    strcpy(b+(p-t), Next(rbrace));
-	    push_braces(ary, buf, flags);
+	    status = push_braces(ary, buf, flags);
+	    if (status) break;
 	}
 	free(buf);
     }
     else {
-	push_globs(ary, s, flags);
+	status = push_globs(ary, s, flags);
     }
+
+    return status;
 }
 
 #define isdelim(c) ((c)=='\0')
@@ -1460,6 +1465,7 @@ rb_push_glob(str, flags)
     char *buf;
     const char *t;
     int nest, maxnest;
+    int status = 0;
     int escape = !(flags & FNM_NOESCAPE);
     VALUE ary;
 
@@ -1490,14 +1496,18 @@ rb_push_glob(str, flags)
 	memcpy(buf, t, p - t);
 	buf[p - t] = '\0';
 	if (maxnest == 0) {
-	    push_globs(ary, buf, flags);
+	    status = push_globs(ary, buf, flags);
+	    if (status) break;
 	}
 	else if (nest == 0) {
-	    push_braces(ary, buf, flags);
+	    status = push_braces(ary, buf, flags);
+	    if (status) break;
 	}
 	/* else unmatched braces */
     }
     free(buf);
+
+    if (status) rb_jump_tag(status);
 
     return ary;
 }

/////////////////////////////////////////////////////////////////////
// 1.8 branch

Index: dir.c
===================================================================
RCS file: /ruby/ruby/dir.c,v
retrieving revision 1.92.2.6
diff -u -w -b -p -r1.92.2.6 dir.c
--- dir.c	17 Mar 2004 05:47:18 -0000	1.92.2.6
+++ dir.c	10 Apr 2004 02:56:06 -0000
@@ -1053,7 +1053,7 @@ glob_helper(path, sub, flags, func, arg)
     return status;
 }
 
-static void
+static int
 rb_glob2(path, flags, func, arg)
     const char *path;
     int flags;
@@ -1067,7 +1067,7 @@ rb_glob2(path, flags, func, arg)
     strcpy(buf, path);
     status = glob_helper(buf, 0, flags, func, arg);
     free(buf);
-    if (status) rb_jump_tag(status);
+    return status;
 }
 
 void
@@ -1076,7 +1076,8 @@ rb_glob(path, func, arg)
     void (*func) _((const char*, VALUE));
     VALUE arg;
 {
-    rb_glob2(path, 0, func, arg);
+    int status = rb_glob2(path, 0, func, arg);
+    if (status) rb_jump_tag(status);
 }
 
 void
@@ -1085,7 +1086,8 @@ rb_globi(path, func, arg)
     void (*func) _((const char*, VALUE));
     VALUE arg;
 {
-    rb_glob2(path, FNM_CASEFOLD, func, arg);
+    int status = rb_glob2(path, FNM_CASEFOLD, func, arg);
+    if (status) rb_jump_tag(status);
 }
 
 static void
@@ -1103,16 +1105,16 @@ push_pattern(path, ary)
     }
 }
 
-static void
+static int
 push_globs(ary, s, flags)
     VALUE ary;
     const char *s;
     int flags;
 {
-    rb_glob2(s, flags, push_pattern, ary);
+    return rb_glob2(s, flags, push_pattern, ary);
 }
 
-static void
+static int
 push_braces(ary, s, flags)
     VALUE ary;
     const char *s;
@@ -1122,6 +1124,7 @@ push_braces(ary, s, flags)
     const char *p, *t;
     const char *lbrace, *rbrace;
     int nest = 0;
+    int status = 0;
 
     p = s;
     lbrace = rbrace = 0;
@@ -1155,13 +1158,16 @@ push_braces(ary, s, flags)
 	    }
 	    memcpy(b, t, p-t);
 	    strcpy(b+(p-t), rbrace+1);
-	    push_braces(ary, buf, flags);
+	    status = push_braces(ary, buf, flags);
+	    if (status) break;
 	}
 	free(buf);
     }
     else {
-	push_globs(ary, s, flags);
+	status = push_globs(ary, s, flags);
     }
+
+    return status;
 }
 
 #define isdelim(c) ((c)=='\0')
@@ -1175,6 +1181,7 @@ rb_push_glob(str, flags)
     char *buf;
     char *t;
     int nest, maxnest;
+    int status = 0;
     int noescape = flags & FNM_NOESCAPE;
     VALUE ary;
 
@@ -1204,14 +1211,18 @@ rb_push_glob(str, flags)
 	}
 	*t = '\0';
 	if (maxnest == 0) {
-	    push_globs(ary, buf, flags);
+	    status = push_globs(ary, buf, flags);
+	    if (status) break;
 	}
 	else if (nest == 0) {
-	    push_braces(ary, buf, flags);
+	    status = push_braces(ary, buf, flags);
+	    if (status) break;
 	}
 	/* else unmatched braces */
     }
     free(buf);
+
+    if (status) rb_jump_tag(status);
 
     return ary;
 }



In This Thread