From: Eric Wong <bofh@yhbt.net>
To: kgio-public@yhbt.net
Subject: [PATCH 2/3] sock_for_fd: drop 1.8/1.9/2.x/3.0-specific hacks
Date: Sun, 10 Sep 2023 18:49:47 +0000 [thread overview]
Message-ID: <20230910184948.3907011-3-bofh@yhbt.net> (raw)
In-Reply-To: <20230910184948.3907011-1-bofh@yhbt.net>
The generic version works for all Rubies
---
ext/kgio/sock_for_fd.h | 58 +-----------------------------------------
1 file changed, 1 insertion(+), 57 deletions(-)
diff --git a/ext/kgio/sock_for_fd.h b/ext/kgio/sock_for_fd.h
index 55f9ccb..cfec302 100644
--- a/ext/kgio/sock_for_fd.h
+++ b/ext/kgio/sock_for_fd.h
@@ -1,71 +1,15 @@
#ifndef SOCK_FOR_FD_H
#define SOCK_FOR_FD_H
#include <ruby.h>
-#ifdef HAVE_RUBY_IO_H
-# include <ruby/io.h>
-#else
-# include <stdio.h>
-# include <rubyio.h>
-#endif
-#if defined(MakeOpenFile) && \
- defined(HAVE_RB_IO_T) && (HAVE_RB_IO_T == 1) && \
- defined(HAVE_RB_IO_ASCII8BIT_BINMODE) && \
- defined(HAVE_ST_FD) && \
- defined(HAVE_ST_MODE)
-# define SOCK_FOR_FD (19)
-# define FMODE_NOREVLOOKUP 0x100
-#elif defined(MakeOpenFile) && \
- (defined(OpenFile) || defined(HAVE_RB_IO_T)) && \
- defined(HAVE_RB_FDOPEN) && \
- defined(HAVE_ST_F) && \
- defined(HAVE_ST_F2) && \
- defined(HAVE_ST_MODE)
-# define SOCK_FOR_FD (18)
-#else
-# define SOCK_FOR_FD (-1)
-#endif
-
-#if SOCK_FOR_FD == 19 /* modeled after ext/socket/init.c */
-static VALUE sock_for_fd(VALUE klass, int fd)
-{
- VALUE sock;
- rb_io_t *fp;
-
- rb_update_max_fd(fd); /* 1.9.3+ API */
- sock = rb_obj_alloc(klass);
- MakeOpenFile(sock, fp);
- fp->fd = fd;
- fp->mode = FMODE_READWRITE|FMODE_DUPLEX|FMODE_NOREVLOOKUP;
- rb_io_ascii8bit_binmode(sock);
- rb_io_synchronized(fp);
- return sock;
-}
-#elif SOCK_FOR_FD == 18 /* modeled after init_sock() in ext/socket/socket.c */
-static VALUE sock_for_fd(VALUE klass, int fd)
-{
- VALUE sock = rb_obj_alloc(klass);
- OpenFile *fp;
-
- MakeOpenFile(sock, fp);
- fp->f = rb_fdopen(fd, "r");
- fp->f2 = rb_fdopen(fd, "w");
- fp->mode = FMODE_READWRITE;
- rb_io_synchronized(fp);
- return sock;
-}
-#else /* Rubinius, et al. */
static ID id_for_fd;
static VALUE sock_for_fd(VALUE klass, int fd)
{
return rb_funcall(klass, id_for_fd, 1, INT2NUM(fd));
}
+
static void init_sock_for_fd(void)
{
id_for_fd = rb_intern("for_fd");
}
-#endif /* sock_for_fd */
-#if SOCK_FOR_FD > 0
-# define init_sock_for_fd() for (;0;)
-#endif
#endif /* SOCK_FOR_FD_H */
next prev parent 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 ` [PATCH 1/3] my_fileno: drop Ruby 1.8 support, really require 1.9.3 Eric Wong
2023-09-10 18:49 ` Eric Wong [this message]
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-3-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).