kgio RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <bofh@yhbt.net>
To: kgio-public@yhbt.net
Subject: [PATCH 3/3] drop remaining 1.8 and fragile autopush code paths
Date: Sun, 10 Sep 2023 18:49:48 +0000	[thread overview]
Message-ID: <20230910184948.3907011-4-bofh@yhbt.net> (raw)
In-Reply-To: <20230910184948.3907011-1-bofh@yhbt.net>

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

      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 ` [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 [this message]

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-4-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).