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: AS63949 194.195.248.0/21 X-Spam-Status: No, score=-3.0 required=3.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from mail.oriontransfer.net (mail.oriontransfer.net [194.195.253.146]) by dcvr.yhbt.net (Postfix) with ESMTP id 29AAA1F542 for ; Fri, 9 Jun 2023 08:58:42 +0000 (UTC) Received: from localhost.localdomain (sp49-97-92-87.msc.spmode.ne.jp [49.97.92.87]) by mail.oriontransfer.net (Postfix) with ESMTPSA id C1EAD2B05B; Fri, 9 Jun 2023 08:58:39 +0000 (UTC) From: Samuel Williams To: raindrops-public@yhbt.net Cc: Samuel Williams Subject: [PATCH] Prefer to use rb_io_descriptor in my_fileno Date: Fri, 9 Jun 2023 17:58:06 +0900 Message-Id: <20230609085806.37650-1-samuel.williams@oriontransfer.co.nz> X-Mailer: git-send-email 2.39.2 (Apple Git-143) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: --- 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)