[macruby-changes] [2288] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Tue Aug 11 17:21:10 PDT 2009


Revision: 2288
          http://trac.macosforge.org/projects/ruby/changeset/2288
Author:   lsansonetti at apple.com
Date:     2009-08-11 17:21:08 -0700 (Tue, 11 Aug 2009)
Log Message:
-----------
fixed a problem that can occur on fast hardware: MacRuby was creating too many IO objects before the GC actually has a chance to finalize them (that was happening randomly during install), we now schedule synchronous and full collections in case this error happens

Modified Paths:
--------------
    MacRuby/trunk/gc.c
    MacRuby/trunk/io.c

Modified: MacRuby/trunk/gc.c
===================================================================
--- MacRuby/trunk/gc.c	2009-08-11 21:59:06 UTC (rev 2287)
+++ MacRuby/trunk/gc.c	2009-08-12 00:21:08 UTC (rev 2288)
@@ -355,9 +355,11 @@
 static int
 garbage_collect(void)
 {
-    if (dont_gc)
-	return Qtrue;
-    auto_collect(__auto_zone, AUTO_COLLECT_GENERATIONAL_COLLECTION, NULL);
+    if (!dont_gc) {
+	auto_collect(__auto_zone,
+		AUTO_COLLECT_EXHAUSTIVE_COLLECTION|AUTO_COLLECT_SYNCHRONOUS,
+		NULL);
+    }
     return Qtrue;
 }
 

Modified: MacRuby/trunk/io.c
===================================================================
--- MacRuby/trunk/io.c	2009-08-11 21:59:06 UTC (rev 2287)
+++ MacRuby/trunk/io.c	2009-08-12 00:21:08 UTC (rev 2288)
@@ -2371,9 +2371,23 @@
     StringValue(path);
     const char *filepath = RSTRING_PTR(path);
     const int flags = convert_mode_string_to_oflags(modes);
-    int fd = open(filepath, flags, 0644);
-    if (fd == -1) {
-	rb_sys_fail(NULL);
+    int fd, retry = 0;
+    while (true) {
+       fd = open(filepath, flags, 0644);
+       if (fd == -1) {
+	   if (retry < 5 && errno == EMFILE) {
+		// Too many open files. Let's schedule a GC collection.
+	       	rb_gc();
+		usleep(1000);
+	       	retry++;
+	   }
+	   else {
+	       rb_sys_fail("open() failed");
+	   }
+       }
+       else {
+	   break;
+       }
     }
     rb_io_t *io_struct = ExtractIOStruct(io);
     prepare_io_from_fd(io_struct, fd, convert_mode_string_to_fmode(modes), true);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090811/d71dfd0a/attachment.html>


More information about the macruby-changes mailing list