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

ruby-changes:14495

From: nobu <ko1@a...>
Date: Sun, 17 Jan 2010 14:25:25 +0900 (JST)
Subject: [ruby-changes:14495] Ruby:r26332 (trunk): * ext/iconv/iconv.c (iconv_convert): suppress a warning.

nobu	2010-01-17 14:23:25 +0900 (Sun, 17 Jan 2010)

  New Revision: 26332

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

  Log:
    * ext/iconv/iconv.c (iconv_convert): suppress a warning.
    
    * lib/mkmf.rb (check_signedness): new method.

  Modified files:
    trunk/ChangeLog
    trunk/ext/iconv/extconf.rb
    trunk/ext/iconv/iconv.c
    trunk/lib/mkmf.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 26331)
+++ ChangeLog	(revision 26332)
@@ -1,5 +1,9 @@
-Sun Jan 17 14:18:01 2010  Nobuyoshi Nakada  <nobu@r...>
+Sun Jan 17 14:23:23 2010  Nobuyoshi Nakada  <nobu@r...>
 
+	* ext/iconv/iconv.c (iconv_convert): suppress a warning.
+
+	* lib/mkmf.rb (check_signedness): new method.
+
 	* lib/mkmf.rb (have_header, create_header): use String#tr_cpp.
 
 Thu Jan 14 13:06:58 2010  Nobuyoshi Nakada  <nobu@r...>
Index: lib/mkmf.rb
===================================================================
--- lib/mkmf.rb	(revision 26331)
+++ lib/mkmf.rb	(revision 26332)
@@ -985,6 +985,11 @@
   end
 end
 
+STRING_OR_FAILED_FORMAT = "%s"
+def STRING_OR_FAILED_FORMAT.%(x)
+  x ? super : "failed"
+end
+
 # Returns the size of the given +type+.  You may optionally specify additional
 # +headers+ to search in for the +type+.
 #
@@ -1002,10 +1007,7 @@
   prelude << "static rbcv_typedef_ *rbcv_ptr_;\n"
   prelude = [prelude]
   expr = "sizeof((*rbcv_ptr_)#{"." << member if member})"
-  fmt = "%s"
-  def fmt.%(x)
-    x ? super : "failed"
-  end
+  fmt = STRING_OR_FAILED_FORMAT
   checking_for checking_message("size of #{type}", headers), fmt do
     if UNIVERSAL_INTS.include?(type)
       type
@@ -1021,6 +1023,37 @@
   end
 end
 
+# Returns the signedness of the given +type+.  You may optionally
+# specify additional +headers+ to search in for the +type+.
+#
+# If the +type+ is found and is a numeric type, a macro is passed as a
+# preprocessor constant to the compiler using the +type+ name, in
+# uppercase, prepended with 'SIGNEDNESS_OF_', followed by the +type+
+# name, followed by '=X' where 'X' is positive integer if the +type+ is
+# unsigned, or negative integer if the +type+ is signed.
+#
+# For example, if size_t is defined as unsigned, then
+# check_signedness('size_t') would returned +1 and the
+# SIGNEDNESS_OF_SIZE_T=+1 preprocessor macro would be passed to the
+# compiler, and SIGNEDNESS_OF_INT=-1 if check_signedness('int') is
+# done.
+#
+def check_signedness(type, headers = nil)
+  signed = nil
+  checking_for("signedness of #{type}", STRING_OR_FAILED_FORMAT) do
+    if try_static_assert("(#{type})-1 < 0")
+      signed = -1
+    elsif try_static_assert("(#{type})-1 > 0")
+      signed = +1
+    else
+      next nil
+    end
+    $defs.push("-DSIGNEDNESS_OF_%s=%+d" % [type.tr_cpp, signed])
+    signed < 0 ? "signed" : "unsigned"
+  end
+  signed
+end
+
 # :stopdoc:
 
 # Used internally by the what_type? method to determine if +type+ is a scalar
Index: ext/iconv/iconv.c
===================================================================
--- ext/iconv/iconv.c	(revision 26331)
+++ ext/iconv/iconv.c	(revision 26332)
@@ -464,7 +464,11 @@
 	errmsg[0] = 0;
 	error = iconv_try(cd, &inptr, &inlen, &outptr, &outlen);
 
-	if (0 <= outlen && outlen <= sizeof(buffer)) {
+	if (
+#if SIGNEDNESS_OF_SIZE_T < 0
+	    0 <= outlen &&
+#endif
+	    outlen <= sizeof(buffer)) {
 	    outlen = sizeof(buffer) - outlen;
 	    if (NIL_P(error) ||	/* something converted */
 		outlen > (size_t)(inptr - tmpstart) || /* input can't contain output */
Index: ext/iconv/extconf.rb
===================================================================
--- ext/iconv/extconf.rb	(revision 26331)
+++ ext/iconv/extconf.rb	(revision 26332)
@@ -7,6 +7,7 @@
 
 if have_func("iconv", "iconv.h") or
     have_library("iconv", "iconv", "iconv.h")
+  check_signedness("size_t")
   if checking_for("const of iconv() 2nd argument") do
       create_tmpsrc(cpp_include("iconv.h") + "---> iconv(cd,0,0,0,0) <---")
       src = xpopen(cpp_command("")) {|f|f.read}

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

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