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: X-Spam-Status: No, score=-4.1 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id CB9111F560 for ; Sun, 10 Sep 2023 18:49:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yhbt.net; s=selector1; t=1694371788; bh=K8PEId0YLl3SXiRtRAXhuAOzPdkfic/MA0wbnVlsrC4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=XeSzsYraoaZw31rzc/5VTPbtCH7Btr/X6UYzrgjrdDeXvfG6EYJB6pcpjwzzYb7Wq 1YAXgWZbyoL4TZdKipcdcsTh+KQ64m5RhVfsokof1k11guUxH3SM2insLfOdq7e5To irpx9UaHwcJ5lBJovstoloKomq8LP5FRq3jHH3sY= From: Eric Wong To: kgio-public@yhbt.net Subject: [PATCH 1/3] my_fileno: drop Ruby 1.8 support, really require 1.9.3 Date: Sun, 10 Sep 2023 18:49:46 +0000 Message-ID: <20230910184948.3907011-2-bofh@yhbt.net> In-Reply-To: <20230910184948.3907011-1-bofh@yhbt.net> References: <20230910184948.3907011-1-bofh@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: I have no idea if 1.8 has worked in a while, but maybe it has. `rb_io_get_io' has been public API since Ruby 1.9.2, so we can use it everywhere. `rb_io_check_closed' has existed since the initial cvs2svn imports of Ruby, so it's safe to depend on for Ruby v1.9.3..v3.0. --- ext/kgio/my_fileno.h | 32 +++++--------------------------- kgio.gemspec | 1 + 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/ext/kgio/my_fileno.h b/ext/kgio/my_fileno.h index d9bda3c..6dbd083 100644 --- a/ext/kgio/my_fileno.h +++ b/ext/kgio/my_fileno.h @@ -1,30 +1,11 @@ #include -#ifdef HAVE_RUBY_IO_H -# include -#else -# include -# include -#endif - -#if ! HAVE_RB_IO_T -# define rb_io_t OpenFile -#endif - -#ifdef GetReadFile -# define FPTR_TO_FD(fptr) (fileno(GetReadFile(fptr))) -#else -# if !HAVE_RB_IO_T || (RUBY_VERSION_MAJOR == 1 && RUBY_VERSION_MINOR == 8) -# define FPTR_TO_FD(fptr) fileno(fptr->f) -# else -# define FPTR_TO_FD(fptr) fptr->fd -# endif -#endif +#include 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"); + io = rb_io_get_io(io); return rb_io_descriptor(io); #else @@ -32,12 +13,9 @@ static int my_fileno(VALUE io) int fd; if (TYPE(io) != T_FILE) - io = rb_convert_type(io, T_FILE, "IO", "to_io"); + io = rb_io_get_io(io); GetOpenFile(io, fptr); - fd = FPTR_TO_FD(fptr); - - if (fd < 0) - rb_raise(rb_eIOError, "closed stream"); - return fd; + rb_io_check_closed(fptr); + return fptr->fd; #endif } diff --git a/kgio.gemspec b/kgio.gemspec index 1c3f26a..edba39f 100644 --- a/kgio.gemspec +++ b/kgio.gemspec @@ -21,4 +21,5 @@ Gem::Specification.new do |s| # s.add_development_dependency('strace_me', '~> 1.0') # Linux only s.licenses = %w(LGPL-2.1+) + s.required_ruby_version = '>= 1.9.3' # kgio is deprecated anyways... end