about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <bofh@yhbt.net>2023-09-10 18:49:46 +0000
committerEric Wong <bofh@yhbt.net>2023-09-10 20:11:21 +0000
commit586ab4d80f44592914e5e0505ceeb630c68432f3 (patch)
tree304972e45c5c05182eb1f6ba36c2a1a20c616428
parent6e0885091087d06658734ce7397a9f37146925bc (diff)
downloadkgio-586ab4d80f44592914e5e0505ceeb630c68432f3.tar.gz
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.
-rw-r--r--ext/kgio/my_fileno.h32
-rw-r--r--kgio.gemspec1
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