diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 976f798..d92113e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -24,7 +24,7 @@ jobs: - "3.0" - "3.1" - "3.2" - # - "head" + - "head" experimental: [false] diff --git a/ext/cool.io/extconf.rb b/ext/cool.io/extconf.rb index af456d0..f990899 100644 --- a/ext/cool.io/extconf.rb +++ b/ext/cool.io/extconf.rb @@ -4,6 +4,7 @@ $defs << "-DRUBY_VERSION_CODE=#{RUBY_VERSION.gsub(/\D/, '')}" +have_func('rb_io_descriptor') have_func('rb_thread_blocking_region') have_func('rb_thread_call_without_gvl') have_func('rb_thread_alone') diff --git a/ext/cool.io/iowatcher.c b/ext/cool.io/iowatcher.c index 801893e..f723cfa 100644 --- a/ext/cool.io/iowatcher.c +++ b/ext/cool.io/iowatcher.c @@ -65,11 +65,6 @@ static VALUE Coolio_IOWatcher_initialize(int argc, VALUE *argv, VALUE self) char *flags_str; int events; struct Coolio_Watcher *watcher_data; -#if HAVE_RB_IO_T - rb_io_t *fptr; -#else - OpenFile *fptr; -#endif rb_scan_args(argc, argv, "11", &io, &flags); @@ -88,10 +83,20 @@ static VALUE Coolio_IOWatcher_initialize(int argc, VALUE *argv, VALUE self) rb_raise(rb_eArgError, "invalid event type: '%s' (must be 'r', 'w', or 'rw')", flags_str); Data_Get_Struct(self, struct Coolio_Watcher, watcher_data); - GetOpenFile(rb_convert_type(io, T_FILE, "IO", "to_io"), fptr); + io = rb_convert_type(io, T_FILE, "IO", "to_io"); watcher_data->dispatch_callback = Coolio_IOWatcher_dispatch_callback; +#ifdef HAVE_RB_IO_DESCRIPTOR + ev_io_init(&watcher_data->event_types.ev_io, Coolio_IOWatcher_libev_callback, rb_io_descriptor(io), events); +#else +#if defined(HAVE_RB_IO_T) + rb_io_t *fptr; +#else + OpenFile *fptr; +#endif + GetOpenFile(io, fptr); ev_io_init(&watcher_data->event_types.ev_io, Coolio_IOWatcher_libev_callback, FPTR_TO_FD(fptr), events); +#endif watcher_data->event_types.ev_io.data = (void *)self; return Qnil; diff --git a/ext/iobuffer/extconf.rb b/ext/iobuffer/extconf.rb index 4790c7f..e725c81 100644 --- a/ext/iobuffer/extconf.rb +++ b/ext/iobuffer/extconf.rb @@ -1,6 +1,7 @@ require 'mkmf' dir_config("iobuffer") +have_func("rb_io_descriptor") have_library("c", "main") if have_macro("HAVE_RB_IO_T", "ruby/io.h") have_struct_member("rb_io_t", "fd", "ruby/io.h") diff --git a/ext/iobuffer/iobuffer.c b/ext/iobuffer/iobuffer.c index 161f6a5..07ed3c0 100644 --- a/ext/iobuffer/iobuffer.c +++ b/ext/iobuffer/iobuffer.c @@ -378,17 +378,22 @@ IO_Buffer_read_from(VALUE self, VALUE io) { struct buffer *buf; int ret; -#if HAVE_RB_IO_T +#if defined(HAVE_RB_IO_T) || defined(HAVE_RB_IO_DESCRIPTOR) rb_io_t *fptr; #else OpenFile *fptr; #endif Data_Get_Struct(self, struct buffer, buf); - GetOpenFile(rb_convert_type(io, T_FILE, "IO", "to_io"), fptr); + io = rb_convert_type(io, T_FILE, "IO", "to_io"); + GetOpenFile(io, fptr); rb_io_set_nonblock(fptr); +#ifdef HAVE_RB_IO_DESCRIPTOR + ret = buffer_read_from(buf, rb_io_descriptor(io)); +#else ret = buffer_read_from(buf, FPTR_TO_FD(fptr)); +#endif return ret == -1 ? Qnil : INT2NUM(ret); } @@ -404,17 +409,22 @@ static VALUE IO_Buffer_write_to(VALUE self, VALUE io) { struct buffer *buf; -#if HAVE_RB_IO_T +#if defined(HAVE_RB_IO_T) || defined(HAVE_RB_IO_DESCRIPTOR) rb_io_t *fptr; #else OpenFile *fptr; #endif Data_Get_Struct(self, struct buffer, buf); - GetOpenFile(rb_convert_type(io, T_FILE, "IO", "to_io"), fptr); + io = rb_convert_type(io, T_FILE, "IO", "to_io"); + GetOpenFile(io, fptr); rb_io_set_nonblock(fptr); +#ifdef HAVE_RB_IO_DESCRIPTOR + return INT2NUM(buffer_write_to(buf, rb_io_descriptor(io))); +#else return INT2NUM(buffer_write_to(buf, FPTR_TO_FD(fptr))); +#endif } /*