From cb4eac178dcabcc08d7f6808983286b5e32af3fa Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 10 Sep 2023 18:49:48 +0000 Subject: drop remaining 1.8 and fragile autopush code paths 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 -#ifdef HAVE_RUBY_IO_H -# include -#else -# include -#endif +#include #ifdef HAVE_RUBY_THREAD_H # include #endif @@ -21,8 +17,6 @@ #include #include -#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 -#ifdef HAVE_RUBY_IO_H -# include -#else -# include -#endif +#include #ifdef HAVE_RUBY_ST_H # include @@ -17,7 +13,6 @@ #include #include #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 -- cgit v1.2.3-24-ge0c7