From: Samuel Williams <samuel.williams@oriontransfer.co.nz>
To: raindrops-public@yhbt.net
Cc: Samuel Williams <samuel.williams@oriontransfer.co.nz>
Subject: [PATCH] Prefer to use rb_io_descriptor in my_fileno
Date: Fri, 9 Jun 2023 17:58:06 +0900 [thread overview]
Message-ID: <20230609085806.37650-1-samuel.williams@oriontransfer.co.nz> (raw)
---
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 @@
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
}
--
2.39.2 (Apple Git-143)
next reply other threads:[~2023-06-09 8:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-09 8:58 Samuel Williams [this message]
2023-06-09 10:16 ` [PATCH] Prefer to use rb_io_descriptor in my_fileno Eric Wong
[not found] <5679D720-AD66-4471-9061-625159E71514@oriontransfer.co.nz>
2023-06-09 11:01 ` Samuel Williams
-- strict thread matches above, loose matches on Subject: below --
2023-06-10 7:30 Jean Boussier
2023-06-11 21:39 ` 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/raindrops/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230609085806.37650-1-samuel.williams@oriontransfer.co.nz \
--to=samuel.williams@oriontransfer.co.nz \
--cc=raindrops-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/raindrops.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).