From 6d8ad6c489f41dfb5553d0933793eb5c84e0cc29 Mon Sep 17 00:00:00 2001 From: kosaki Date: Mon, 17 Dec 2012 05:04:04 +0000 Subject: * io.c (io_flush_buffer_sync2): avoid to return 0. because rb_thread_call_without_gvl2 uses 0 internally. * io.c (io_flush_buffer_async2): adapt the above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38422 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ io.c | 24 ++++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index ba1794a796..abaf992047 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon Dec 17 13:56:55 2012 KOSAKI Motohiro + + * io.c (io_flush_buffer_sync2): avoid to return 0. because + rb_thread_call_without_gvl2 uses 0 internally. + * io.c (io_flush_buffer_async2): adapt the above. + Mon Dec 17 12:05:32 2012 Eric Hodel * doc/syntax/methods.rdoc: Added a description of singleton methods. diff --git a/io.c b/io.c index bfafe636d8..3047da4380 100644 --- a/io.c +++ b/io.c @@ -975,7 +975,13 @@ io_flush_buffer_sync(void *arg) static void* io_flush_buffer_sync2(void *arg) { - return (void*)io_flush_buffer_sync(arg); + VALUE result = io_flush_buffer_sync(arg); + + /* + * rb_thread_call_without_gvl2 uses 0 as interrupted. + * So, we need to avoid to use 0. + */ + return !result ? (void*)1 : (void*)result; } static VALUE @@ -989,17 +995,19 @@ static VALUE io_flush_buffer_async2(VALUE arg) { rb_io_t *fptr = (rb_io_t *)arg; - void *ret; + VALUE ret; - ret = rb_thread_call_without_gvl2(io_flush_buffer_sync2, fptr, - RUBY_UBF_IO, NULL); + ret = (VALUE)rb_thread_call_without_gvl2(io_flush_buffer_sync2, fptr, + RUBY_UBF_IO, NULL); - /* pending async interrupt is there. */ if (!ret) { + /* pending async interrupt is there. */ errno = EAGAIN; - return (VALUE)-1; - } - return (VALUE) ret; + return -1; + } else if (ret == 1) { + return 0; + } else + return ret; } static inline int -- cgit v1.2.3