From 30e0f51a5df6a207ebeec105317cbb4cb5566be6 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 10 Dec 2010 09:11:48 +0000 Subject: [PATCH] * lib/mkmf.rb (check_signedness): should use the prelude code. [ruby-dev:42731] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30160 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 ++++- lib/mkmf.rb | 4 ++-- test/mkmf/base.rb | 7 +++++++ test/mkmf/test_signedness.rb | 27 +++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 test/mkmf/test_signedness.rb diff --git a/ChangeLog b/ChangeLog index 6497a832c5..f6b97785a7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,7 @@ -Fri Dec 10 18:11:08 2010 Nobuyoshi Nakada +Fri Dec 10 18:11:45 2010 Nobuyoshi Nakada + + * lib/mkmf.rb (check_signedness): should use the prelude code. + [ruby-dev:42731] * lib/mkmf.rb (Logging.log_close): separate from Logging.logfile. diff --git a/lib/mkmf.rb b/lib/mkmf.rb index d289cefca7..c25270dbc6 100644 --- a/lib/mkmf.rb +++ b/lib/mkmf.rb @@ -1167,10 +1167,10 @@ end # done. # def check_signedness(type, headers = nil, opts = nil, &b) - typedef, member, _ = typedef_expr(type, headers) + typedef, member, prelude = typedef_expr(type, headers) signed = nil checking_for("signedness of #{type}", STRING_OR_FAILED_FORMAT) do - signed = try_signedness(typedef, member, headers, opts, &b) or next nil + signed = try_signedness(typedef, member, [prelude], opts, &b) or next nil $defs.push("-DSIGNEDNESS_OF_%s=%+d" % [type.tr_cpp, signed]) signed < 0 ? "signed" : "unsigned" end diff --git a/test/mkmf/base.rb b/test/mkmf/base.rb index 4ceb35087a..f82952d0c5 100644 --- a/test/mkmf/base.rb +++ b/test/mkmf/base.rb @@ -13,6 +13,13 @@ class TestMkmf < Test::Unit::TestCase class << MKMFLOG alias to_s call end + def mkmflog(msg) + log = proc {MKMFLOG[] << msg} + class << log + alias to_s call + end + log + end def setup @tmpdir = Dir.mktmpdir diff --git a/test/mkmf/test_signedness.rb b/test/mkmf/test_signedness.rb new file mode 100644 index 0000000000..97fc1078d6 --- /dev/null +++ b/test/mkmf/test_signedness.rb @@ -0,0 +1,27 @@ +require_relative 'base' + +class TestMkmf + class TestSignedness < TestMkmf + def test_typeof_builtin + bug4144 = '[ruby-dev:42731]' + [["", "-1"], ["signed ", "-1"], ["unsigned ", "+1"]].each do |signed, expect| + %w[short int long].each do |type| + assert_equal(expect.to_i, mkmf {check_signedness(signed+type)}, mkmflog(bug4144)) + end + end + end + + def test_typeof_typedef + [["", "-1"], ["signed ", "-1"], ["unsigned ", "+1"]].each do |signed, expect| + %w[short int long].each do |type| + open("confdefs.h", "w") {|f| + f.puts "typedef #{signed}#{type} test1_t;" + } + $defs.clear + assert_equal(expect.to_i, mkmf {check_signedness("test1_t", "confdefs.h")}, MKMFLOG) + assert_includes($defs, "-DSIGNEDNESS_OF_TEST1_T=#{expect}") + end + end + end + end +end