diff options
author | Sutou Kouhei <kou@clear-code.com> | 2021-07-05 10:45:48 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-07-13 19:37:46 +0900 |
commit | bb868f4814c09c978f20f224c5e99656bc8b9bee (patch) | |
tree | 0bfeb0e7494510d244c8cf21b830d69059d13f6c /ext | |
parent | 5c0d8c6369f92915bf99924f58f0763abe4f493e (diff) | |
download | ruby-bb868f4814c09c978f20f224c5e99656bc8b9bee.tar.gz |
[ruby/fiddle] Use have_header and have_type to detect memory view availability
Fix https://github.com/ruby/fiddle/pull/84
It may detect ruby/memory_view.h for system Ruby that is installed in
/usr.
We can use RUBY_API_VERSION_MAJOR to detect memory view availability
because memory view is available since Ruby 3.0.
Reported by Jun Aruga. Thanks!!!
https://github.com/ruby/fiddle/commit/3292929830
Diffstat (limited to 'ext')
-rw-r--r-- | ext/fiddle/extconf.rb | 4 | ||||
-rw-r--r-- | ext/fiddle/fiddle.h | 3 | ||||
-rw-r--r-- | ext/fiddle/memory_view.c | 12 | ||||
-rw-r--r-- | ext/fiddle/pointer.c | 8 |
4 files changed, 11 insertions, 16 deletions
diff --git a/ext/fiddle/extconf.rb b/ext/fiddle/extconf.rb index 6ca685317e..8cc98fb8f6 100644 --- a/ext/fiddle/extconf.rb +++ b/ext/fiddle/extconf.rb @@ -222,10 +222,6 @@ types.each do |type, signed| end end -if have_header("ruby/memory_view.h") - have_type("rb_memory_view_t", ["ruby/memory_view.h"]) -end - if libffi $LOCAL_LIBS.prepend("./#{libffi.a} ").strip! # to exts.mk $INCFLAGS.gsub!(/-I#{libffi.dir}/, '-I$(LIBFFI_DIR)') diff --git a/ext/fiddle/fiddle.h b/ext/fiddle/fiddle.h index dbad910d07..c5d7fa8016 100644 --- a/ext/fiddle/fiddle.h +++ b/ext/fiddle/fiddle.h @@ -2,6 +2,7 @@ #define FIDDLE_H #include <ruby.h> +#include <ruby/version.h> #include <errno.h> #if defined(_WIN32) @@ -189,7 +190,7 @@ #define ALIGN_INT32_T ALIGN_OF(int32_t) #define ALIGN_INT64_T ALIGN_OF(int64_t) -#ifdef HAVE_TYPE_RB_MEMORY_VIEW_T +#if RUBY_API_VERSION_MAJOR >= 3 # define FIDDLE_MEMORY_VIEW #endif diff --git a/ext/fiddle/memory_view.c b/ext/fiddle/memory_view.c index 3e260f94f9..c9df5fd2bd 100644 --- a/ext/fiddle/memory_view.c +++ b/ext/fiddle/memory_view.c @@ -1,10 +1,11 @@ +#include <fiddle.h> + +#ifdef FIDDLE_MEMORY_VIEW + #include <stdbool.h> #include <ruby/ruby.h> #include <ruby/encoding.h> - -#ifdef HAVE_RUBY_MEMORY_VIEW_H -# include <ruby/memory_view.h> -#endif +#include <ruby/memory_view.h> #if SIZEOF_INTPTR_T == SIZEOF_LONG_LONG # define INTPTR2NUM LL2NUM @@ -17,9 +18,6 @@ # define UINTPTR2NUM UINT2NUM #endif -#include <fiddle.h> - -#ifdef FIDDLE_MEMORY_VIEW VALUE rb_cMemoryView = Qnil; struct memview_data { diff --git a/ext/fiddle/pointer.c b/ext/fiddle/pointer.c index 9336f0431c..ae9eb166ec 100644 --- a/ext/fiddle/pointer.c +++ b/ext/fiddle/pointer.c @@ -6,13 +6,13 @@ #include <ruby/ruby.h> #include <ruby/io.h> -#ifdef HAVE_RUBY_MEMORY_VIEW_H -# include <ruby/memory_view.h> -#endif - #include <ctype.h> #include <fiddle.h> +#ifdef FIDDLE_MEMORY_VIEW +# include <ruby/memory_view.h> +#endif + #ifdef PRIsVALUE # define RB_OBJ_CLASSNAME(obj) rb_obj_class(obj) # define RB_OBJ_STRING(obj) (obj) |