raindrops.git  about / heads / tags
real-time stats for preforking Rack servers
   commit b3212417cc3e7cc44aa9e1ffe89b0d62ef3fdab5 (patch)
   parent d843802 my_fileno: drop Ruby 1.8 support and simplify
     tree 989dc805c36cff204b5f3ef7b33cf5e65c3c4dfb
   author Samuel Williams <samuel.williams@oriontransfer.co.nz>  2023-06-09 19:48:05 +0900
committer Eric Wong <bofh@yhbt.net>                              2023-06-11 20:17:50 +0000

Improve compatibility with Ruby 3.3+

Prefer to use `rb_io_descriptor` in my_fileno if it is available. This
function was introduced in Ruby 3.1. Ruby 3.3 will deprecate access to
all internal fields of `rb_io_t`.

This change is necessary for compatibility with the current
ruby.git master:

	https://bugs.ruby-lang.org/issues/19057#note-17
---
 ext/raindrops/extconf.rb  | 1 +
 ext/raindrops/my_fileno.h | 7 +++++++
 2 files changed, 8 insertions(+)

diff --git a/ext/raindrops/extconf.rb b/ext/raindrops/extconf.rb
index 792e509..1733703 100644
--- a/ext/raindrops/extconf.rb
+++ b/ext/raindrops/extconf.rb
@@ -4,6 +4,7 @@ require 'shellwords'
 dir_config('atomic_ops')
 have_func('mmap', 'sys/mman.h') or abort 'mmap() not found'
 have_func('munmap', 'sys/mman.h') or abort 'munmap() not found'
+have_func('rb_io_descriptor')
 
 $CPPFLAGS += " -D_GNU_SOURCE "
 have_func('mremap', 'sys/mman.h')
diff --git a/ext/raindrops/my_fileno.h b/ext/raindrops/my_fileno.h
index 4c8ffba..00c5d29 100644
--- a/ext/raindrops/my_fileno.h
+++ b/ext/raindrops/my_fileno.h
@@ -3,6 +3,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;
 
 	if (TYPE(io) != T_FILE)
@@ -12,4 +18,5 @@ static int my_fileno(VALUE io)
 	if (fptr->fd < 0)
 		rb_raise(rb_eIOError, "closed stream");
 	return fptr->fd;
+#endif
 }


glossary
--------
Commit objects reference one tree, and zero or more parents.

Single parent commits can typically generate a patch in
unified diff format via `git format-patch'.

Multiple parents means the commit is a merge.

Root commits have no ancestor.  Note that it is
possible to have multiple root commits when merging independent histories.

Every commit references one top-level tree object.

git clone http://yhbt.net/raindrops.git