diff options
Diffstat (limited to 'spec/rubyspec/optional')
-rw-r--r-- | spec/rubyspec/optional/capi/ext/io_spec.c | 23 | ||||
-rw-r--r-- | spec/rubyspec/optional/capi/globals_spec.rb | 4 | ||||
-rw-r--r-- | spec/rubyspec/optional/capi/object_spec.rb | 2 | ||||
-rw-r--r-- | spec/rubyspec/optional/capi/thread_spec.rb | 4 |
4 files changed, 19 insertions, 14 deletions
diff --git a/spec/rubyspec/optional/capi/ext/io_spec.c b/spec/rubyspec/optional/capi/ext/io_spec.c index 751cb33fd8..9eb733b1e0 100644 --- a/spec/rubyspec/optional/capi/ext/io_spec.c +++ b/spec/rubyspec/optional/capi/ext/io_spec.c @@ -1,6 +1,7 @@ #include "ruby.h" #include "rubyspec.h" #include "ruby/io.h" +#include <errno.h> #include <fcntl.h> #ifdef HAVE_UNISTD_H #include <unistd.h> @@ -133,46 +134,46 @@ VALUE io_spec_rb_io_taint_check(VALUE self, VALUE io) { } #endif -typedef int wait_bool; -#define wait_bool_to_ruby_bool(x) (x ? Qtrue : Qfalse) - #ifdef HAVE_RB_IO_WAIT_READABLE #define RB_IO_WAIT_READABLE_BUF 13 VALUE io_spec_rb_io_wait_readable(VALUE self, VALUE io, VALUE read_p) { int fd = io_spec_get_fd(io); char buf[RB_IO_WAIT_READABLE_BUF]; - wait_bool ret; + int ret, r, saved_errno; if (set_non_blocking(fd) == -1) rb_sys_fail("set_non_blocking failed"); if(RTEST(read_p)) { - if(read(fd, buf, RB_IO_WAIT_READABLE_BUF) != -1) { + if (read(fd, buf, RB_IO_WAIT_READABLE_BUF) != -1) { return Qnil; } + saved_errno = errno; rb_ivar_set(self, rb_intern("@write_data"), Qtrue); + errno = saved_errno; } ret = rb_io_wait_readable(fd); if(RTEST(read_p)) { - if(read(fd, buf, RB_IO_WAIT_READABLE_BUF) != 13) { - return Qnil; + r = read(fd, buf, RB_IO_WAIT_READABLE_BUF); + if (r != RB_IO_WAIT_READABLE_BUF) { + perror("read"); + return INT2FIX(r); } rb_ivar_set(self, rb_intern("@read_data"), rb_str_new(buf, RB_IO_WAIT_READABLE_BUF)); } - return wait_bool_to_ruby_bool(ret); + return ret ? Qtrue : Qfalse; } #endif #ifdef HAVE_RB_IO_WAIT_WRITABLE VALUE io_spec_rb_io_wait_writable(VALUE self, VALUE io) { - wait_bool ret; - ret = rb_io_wait_writable(io_spec_get_fd(io)); - return wait_bool_to_ruby_bool(ret); + int ret = rb_io_wait_writable(io_spec_get_fd(io)); + return ret ? Qtrue : Qfalse; } #endif diff --git a/spec/rubyspec/optional/capi/globals_spec.rb b/spec/rubyspec/optional/capi/globals_spec.rb index 2e748e78ac..c6e2ed912b 100644 --- a/spec/rubyspec/optional/capi/globals_spec.rb +++ b/spec/rubyspec/optional/capi/globals_spec.rb @@ -188,7 +188,7 @@ describe "CApiGlobalSpecs" do running = true end - Thread.pass until running + Thread.pass while thr.status and !running $_.should be_nil thr.join @@ -215,7 +215,7 @@ describe "CApiGlobalSpecs" do running = true end - Thread.pass until running + Thread.pass while thr.status and !running $_.should be_nil thr.join diff --git a/spec/rubyspec/optional/capi/object_spec.rb b/spec/rubyspec/optional/capi/object_spec.rb index 41224d0de3..b16d26ce47 100644 --- a/spec/rubyspec/optional/capi/object_spec.rb +++ b/spec/rubyspec/optional/capi/object_spec.rb @@ -175,6 +175,7 @@ describe "CApiObject" do describe "rb_require" do before :each do @saved_loaded_features = $LOADED_FEATURES.dup + $foo = nil end after :each do @@ -183,7 +184,6 @@ describe "CApiObject" do end it "requires a ruby file" do - $foo.should == nil $:.unshift File.dirname(__FILE__) @o.rb_require() $foo.should == 7 diff --git a/spec/rubyspec/optional/capi/thread_spec.rb b/spec/rubyspec/optional/capi/thread_spec.rb index fbce8016a2..0ca701e35d 100644 --- a/spec/rubyspec/optional/capi/thread_spec.rb +++ b/spec/rubyspec/optional/capi/thread_spec.rb @@ -107,6 +107,10 @@ describe "C-API Thread function" do # 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 |