Skip to content

Commit

Permalink
Support Ruby 3.3 (#79)
Browse files Browse the repository at this point in the history
Co-authored-by: Samuel Williams <[email protected]>
  • Loading branch information
k0kubun and ioquatix authored Aug 3, 2023
1 parent 6956af8 commit 273ca95
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- "3.0"
- "3.1"
- "3.2"
# - "head"
- "head"

experimental: [false]

Expand Down
1 change: 1 addition & 0 deletions ext/cool.io/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
17 changes: 11 additions & 6 deletions ext/cool.io/iowatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions ext/iobuffer/extconf.rb
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
18 changes: 14 additions & 4 deletions ext/iobuffer/iobuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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
}

/*
Expand Down

0 comments on commit 273ca95

Please sign in to comment.