Skip to content

Commit

Permalink
[ruby/fiddle] Use have_header and have_type to detect memory view ava…
Browse files Browse the repository at this point in the history
…ilability

Fix ruby/fiddle#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!!!

ruby/fiddle@3292929830
  • Loading branch information
kou authored and nobu committed Jul 13, 2021
1 parent 5c0d8c6 commit bb868f4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
4 changes: 0 additions & 4 deletions ext/fiddle/extconf.rb
Expand Up @@ -222,10 +222,6 @@ def enable_debug_build_flag(flags)
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)')
Expand Down
3 changes: 2 additions & 1 deletion ext/fiddle/fiddle.h
Expand Up @@ -2,6 +2,7 @@
#define FIDDLE_H

#include <ruby.h>
#include <ruby/version.h>
#include <errno.h>

#if defined(_WIN32)
Expand Down Expand Up @@ -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

Expand Down
12 changes: 5 additions & 7 deletions 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
Expand All @@ -17,9 +18,6 @@
# define UINTPTR2NUM UINT2NUM
#endif

#include <fiddle.h>

#ifdef FIDDLE_MEMORY_VIEW
VALUE rb_cMemoryView = Qnil;

struct memview_data {
Expand Down
8 changes: 4 additions & 4 deletions ext/fiddle/pointer.c
Expand Up @@ -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)
Expand Down

0 comments on commit bb868f4

Please sign in to comment.