kgio RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <bofh@yhbt.net>
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	[thread overview]
Message-ID: <20230910184948.3907011-2-bofh@yhbt.net> (raw)
In-Reply-To: <20230910184948.3907011-1-bofh@yhbt.net>

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 <ruby.h>
-#ifdef HAVE_RUBY_IO_H
-#  include <ruby/io.h>
-#else
-#  include <stdio.h>
-#  include <rubyio.h>
-#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 <ruby/io.h>
 
 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

  reply	other threads:[~2023-09-10 18:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-10 18:49 [PATCH 0/3] remove some Ruby 1.8 codepaths Eric Wong
2023-09-10 18:49 ` Eric Wong [this message]
2023-09-10 18:49 ` [PATCH 2/3] sock_for_fd: drop 1.8/1.9/2.x/3.0-specific hacks Eric Wong
2023-09-10 18:49 ` [PATCH 3/3] drop remaining 1.8 and fragile autopush code paths Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/kgio/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230910184948.3907011-2-bofh@yhbt.net \
    --to=bofh@yhbt.net \
    --cc=kgio-public@yhbt.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/kgio.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).