* [PATCH 0/3] remove some Ruby 1.8 codepaths
@ 2023-09-10 18:49 Eric Wong
2023-09-10 18:49 ` [PATCH 1/3] my_fileno: drop Ruby 1.8 support, really require 1.9.3 Eric Wong
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Eric Wong @ 2023-09-10 18:49 UTC (permalink / raw)
To: kgio-public
I haven't been motivated to build 1.8 in ages due to
toolchain changes in distros.
Eric Wong (3):
my_fileno: drop Ruby 1.8 support, really require 1.9.3
sock_for_fd: drop 1.8/1.9/2.x/3.0-specific hacks
drop remaining 1.8 and fragile autopush code paths
ext/kgio/ancient_ruby.h | 24 -----------------
ext/kgio/autopush.c | 21 ---------------
ext/kgio/extconf.rb | 18 -------------
ext/kgio/kgio.h | 8 +-----
ext/kgio/my_fileno.h | 32 ++++------------------
ext/kgio/set_file_path.h | 22 ---------------
ext/kgio/sock_for_fd.h | 58 +---------------------------------------
ext/kgio/tryopen.c | 32 +---------------------
kgio.gemspec | 1 +
lib/kgio.rb | 5 ++++
10 files changed, 14 insertions(+), 207 deletions(-)
delete mode 100644 ext/kgio/ancient_ruby.h
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] my_fileno: drop Ruby 1.8 support, really require 1.9.3
2023-09-10 18:49 [PATCH 0/3] remove some Ruby 1.8 codepaths Eric Wong
@ 2023-09-10 18:49 ` Eric Wong
2023-09-10 18:49 ` [PATCH 2/3] sock_for_fd: drop 1.8/1.9/2.x/3.0-specific hacks Eric Wong
2023-09-10 18:49 ` [PATCH 3/3] drop remaining 1.8 and fragile autopush code paths Eric Wong
2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2023-09-10 18:49 UTC (permalink / raw)
To: kgio-public
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.
---
ext/kgio/my_fileno.h | 32 +++++---------------------------
kgio.gemspec | 1 +
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] sock_for_fd: drop 1.8/1.9/2.x/3.0-specific hacks
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
2023-09-10 18:49 ` [PATCH 3/3] drop remaining 1.8 and fragile autopush code paths Eric Wong
2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2023-09-10 18:49 UTC (permalink / raw)
To: kgio-public
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 */
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] drop remaining 1.8 and fragile autopush code paths
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 ` [PATCH 2/3] sock_for_fd: drop 1.8/1.9/2.x/3.0-specific hacks Eric Wong
@ 2023-09-10 18:49 ` Eric Wong
2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2023-09-10 18:49 UTC (permalink / raw)
To: kgio-public
Ruby 1.8 is long gone, and rb_io_t internals are going private
so we can't assign fptr->pathv and such, so rely on ivars for
that. TCP autopush never seemed worth it, but the ivar fallback
remains in case anybody wants to use it.
---
ext/kgio/ancient_ruby.h | 24 ------------------------
ext/kgio/autopush.c | 21 ---------------------
ext/kgio/extconf.rb | 18 ------------------
ext/kgio/kgio.h | 8 +-------
ext/kgio/set_file_path.h | 22 ----------------------
ext/kgio/tryopen.c | 32 +-------------------------------
lib/kgio.rb | 5 +++++
7 files changed, 7 insertions(+), 123 deletions(-)
delete mode 100644 ext/kgio/ancient_ruby.h
diff --git a/ext/kgio/ancient_ruby.h b/ext/kgio/ancient_ruby.h
deleted file mode 100644
index fb0a80b..0000000
--- a/ext/kgio/ancient_ruby.h
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifndef MISSING_ANCIENT_RUBY_H
-#define MISSING_ANCIENT_RUBY_H
-
-#ifndef HAVE_RB_STR_SET_LEN
-static void my_str_set_len(VALUE str, long len)
-{
- RSTRING(str)->len = len;
- RSTRING(str)->ptr[len] = '\0';
-}
-#define rb_str_set_len(str,len) my_str_set_len((str),(len))
-#endif /* ! HAVE_RB_STR_SET_LEN */
-
-#ifndef RSTRING_PTR
-# define RSTRING_PTR(s) (RSTRING(s)->ptr)
-#endif /* !defined(RSTRING_PTR) */
-#ifndef RSTRING_LEN
-# define RSTRING_LEN(s) (RSTRING(s)->len)
-#endif /* !defined(RSTRING_LEN) */
-
-#ifndef RARRAY_LEN
-# define RARRAY_LEN(s) (RARRAY(s)->len)
-#endif /* !defined(RARRAY_LEN) */
-
-#endif /* MISSING_ANCIENT_RUBY_H */
diff --git a/ext/kgio/autopush.c b/ext/kgio/autopush.c
index f9b9ef2..f81dd8a 100644
--- a/ext/kgio/autopush.c
+++ b/ext/kgio/autopush.c
@@ -39,26 +39,6 @@ enum autopush_state {
AUTOPUSH_STATE_ACCEPTOR = 3
};
-#if defined(R_CAST) && \
- defined(HAVE_TYPE_STRUCT_RFILE) && \
- defined(HAVE_TYPE_STRUCT_ROBJECT) && \
- ((SIZEOF_STRUCT_RFILE + SIZEOF_INT) <= (SIZEOF_STRUCT_ROBJECT))
-
-struct AutopushSocket {
- struct RFile rfile;
- enum autopush_state autopush_state;
-};
-
-static enum autopush_state state_get(VALUE io)
-{
- return ((struct AutopushSocket *)(io))->autopush_state;
-}
-
-static void state_set(VALUE io, enum autopush_state state)
-{
- ((struct AutopushSocket *)(io))->autopush_state = state;
-}
-#else
static enum autopush_state state_get(VALUE io)
{
VALUE val;
@@ -74,7 +54,6 @@ static void state_set(VALUE io, enum autopush_state state)
{
rb_ivar_set(io, id_autopush_state, INT2NUM(state));
}
-#endif /* IVAR fallback */
static enum autopush_state detect_acceptor_state(VALUE io);
static void push_pending_data(VALUE io);
diff --git a/ext/kgio/extconf.rb b/ext/kgio/extconf.rb
index 54063f5..a42fc9e 100644
--- a/ext/kgio/extconf.rb
+++ b/ext/kgio/extconf.rb
@@ -26,23 +26,6 @@ have_header("sys/select.h")
have_func("writev", "sys/uio.h")
-if have_header('ruby/io.h')
- rubyio = %w(ruby.h ruby/io.h)
- have_struct_member("rb_io_t", "fd", rubyio)
- have_struct_member("rb_io_t", "mode", rubyio)
- have_struct_member("rb_io_t", "pathv", rubyio)
-else
- rubyio = %w(ruby.h rubyio.h)
- rb_io_t = have_type("OpenFile", rubyio) ? "OpenFile" : "rb_io_t"
- have_struct_member(rb_io_t, "f", rubyio)
- have_struct_member(rb_io_t, "f2", rubyio)
- have_struct_member(rb_io_t, "mode", rubyio)
- have_struct_member(rb_io_t, "path", rubyio)
- have_func('rb_fdopen')
-end
-have_type("struct RFile", rubyio) and check_sizeof("struct RFile", rubyio)
-have_type("struct RObject") and check_sizeof("struct RObject")
-check_sizeof("int")
have_func('rb_io_ascii8bit_binmode')
have_func('rb_update_max_fd')
have_func('rb_fd_fix_cloexec')
@@ -51,7 +34,6 @@ have_header('ruby/thread.h')
have_func('rb_thread_call_without_gvl', %w{ruby/thread.h})
have_func('rb_thread_blocking_region')
have_func('rb_thread_io_blocking_region')
-have_func('rb_str_set_len')
have_func("rb_hash_clear", "ruby.h") # Ruby 2.0+
have_func('rb_time_interval')
have_func('rb_wait_for_single_fd')
diff --git a/ext/kgio/kgio.h b/ext/kgio/kgio.h
index c0630ae..87f2559 100644
--- a/ext/kgio/kgio.h
+++ b/ext/kgio/kgio.h
@@ -2,11 +2,7 @@
#define KGIO_H
#include <ruby.h>
-#ifdef HAVE_RUBY_IO_H
-# include <ruby/io.h>
-#else
-# include <rubyio.h>
-#endif
+#include <ruby/io.h>
#ifdef HAVE_RUBY_THREAD_H
# include <ruby/thread.h>
#endif
@@ -21,8 +17,6 @@
#include <assert.h>
#include <netdb.h>
-#include "ancient_ruby.h"
-
void init_kgio_wait(void);
void init_kgio_read(void);
void init_kgio_write(void);
diff --git a/ext/kgio/set_file_path.h b/ext/kgio/set_file_path.h
index 46603f1..756d9bb 100644
--- a/ext/kgio/set_file_path.h
+++ b/ext/kgio/set_file_path.h
@@ -1,27 +1,5 @@
/* We do not modify RSTRING in this file, so RSTRING_MODIFIED is not needed */
-#if defined(HAVE_RB_IO_T) && \
- defined(HAVE_TYPE_STRUCT_RFILE) && \
- defined(HAVE_ST_PATHV)
-/* MRI 1.9 */
-static void set_file_path(VALUE io, VALUE path)
-{
- rb_io_t *fptr = RFILE(io)->fptr;
- fptr->pathv = rb_str_new4(path);
-}
-#elif defined(HAVE_TYPE_OPENFILE) && \
- defined(HAVE_TYPE_STRUCT_RFILE) && \
- defined(HAVE_ST_PATH)
-/* MRI 1.8 */
-#include "util.h"
-static void set_file_path(VALUE io, VALUE path)
-{
- OpenFile *fptr = RFILE(io)->fptr;
- fptr->path = ruby_strdup(RSTRING_PTR(path));
-}
-#else
-/* Rubinius */
static void set_file_path(VALUE io, VALUE path)
{
rb_iv_set(io, "@path", rb_str_new4(path));
}
-#endif
diff --git a/ext/kgio/tryopen.c b/ext/kgio/tryopen.c
index d87cb17..87017a5 100644
--- a/ext/kgio/tryopen.c
+++ b/ext/kgio/tryopen.c
@@ -1,10 +1,6 @@
/* We do not modify RSTRING in this file, so RSTRING_MODIFIED is not needed */
#include <ruby.h>
-#ifdef HAVE_RUBY_IO_H
-# include <ruby/io.h>
-#else
-# include <rubyio.h>
-#endif
+#include <ruby/io.h>
#ifdef HAVE_RUBY_ST_H
# include <ruby/st.h>
@@ -17,7 +13,6 @@
#include <fcntl.h>
#include <errno.h>
#include "set_file_path.h"
-#include "ancient_ruby.h"
#include "kgio.h"
static ID id_for_fd, id_to_path, id_path;
@@ -41,27 +36,6 @@ static void * nogvl_open(void *ptr)
return (void *)fd;
}
-#ifndef KGIO_WITHOUT_GVL
-# define RUBY_UBF_IO ((void *)(-1))
-# include "rubysig.h"
-typedef void my_unblock_function_t(void *);
-typedef void *my_blocking_function_t(void *);
-static void * my_thread_blocking_region(
- my_blocking_function_t *fn, void *data1,
- my_unblock_function_t *ubf, void *data2)
-{
- void *rv;
-
- TRAP_BEG; /* for FIFO */
- rv = fn(data1);
- TRAP_END;
-
- return rv;
-}
-#define KGIO_WITHOUT_GVL(fn,data1,ubf,data2) \
- my_thread_blocking_region((fn),(data1),(ubf),(data2))
-#endif /* ! KGIO_WITHOUT_GVL */
-
/*
* call-seq:
*
@@ -157,10 +131,6 @@ void init_kgio_tryopen(void)
rb_define_singleton_method(cFile, "tryopen", s_tryopen, -1);
rb_include_module(cFile, mPipeMethods);
- if (!rb_funcall(cFile, rb_intern("method_defined?"), 1,
- ID2SYM(id_to_path)))
- rb_define_alias(cFile, "to_path", "path");
-
errno2sym = st_init_numtable();
tmp = rb_funcall(rb_mErrno, rb_intern("constants"), 0);
len = RARRAY_LEN(tmp);
diff --git a/lib/kgio.rb b/lib/kgio.rb
index 5de431b..bc86116 100644
--- a/lib/kgio.rb
+++ b/lib/kgio.rb
@@ -36,3 +36,8 @@ class Kgio::Pipe < IO
alias new pipe
end
end
+
+class Kgio::File < File # :nodoc:
+ attr_reader :path # cf. set_file_path
+ alias to_path path
+end
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-09-10 18:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 2/3] sock_for_fd: drop 1.8/1.9/2.x/3.0-specific hacks Eric Wong
2023-09-10 18:49 ` [PATCH 3/3] drop remaining 1.8 and fragile autopush code paths Eric Wong
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).