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

ruby-changes:42025

From: nobu <ko1@a...>
Date: Mon, 14 Mar 2016 16:03:06 +0900 (JST)
Subject: [ruby-changes:42025] nobu:r54099 (trunk): ruby.c: reduce fstat

nobu	2016-03-14 16:03:01 +0900 (Mon, 14 Mar 2016)

  New Revision: 54099

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54099

  Log:
    ruby.c: reduce fstat
    
    * file.c (ruby_is_fd_loadable): now return -1 if loadable but
      may block.
    * ruby.c (open_load_file): wait to read by the result of
      ruby_is_fd_loadable, without fstat.

  Modified files:
    trunk/ChangeLog
    trunk/file.c
    trunk/ruby.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54098)
+++ ChangeLog	(revision 54099)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Mar 14 16:02:59 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* file.c (ruby_is_fd_loadable): now return -1 if loadable but
+	  may block.
+
+	* ruby.c (open_load_file): wait to read by the result of
+	  ruby_is_fd_loadable, without fstat.
+
 Mon Mar 14 13:38:38 2016  NARUSE, Yui  <naruse@r...>
 
 	* numeric.c (fix2str): improve r54092 like rb_int2big().
Index: ruby.c
===================================================================
--- ruby.c	(revision 54098)
+++ ruby.c	(revision 54099)
@@ -1871,15 +1871,14 @@ open_load_file(VALUE fname_v, int *xflag https://github.com/ruby/ruby/blob/trunk/ruby.c#L1871
 	}
 #endif
 
-#ifdef S_ISFIFO
-	{
-	    struct stat st;
-	    if (fstat(fd, &st) != 0) {
+	e = ruby_is_fd_loadable(fd);
+	if (e <= 0) {
+	    if (!e) {
 		e = errno;
 		(void)close(fd);
 		rb_load_fail(fname_v, strerror(e));
 	    }
-	    if (S_ISFIFO(st.st_mode)) {
+	    else {
 		/*
 		  We need to wait if FIFO is empty. It's FIFO's semantics.
 		  rb_thread_wait_fd() release GVL. So, it's safe.
@@ -1887,12 +1886,6 @@ open_load_file(VALUE fname_v, int *xflag https://github.com/ruby/ruby/blob/trunk/ruby.c#L1886
 		rb_thread_wait_fd(fd);
 	    }
 	}
-#endif
-	if (!ruby_is_fd_loadable(fd)) {
-	    e = errno;
-	    (void)close(fd);
-	    rb_load_fail(fname_v, strerror(e));
-	}
 
 	f = rb_io_fdopen(fd, mode, fname);
     }
Index: file.c
===================================================================
--- file.c	(revision 54098)
+++ file.c	(revision 54099)
@@ -5644,11 +5644,12 @@ ruby_is_fd_loadable(int fd) https://github.com/ruby/ruby/blob/trunk/file.c#L5644
 
     if (fstat(fd, &st) < 0)
 	return 0;
+
     if (S_ISREG(st.st_mode))
 	return 1;
 
     if (S_ISFIFO(st.st_mode))
-	return 1;
+	return -1;
 
     if (S_ISDIR(st.st_mode))
 	errno = EISDIR;

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

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