[前][次][番号順一覧][スレッド一覧]

ruby-changes:66735

From: Nobuyoshi <ko1@a...>
Date: Thu, 8 Jul 2021 20:06:40 +0900 (JST)
Subject: [ruby-changes:66735] 524513be39 (master): mkmf.rb: try linking at try_var

https://git.ruby-lang.org/ruby.git/commit/?id=524513be39

From 524513be399e81bb170ec88aa0d501f33cbde8c3 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Thu, 8 Jul 2021 16:56:32 +0900
Subject: mkmf.rb: try linking at try_var

To check for variables accessible but not declared.
---
 lib/mkmf.rb                | 10 +++++++++-
 test/mkmf/test_have_var.rb | 17 +++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)
 create mode 100644 test/mkmf/test_have_var.rb

diff --git a/lib/mkmf.rb b/lib/mkmf.rb
index 3a84aba..04b5f26 100644
--- a/lib/mkmf.rb
+++ b/lib/mkmf.rb
@@ -812,13 +812,21 @@ SRC https://github.com/ruby/ruby/blob/trunk/lib/mkmf.rb#L812
   # You should use +have_var+ rather than +try_var+.
   def try_var(var, headers = nil, opt = "", &b)
     headers = cpp_include(headers)
-    try_compile(<<"SRC", opt, &b)
+    try_compile(<<"SRC", opt, &b) or
 #{headers}
 /*top*/
 extern int t(void);
 #{MAIN_DOES_NOTHING 't'}
 int t(void) { const volatile void *volatile p; p = &(&#{var})[0]; return !p; }
 SRC
+    try_link(<<"SRC", opt, &b)
+#{headers}
+/*top*/
+extern int t(void);
+#{MAIN_DOES_NOTHING 't'}
+extern int #{var};
+int t(void) { const volatile void *volatile p; p = &(&#{var})[0]; return !p; }
+SRC
   end
 
   # Returns whether or not the +src+ can be preprocessed with the C
diff --git a/test/mkmf/test_have_var.rb b/test/mkmf/test_have_var.rb
new file mode 100644
index 0000000..5367ec2
--- /dev/null
+++ b/test/mkmf/test_have_var.rb
@@ -0,0 +1,17 @@ https://github.com/ruby/ruby/blob/trunk/test/mkmf/test_have_var.rb#L1
+# frozen_string_literal: false
+require_relative 'base'
+require 'tempfile'
+
+class TestMkmf
+  class TestHaveVar < TestMkmf
+    def test_have_var
+      assert_equal(true, have_var("ruby_version"), MKMFLOG)
+      assert_include($defs, '-DHAVE_RUBY_VERSION')
+    end
+
+    def test_not_have_var
+      assert_equal(false, have_var("rb_vm_something_flag"), MKMFLOG)
+      assert_not_include($defs, '-DHAVE_RB_VM_SOMETHING_FLAG')
+    end
+  end
+end
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]