ruby-changes:11451
From: nobu <ko1@a...>
Date: Fri, 27 Mar 2009 12:56:58 +0900 (JST)
Subject: [ruby-changes:11451] Ruby:r23076 (trunk): * lib/mkmf.rb (what_type?): checks more restrictively, and
nobu 2009-03-27 12:56:46 +0900 (Fri, 27 Mar 2009) New Revision: 23076 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=23076 Log: * lib/mkmf.rb (what_type?): checks more restrictively, and supports universal binary. Modified files: trunk/ChangeLog trunk/lib/mkmf.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 23075) +++ ChangeLog (revision 23076) @@ -1,3 +1,8 @@ +Fri Mar 27 12:56:44 2009 Nobuyoshi Nakada <nobu@r...> + + * lib/mkmf.rb (what_type?): checks more restrictively, and + supports universal binary. + Fri Mar 27 01:33:37 2009 Tanaka Akira <akr@f...> * time.c (time_cmp): negate the result of reverse comparison. Index: lib/mkmf.rb =================================================================== --- lib/mkmf.rb (revision 23075) +++ lib/mkmf.rb (revision 23076) @@ -372,6 +372,7 @@ def link_command(ldflags, opt="", libpath=$DEFLIBPATH|$LIBPATH) conf = RbConfig::CONFIG.merge('hdrdir' => $hdrdir.quote, 'src' => CONFTEST_C, + 'extout' => $extout, 'arch_hdrdir' => "#$arch_hdrdir", 'top_srcdir' => $top_srcdir.quote, 'INCFLAGS' => "#$INCFLAGS", @@ -387,6 +388,7 @@ def cc_command(opt="") conf = RbConfig::CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote, + 'extout' => $extout, 'arch_hdrdir' => "#$arch_hdrdir", 'top_srcdir' => $top_srcdir.quote) RbConfig::expand("$(CC) #$INCFLAGS #$CPPFLAGS #$CFLAGS #$ARCH_FLAG #{opt} -c #{CONFTEST_C}", @@ -395,6 +397,7 @@ def cpp_command(outfile, opt="") conf = RbConfig::CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote, + 'extout' => $extout, 'arch_hdrdir' => "#$arch_hdrdir", 'top_srcdir' => $top_srcdir.quote) RbConfig::expand("$(CPP) #$INCFLAGS #$CPPFLAGS #$CFLAGS #{opt} #{CONFTEST_C} #{outfile}", @@ -983,7 +986,7 @@ prelude << "typedef #{typename} rbcv_typedef_;\n" prelude << "static rbcv_typedef_ *rbcv_ptr_;\n" prelude = [prelude] - expr = "sizeof((*rbcv_ptr_)#{"."<<member if member})" + expr = "sizeof((*rbcv_ptr_)#{"." << member if member})" fmt = "%s" def fmt.%(x) x ? super : "failed" @@ -1028,11 +1031,21 @@ def what_type?(type, member = nil, headers = nil, &b) m = "#{type}" - name = type + var = "*rbcv_var_" + func = "rbcv_func_(void)" if member m << "." << member - name = "(((#{type} *)0)->#{member})" + else + type, member = type.split('.', 2) end + prelude = cpp_include(headers).split(/$/) + prelude << "typedef #{type} rbcv_typedef_;\n" + prelude << "static rbcv_typedef_ #{var_};\n" + prelude << "extern rbcv_typedef_ #{func};\n" + headers = [prelude] + if member + var = "(#{var}).#{member}" + end fmt = "seems %s" def fmt.%(x) x ? super : "unknown" @@ -1040,21 +1053,24 @@ checking_for checking_message(m, headers), fmt do if scalar_ptr_type?(type, member, headers, &b) if try_static_assert("sizeof(*#{name}) == 1", headers) - "string" + return "string" end + ptr = "*" elsif scalar_type?(type, member, headers, &b) - if try_static_assert("sizeof(#{name}) > sizeof(long)", headers) - "long long" - elsif try_static_assert("sizeof(#{name}) > sizeof(int)", headers) - "long" - elsif try_static_assert("sizeof(#{name}) > sizeof(short)", headers) - "int" - elsif try_static_assert("sizeof(#{name}) > 1", headers) - "short" - else - "char" - end + ptr = "" + else + return end + unsigned = try_static_assert("(rbcv_typedef_)-1 < 0", headers) ? "unsigned" : "" + [ + unsigned, + (UNIVERSAL_INTS+["short"]).find do |t| + prelude = headers + [["static #{unsigned} #{t} #{ptr}#{name};\n", + "extern #{unsigned} #{t} #{ptr}#{func};\n"]] + try_static_assert("sizeof(#{ptr}#{name}) == sizeof(#{unsigned}#{t})", prelude) + end, + ptr + ].compact.join(" ") end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/