diff --git a/ChangeLog b/ChangeLog index c580232639..4a0b75f536 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Fri Oct 16 15:54:37 2015 Nobuyoshi Nakada + + * file.c (rb_file_load_ok): open in non-blocking mode withoout + releasing GVL. don't care about others than regular files and + directories. [ruby-dev:49272] [Bug #11559] + + * ruby.c (load_file_internal): ditto. + Thu Oct 15 23:56:03 2015 Nobuyoshi Nakada * proc.c (rb_sym_to_proc): make void env. diff --git a/common.mk b/common.mk index ba587c0239..2f152d59f5 100644 --- a/common.mk +++ b/common.mk @@ -728,7 +728,7 @@ compile.$(OBJEXT): {$(VPATH)}opt_sc.inc {$(VPATH)}optunifs.inc win32/win32.$(OBJEXT): {$(VPATH)}win32/win32.c {$(VPATH)}win32/file.h \ {$(VPATH)}dln.h {$(VPATH)}dln_find.c {$(VPATH)}encindex.h \ {$(VPATH)}internal.h {$(VPATH)}util.h $(RUBY_H_INCLUDES) $(PLATFORM_D) -win32/file.$(OBJEXT): {$(VPATH)}win32/file.c {$(VPATH)}win32/file.h {$(VPATH)}thread.h \ +win32/file.$(OBJEXT): {$(VPATH)}win32/file.c {$(VPATH)}win32/file.h \ $(RUBY_H_INCLUDES) $(PLATFORM_D) $(NEWLINE_C): $(srcdir)/enc/trans/newline.trans $(srcdir)/tool/transcode-tblgen.rb @@ -1462,7 +1462,6 @@ file.$(OBJEXT): {$(VPATH)}missing.h file.$(OBJEXT): {$(VPATH)}oniguruma.h file.$(OBJEXT): {$(VPATH)}st.h file.$(OBJEXT): {$(VPATH)}subst.h -file.$(OBJEXT): {$(VPATH)}thread.h file.$(OBJEXT): {$(VPATH)}util.h gc.$(OBJEXT): $(CCAN_DIR)/check_type/check_type.h gc.$(OBJEXT): $(CCAN_DIR)/container_of/container_of.h diff --git a/file.c b/file.c index f2b760aa0c..5a5fcde229 100644 --- a/file.c +++ b/file.c @@ -26,7 +26,6 @@ #include "internal.h" #include "ruby/io.h" #include "ruby/util.h" -#include "ruby/thread.h" #include "dln.h" #include "encindex.h" @@ -5665,25 +5664,24 @@ rb_path_check(const char *path) } #ifndef _WIN32 -static void * -loadopen_func(void *arg) -{ - return (void *)(VALUE)rb_cloexec_open((const char *)arg, O_RDONLY, 0); -} - int rb_file_load_ok(const char *path) { int ret = 1; - int fd; - - fd = (int)(VALUE)rb_thread_call_without_gvl(loadopen_func, (void *)path, RUBY_UBF_IO, 0); + int mode = (O_RDONLY | +#if defined O_NONBLOCK + O_NONBLOCK | +#elif defined O_NDELAY + O_NDELAY | +#endif + 0); + int fd = rb_cloexec_open(path, mode, 0); if (fd == -1) return 0; rb_update_max_fd(fd); #if !defined DOSISH { struct stat st; - if (fstat(fd, &st) || !S_ISREG(st.st_mode)) { + if (fstat(fd, &st) || S_ISDIR(st.st_mode)) { ret = 0; } } diff --git a/ruby.c b/ruby.c index 2d4c64b62a..6899ac2403 100644 --- a/ruby.c +++ b/ruby.c @@ -1739,6 +1739,11 @@ load_file_internal(VALUE arg) } else { int fd, mode = O_RDONLY; +#if defined O_NONBLOCK + mode |= O_NONBLOCK; +#elif defined O_NDELAY + mod |= O_NDELAY; +#endif #if defined DOSISH || defined __CYGWIN__ { const char *ext = strrchr(fname, '.'); diff --git a/test/ruby/test_require.rb b/test/ruby/test_require.rb index 25116e4912..d51aeb2ae7 100644 --- a/test/ruby/test_require.rb +++ b/test/ruby/test_require.rb @@ -702,7 +702,12 @@ class TestRequire < Test::Unit::TestCase assert_separately(["-", f.path], <<-END, timeout: 3) th = Thread.current Thread.start {begin sleep(0.001) end until th.stop?; th.raise(IOError)} - assert_raise(IOError) {load(ARGV[0])} + assert_nothing_raised do + begin + load(ARGV[0]) + rescue IOError + end + end END } end unless /mswin|mingw/ =~ RUBY_PLATFORM diff --git a/win32/file.c b/win32/file.c index 5eb9eb98b7..46a7ec7d5d 100644 --- a/win32/file.c +++ b/win32/file.c @@ -4,7 +4,6 @@ #endif #include "ruby/ruby.h" #include "ruby/encoding.h" -#include "ruby/thread.h" #include "internal.h" #include #include @@ -700,14 +699,6 @@ rb_readlink(VALUE path, rb_encoding *resultenc) return str; } -static void * -loadopen_func(void *wpath) -{ - return (void *)CreateFileW(wpath, GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); -} - int rb_file_load_ok(const char *path) { @@ -725,8 +716,9 @@ rb_file_load_ok(const char *path) ret = 0; } else { - HANDLE h = (HANDLE)rb_thread_call_without_gvl(loadopen_func, (void *)wpath, - RUBY_UBF_IO, 0); + HANDLE h = CreateFileW(wpath, GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (h != INVALID_HANDLE_VALUE) { CloseHandle(h); }