From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS63949 194.195.248.0/21 X-Spam-Status: No, score=-3.0 required=3.0 tests=AWL,BAYES_00,SPF_HELO_NONE, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from mail.oriontransfer.net (mail.oriontransfer.net [194.195.253.146]) by dcvr.yhbt.net (Postfix) with ESMTP id CB07D1F406 for ; Mon, 28 Aug 2023 23:47:16 +0000 (UTC) Received: from localhost.localdomain (unknown [203.86.197.151]) by mail.oriontransfer.net (Postfix) with ESMTPSA id EC2E82AFB9; Mon, 28 Aug 2023 23:47:15 +0000 (UTC) From: Samuel Williams To: kgio-public@yhbt.net Cc: Jean Boussier Subject: [PATCH] Use rb_io_descriptor if available for Ruby 3.3 compatibility Date: Tue, 29 Aug 2023 11:46:40 +1200 Message-Id: <20230828234640.74866-1-samuel.williams@oriontransfer.co.nz> X-Mailer: git-send-email 2.39.2 (Apple Git-143) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: From: Jean Boussier 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 @@ unless have_macro('CLOCK_MONOTONIC', 'time.h') 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 } -- 2.39.2 (Apple Git-143)