From a04f6057a94ae8413fc6d1e7b74bfa6b9d802285 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Mon, 12 Jun 2023 10:21:31 +0200 Subject: [PATCH] Use rb_io_descriptor if available for Ruby 3.3 compatibility Ref: https://bugs.ruby-lang.org/issues/19057#note-17 Ruby 3.3 no longer fully expose rb_io_t which cause kgio to think it's being compiled on an older Ruby. The prefered API to use from Ruby 3.1 onwards is rb_io_descriptor. --- ext/kgio/extconf.rb | 1 + ext/kgio/my_fileno.h | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/ext/kgio/extconf.rb b/ext/kgio/extconf.rb index 5b0b74a..54063f5 100644 --- a/ext/kgio/extconf.rb +++ b/ext/kgio/extconf.rb @@ -7,6 +7,7 @@ end have_type('clockid_t', 'time.h') have_library('rt', 'clock_gettime', 'time.h') +have_func('rb_io_descriptor') # taken from ext/socket/extconf.rb in ruby/trunk: # OpenSolaris: diff --git a/ext/kgio/my_fileno.h b/ext/kgio/my_fileno.h index bdf1a5f..d9bda3c 100644 --- a/ext/kgio/my_fileno.h +++ b/ext/kgio/my_fileno.h @@ -22,6 +22,12 @@ static int my_fileno(VALUE io) { +#ifdef HAVE_RB_IO_DESCRIPTOR + if (TYPE(io) != T_FILE) + io = rb_convert_type(io, T_FILE, "IO", "to_io"); + + return rb_io_descriptor(io); +#else rb_io_t *fptr; int fd; @@ -33,4 +39,5 @@ static int my_fileno(VALUE io) if (fd < 0) rb_raise(rb_eIOError, "closed stream"); return fd; +#endif }