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

ruby-changes:28748

From: akr <ko1@a...>
Date: Sat, 18 May 2013 00:40:10 +0900 (JST)
Subject: [ruby-changes:28748] akr:r40800 (trunk): * ext/socket/mkconstants.rb: Convert integer constants bigger than int

akr	2013-05-18 00:39:59 +0900 (Sat, 18 May 2013)

  New Revision: 40800

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

  Log:
    * ext/socket/mkconstants.rb: Convert integer constants bigger than int
      correctly.

  Modified files:
    trunk/ChangeLog
    trunk/ext/socket/mkconstants.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40799)
+++ ChangeLog	(revision 40800)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat May 18 00:38:47 2013  Tanaka Akira  <akr@f...>
+
+	* ext/socket/mkconstants.rb: Convert integer constants bigger than int
+	  correctly.
+
 Fri May 17 22:02:15 2013  Tanaka Akira  <akr@f...>
 
 	* ext/socket/ifaddr.c: Use unsigned LONG_LONG to represent flags
Index: ext/socket/mkconstants.rb
===================================================================
--- ext/socket/mkconstants.rb	(revision 40799)
+++ ext/socket/mkconstants.rb	(revision 40800)
@@ -56,17 +56,12 @@ DEFS = h.to_a https://github.com/ruby/ruby/blob/trunk/ext/socket/mkconstants.rb#L56
 
 def each_const
   DEFS.each {|name, default_value|
-    if name =~ /\AINADDR_/
-      make_value = "UINT2NUM"
-    else
-      make_value = "INT2NUM"
-    end
     guard = nil
     if /\A(AF_INET6|PF_INET6|IPV6_.*)\z/ =~ name
       # IPv6 is not supported although AF_INET6 is defined on mingw
       guard = "defined(INET6)"
     end
-    yield guard, make_value, name, default_value
+    yield guard, name, default_value
   }
 end
 
@@ -78,7 +73,7 @@ def each_name(pat) https://github.com/ruby/ruby/blob/trunk/ext/socket/mkconstants.rb#L73
 end
 
 ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_const_decls")
-% each_const {|guard, make_value, name, default_value|
+% each_const {|guard, name, default_value|
 #if !defined(<%=name%>)
 # if defined(HAVE_CONST_<%=name.upcase%>)
 #  define <%=name%> <%=name%>
@@ -91,23 +86,23 @@ ERB.new(<<'EOS', nil, '%').def_method(Ob https://github.com/ruby/ruby/blob/trunk/ext/socket/mkconstants.rb#L86
 % }
 EOS
 
-ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_const_defs_in_guard(make_value, name, default_value)")
+ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_const_defs_in_guard(name, default_value)")
 #if defined(<%=name%>)
     /* <%= COMMENTS[name] %> */
-    rb_define_const(rb_cSocket, <%=c_str name%>, <%=make_value%>(<%=name%>));
+    rb_define_const(rb_cSocket, <%=c_str name%>, INTEGER2VALUE(<%=name%>));
     /* <%= COMMENTS[name] %> */
-    rb_define_const(rb_mSockConst, <%=c_str name%>, <%=make_value%>(<%=name%>));
+    rb_define_const(rb_mSockConst, <%=c_str name%>, INTEGER2VALUE(<%=name%>));
 #endif
 EOS
 
 ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_const_defs")
-% each_const {|guard, make_value, name, default_value|
+% each_const {|guard, name, default_value|
 %   if guard
 #if <%=guard%>
-<%= gen_const_defs_in_guard(make_value, name, default_value).chomp %>
+<%= gen_const_defs_in_guard(name, default_value).chomp %>
 #endif
 %   else
-<%= gen_const_defs_in_guard(make_value, name, default_value).chomp %>
+<%= gen_const_defs_in_guard(name, default_value).chomp %>
 %   end
 % }
 EOS
@@ -284,6 +279,12 @@ result = ERB.new(<<'EOS', nil, '%').resu https://github.com/ruby/ruby/blob/trunk/ext/socket/mkconstants.rb#L279
 
 <%= INTERN_DEFS.map {|vardef, gen_hash, decl, func| vardef }.join("\n") %>
 
+#ifdef HAVE_LONG_LONG
+#define INTEGER2VALUE(n) ((n) <= 0 ? LL2NUM(n) : ULL2NUM(n))
+#else
+#define INTEGER2VALUE(n) ((n) <= 0 ? LONG2NUM(n) : ULONG2NUM(n))
+#endif
+
 static void
 init_constants(void)
 {

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

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