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

ruby-changes:26856

From: nobu <ko1@a...>
Date: Wed, 23 Jan 2013 16:18:17 +0900 (JST)
Subject: [ruby-changes:26856] nobu:r38908 (trunk): mkmf.rb: large unsigned

nobu	2013-01-23 16:18:06 +0900 (Wed, 23 Jan 2013)

  New Revision: 38908

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38908

  Log:
    mkmf.rb: large unsigned
    
    * lib/mkmf.rb (MakeMakefile#try_constant): fix for large unsigned.

  Modified files:
    trunk/ChangeLog
    trunk/lib/mkmf.rb
    trunk/test/mkmf/test_constant.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38907)
+++ ChangeLog	(revision 38908)
@@ -1,4 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
-Wed Jan 23 16:17:59 2013  Nobuyoshi Nakada  <nobu@r...>
+Wed Jan 23 16:18:04 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* lib/mkmf.rb (MakeMakefile#try_constant): fix for large unsigned.
 
 	* lib/mkmf.rb (MakeMakefile#try_constant): fix for larger constants.
 
Index: lib/mkmf.rb
===================================================================
--- lib/mkmf.rb	(revision 38907)
+++ lib/mkmf.rb	(revision 38908)
@@ -613,12 +613,12 @@ SRC https://github.com/ruby/ruby/blob/trunk/lib/mkmf.rb#L613
 
   def try_constant(const, headers = nil, opt = "", &b)
     includes = cpp_include(headers)
+    neg = try_static_assert("#{const} < 0", headers, opt)
     if CROSS_COMPILING
-      if try_static_assert("#{const} > 0", headers, opt)
-        # positive constant
-      elsif try_static_assert("#{const} < 0", headers, opt)
-        neg = true
+      if neg
         const = "-(#{const})"
+      elsif try_static_assert("#{const} > 0", headers, opt)
+        # positive constant
       elsif try_static_assert("#{const} == 0", headers, opt)
         return 0
       else
@@ -646,7 +646,7 @@ SRC https://github.com/ruby/ruby/blob/trunk/lib/mkmf.rb#L646
       src = %{#{includes}
 #include <stdio.h>
 /*top*/
-typedef
+typedef#{neg ? '' : ' unsigned'}
 #ifdef PRI_LL_PREFIX
 #define PRI_CONFTEST_PREFIX PRI_LL_PREFIX
 LONG_LONG
@@ -656,7 +656,7 @@ long https://github.com/ruby/ruby/blob/trunk/lib/mkmf.rb#L656
 #endif
 conftest_type;
 conftest_type conftest_const = (conftest_type)(#{const});
-int main() {printf("%"PRI_CONFTEST_PREFIX"d\\n", conftest_const); return 0;}
+int main() {printf("%"PRI_CONFTEST_PREFIX"#{neg ? 'd' : 'u'}\\n", conftest_const); return 0;}
 }
       begin
         if try_link0(src, opt, &b)
Index: test/mkmf/test_constant.rb
===================================================================
--- test/mkmf/test_constant.rb	(revision 38907)
+++ test/mkmf/test_constant.rb	(revision 38908)
@@ -29,5 +29,9 @@ class TestMkmf https://github.com/ruby/ruby/blob/trunk/test/mkmf/test_constant.rb#L29
       decl = "#define CONFTEST_VALUE (unsigned #{type})(((unsigned #{type})1)<<(CHAR_BIT*sizeof(int)))"
       assert_operator(mkmf {try_constant("CONFTEST_VALUE", [[decl]])}, :>, 0, MKMFLOG)
     end
+
+    def test_large_unsigned
+      assert_operator(mkmf {try_constant("1U<<(CHAR_BIT*sizeof(int)-1)")}, :>, 0, MKMFLOG)
+    end
   end
 end

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

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