mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
mkmf.rb: try linking at try_var
To check for variables accessible but not declared.
This commit is contained in:
parent
d6cf4c0c99
commit
524513be39
2 changed files with 26 additions and 1 deletions
10
lib/mkmf.rb
10
lib/mkmf.rb
|
@ -812,12 +812,20 @@ SRC
|
|||
# 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
|
||||
|
||||
|
|
17
test/mkmf/test_have_var.rb
Normal file
17
test/mkmf/test_have_var.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
# 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
|
Loading…
Reference in a new issue