From 4f83ca015d7131f0990ca03a295a9d0c816f0192 Mon Sep 17 00:00:00 2001 From: usa Date: Sat, 18 Nov 2017 08:25:29 +0000 Subject: Cannot call rb_thread_call_with{out,}_gvl before running VM * dir.c (opendir_without_gvl, with_gvl_gc_for_fd, opendir_at): check the VM is already initialized before calling rb_thread_call_with{out,}_gvl(). [Bug #14115] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60837 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- dir.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'dir.c') diff --git a/dir.c b/dir.c index 04f8d99efe..eecbfe2d96 100644 --- a/dir.c +++ b/dir.c @@ -76,6 +76,8 @@ char *strchr(char*,char); #include "ruby/util.h" +#define vm_initialized rb_cThread + /* define system APIs */ #ifdef _WIN32 #undef chdir @@ -501,11 +503,15 @@ nogvl_opendir(void *ptr) static DIR * opendir_without_gvl(const char *path) { - union { const char *in; void *out; } u; + if (vm_initialized) { + union { const char *in; void *out; } u; - u.in = path; + u.in = path; - return rb_thread_call_without_gvl(nogvl_opendir, u.out, RUBY_UBF_IO, 0); + return rb_thread_call_without_gvl(nogvl_opendir, u.out, RUBY_UBF_IO, 0); + } + else + return opendir(path); } /* @@ -1420,7 +1426,10 @@ with_gvl_gc_for_fd(void *ptr) static int gc_for_fd_with_gvl(int e) { - return (int)(VALUE)rb_thread_call_with_gvl(with_gvl_gc_for_fd, &e); + if (vm_initialized) + return (int)(VALUE)rb_thread_call_with_gvl(with_gvl_gc_for_fd, &e); + else + return rb_gc_for_fd(e) ? Qtrue : Qfalse; } static void * @@ -1471,7 +1480,10 @@ opendir_at(int basefd, const char *path) oaa.basefd = basefd; oaa.path = path; - return rb_thread_call_without_gvl(nogvl_opendir_at, &oaa, RUBY_UBF_IO, 0); + if (vm_initialized) + return rb_thread_call_without_gvl(nogvl_opendir_at, &oaa, RUBY_UBF_IO, 0); + else + return nogvl_opendir_at(&oaa); } static DIR * -- cgit v1.2.1