diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-09-25 10:41:16 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-09-25 10:41:16 +0000 |
commit | e87fb88be844f0fae736768846954b6f6f7dc7c3 (patch) | |
tree | cbe2ab069e40b5b7f3217ce95b793426b303a305 /spec/ruby/optional/capi | |
parent | e59bf54b3a88d0465cca021afae7dc05b6db57a7 (diff) |
Update to ruby/spec@241f9e7
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64831 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/optional/capi')
-rw-r--r-- | spec/ruby/optional/capi/ext/thread_spec.c | 8 | ||||
-rw-r--r-- | spec/ruby/optional/capi/spec_helper.rb | 28 | ||||
-rw-r--r-- | spec/ruby/optional/capi/thread_spec.rb | 22 |
3 files changed, 45 insertions, 13 deletions
diff --git a/spec/ruby/optional/capi/ext/thread_spec.c b/spec/ruby/optional/capi/ext/thread_spec.c index 3bfe76b925..fed1b1f3b0 100644 --- a/spec/ruby/optional/capi/ext/thread_spec.c +++ b/spec/ruby/optional/capi/ext/thread_spec.c @@ -27,7 +27,7 @@ static VALUE thread_spec_rb_thread_alone() { /* This is unblocked by unblock_func(). */ static void* blocking_gvl_func(void* data) { int rfd = *(int *)data; - char dummy; + char dummy = ' '; ssize_t r; do { @@ -36,7 +36,7 @@ static void* blocking_gvl_func(void* data) { close(rfd); - return (void*)((r == 1) ? Qtrue : Qfalse); + return (void*)((r == 1 && dummy == 'A') ? Qtrue : Qfalse); } static void unblock_gvl_func(void *data) { @@ -57,7 +57,7 @@ static VALUE thread_spec_rb_thread_call_without_gvl(VALUE self) { void* ret; if (pipe(fds) == -1) { - return Qfalse; + rb_raise(rb_eRuntimeError, "could not create pipe"); } ret = rb_thread_call_without_gvl(blocking_gvl_func, &fds[0], unblock_gvl_func, &fds[1]); @@ -82,7 +82,7 @@ static VALUE thread_spec_rb_thread_call_without_gvl_with_ubf_io(VALUE self) { void* ret; if (pipe(fds) == -1) { - return Qfalse; + rb_raise(rb_eRuntimeError, "could not create pipe"); } ret = rb_thread_call_without_gvl(blocking_gvl_func_for_udf_io, diff --git a/spec/ruby/optional/capi/spec_helper.rb b/spec/ruby/optional/capi/spec_helper.rb index 25658122be..eda4964b69 100644 --- a/spec/ruby/optional/capi/spec_helper.rb +++ b/spec/ruby/optional/capi/spec_helper.rb @@ -16,24 +16,34 @@ def compile_extension(name) debug = false run_mkmf_in_process = RUBY_ENGINE == 'truffleruby' - ext_dir = File.expand_path("../ext", __FILE__) + core_ext_dir = File.expand_path("../ext", __FILE__) + + spec_caller_location = caller_locations.find { |c| c.path.end_with?('_spec.rb') } + spec_file_path = spec_caller_location.path + spec_ext_dir = File.expand_path("../ext", spec_file_path) + ext = "#{name}_spec" lib = "#{object_path}/#{ext}.#{RbConfig::CONFIG['DLEXT']}" ruby_header = "#{RbConfig::CONFIG['rubyhdrdir']}/ruby.h" - libruby_so = RbConfig::CONFIG['LIBRUBY_SO'] if RbConfig::CONFIG["ENABLE_SHARED"] == "yes" - if /mswin|mingw/ =~ RUBY_PLATFORM - libruby_so = RbConfig::CONFIG["LIBRUBY"] if RbConfig::CONFIG["ENABLE_SHARED"] == "yes" + + if RbConfig::CONFIG["ENABLE_SHARED"] == "yes" + if PlatformGuard.windows? + libruby_so = "#{RbConfig::CONFIG['bindir']}/#{RbConfig::CONFIG['LIBRUBY_SO']}" + else + libruby_so = "#{RbConfig::CONFIG['libdir']}/#{RbConfig::CONFIG['LIBRUBY_SO']}" + end end + begin mtime = File.mtime(lib) rescue Errno::ENOENT # not found, then compile else case # if lib is older than headers, source or libruby, then recompile - when mtime <= File.mtime("#{ext_dir}/rubyspec.h") - when mtime <= File.mtime("#{ext_dir}/#{ext}.c") + when mtime <= File.mtime("#{core_ext_dir}/rubyspec.h") + when mtime <= File.mtime("#{spec_ext_dir}/#{ext}.c") when mtime <= File.mtime(ruby_header) - when libruby_so && mtime <= File.mtime("#{RbConfig::CONFIG['libdir']}/#{libruby_so}") + when libruby_so && mtime <= File.mtime(libruby_so) else return lib # up-to-date end @@ -43,8 +53,8 @@ def compile_extension(name) tmpdir = tmp("cext_#{name}") Dir.mkdir(tmpdir) begin - ["rubyspec.h", "#{ext}.c"].each do |file| - cp "#{ext_dir}/#{file}", "#{tmpdir}/#{file}" + ["#{core_ext_dir}/rubyspec.h", "#{spec_ext_dir}/#{ext}.c"].each do |file| + cp file, "#{tmpdir}/#{File.basename(file)}" end Dir.chdir(tmpdir) do diff --git a/spec/ruby/optional/capi/thread_spec.rb b/spec/ruby/optional/capi/thread_spec.rb index f60e9ba065..52070198fd 100644 --- a/spec/ruby/optional/capi/thread_spec.rb +++ b/spec/ruby/optional/capi/thread_spec.rb @@ -123,5 +123,27 @@ describe "C-API Thread function" do # And we got a proper value thr.value.should be_true end + + it "runs a C function with the global lock unlocked amd unlocks IO with the generic RUBY_UBF_IO" do + thr = Thread.new do + @t.rb_thread_call_without_gvl_with_ubf_io + end + + # Wait until it's blocking... + Thread.pass while thr.status and thr.status != "sleep" + + # The thread status is set to sleep by rb_thread_call_without_gvl(), + # but the thread might not be in the blocking read(2) yet, so wait a bit. + sleep 0.1 + + # Wake it up, causing the unblock function to be run. + thr.wakeup + + # Make sure it stopped + thr.join(1).should_not be_nil + + # And we got a proper value + thr.value.should be_true + end end end |