[macruby-changes] [4995] MacRuby/trunk/io.c

source_changes at macosforge.org source_changes at macosforge.org
Wed Dec 8 06:51:32 PST 2010


Revision: 4995
          http://trac.macosforge.org/projects/ruby/changeset/4995
Author:   watson1978 at gmail.com
Date:     2010-12-08 06:51:28 -0800 (Wed, 08 Dec 2010)
Log Message:
-----------
STDIO will be not actually closed. Fixed the #576.

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

Modified: MacRuby/trunk/io.c
===================================================================
--- MacRuby/trunk/io.c	2010-12-08 02:35:02 UTC (rev 4994)
+++ MacRuby/trunk/io.c	2010-12-08 14:51:28 UTC (rev 4995)
@@ -31,6 +31,15 @@
 #include <sys/syscall.h>
 #include <spawn.h>
 
+#define IS_FD_OF_STDIO(x) (x <= 2)
+#define CLOSE_FD(fd)					\
+    do {						\
+	if (!IS_FD_OF_STDIO(fd)) {			\
+	    close(fd);					\
+	}						\
+    }							\
+    while (0)
+
 char ***_NSGetEnviron();
 
 extern void Init_File(void);
@@ -343,7 +352,7 @@
     // rb_sys_fail().
     if (close_read) {
 	if (io_struct->read_fd != io_struct->write_fd) {
-	    close(io_struct->read_fd);
+	    CLOSE_FD(io_struct->read_fd);
 	}
 	else {
 	    io_struct->fd = -1;
@@ -352,7 +361,7 @@
     }
     if (close_write) {
 	if (io_struct->write_fd != io_struct->read_fd) {
-	    close(io_struct->write_fd);
+	    CLOSE_FD(io_struct->write_fd);
 	}
 	else {
 	    io_struct->fd = -1;
@@ -368,7 +377,7 @@
     }
     if (io_struct->fd != -1 && io_struct->read_fd == -1
 	    && io_struct->write_fd == -1) {
-	close(io_struct->fd);
+	CLOSE_FD(io_struct->fd);
 	io_struct->fd = -1;
     }
 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101208/fbb640f6/attachment.html>


More information about the macruby-changes mailing list