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

ruby-changes:9371

From: nobu <ko1@a...>
Date: Mon, 22 Dec 2008 12:06:15 +0900 (JST)
Subject: [ruby-changes:9371] Ruby:r20909 (trunk): * configure.in (mingw): no longer uses snprintf and vsnprintf of

nobu	2008-12-22 12:05:20 +0900 (Mon, 22 Dec 2008)

  New Revision: 20909

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

  Log:
    * configure.in (mingw): no longer uses snprintf and vsnprintf of
      msvcrt.
    * win32/win32.c (rb_w32_vsnprintf, rb_w32_snprintf): removed.
    
    * win32/Makefile.sub (config.h): vsnprintf exists in VC7 or later.
    
    * win32/mkexports.rb (Exports#initialize): aliases
      rb_w32_vsnprintf and rb_w32_snprintf for binary compatibility.
    
    * sprintf.c (rb_str_format): uses snprintf instead of sprintf.
    
    * numeric.c (flo_to_s, rb_num2long, rb_num2ll): ditto.

  Modified files:
    trunk/ChangeLog
    trunk/configure.in
    trunk/include/ruby/missing.h
    trunk/include/ruby/win32.h
    trunk/numeric.c
    trunk/sprintf.c
    trunk/win32/Makefile.sub
    trunk/win32/mkexports.rb
    trunk/win32/win32.c

Index: include/ruby/missing.h
===================================================================
--- include/ruby/missing.h	(revision 20908)
+++ include/ruby/missing.h	(revision 20909)
@@ -144,9 +144,13 @@
 #endif
 */
 
-#ifndef HAVE_VSNPRINTF
+#if defined HAVE_VSNPRINTF || defined HAVE_SNPRINTF
 # include <stdarg.h>
+#endif
+#ifndef HAVE_SNPRINTF
 RUBY_EXTERN int snprintf(char *, size_t n, char const *, ...);
+#endif
+#ifndef HAVE_VSNPRINTF
 RUBY_EXTERN int vsnprintf(char *, size_t n, char const *, va_list);
 #endif
 
Index: include/ruby/win32.h
===================================================================
--- include/ruby/win32.h	(revision 20908)
+++ include/ruby/win32.h	(revision 20909)
@@ -243,11 +243,6 @@
 extern void   rb_w32_free_environ(char **);
 extern int    rb_w32_map_errno(DWORD);
 
-#define vsnprintf(s,n,f,l) rb_w32_vsnprintf(s,n,f,l)
-#define snprintf   rb_w32_snprintf
-extern int rb_w32_vsnprintf(char *, size_t, const char *, va_list);
-extern int rb_w32_snprintf(char *, size_t, const char *, ...);
-
 extern int chown(const char *, int, int);
 extern int link(const char *, const char *);
 extern int gettimeofday(struct timeval *, struct timezone *);
Index: configure.in
===================================================================
--- configure.in	(revision 20908)
+++ configure.in	(revision 20909)
@@ -580,8 +580,6 @@
 		ac_cv_func_times=yes
 		ac_cv_func_waitpid=yes
 		ac_cv_func_fsync=yes
-		ac_cv_func_snprintf=yes
-		ac_cv_func_vsnprintf=yes
 		ac_cv_func_seekdir=yes
 		ac_cv_func_telldir=yes
 		ac_cv_func_isinf=yes
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 20908)
+++ ChangeLog	(revision 20909)
@@ -1,3 +1,19 @@
+Mon Dec 22 12:05:14 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* configure.in (mingw): no longer uses snprintf and vsnprintf of
+	  msvcrt.
+
+	* win32/win32.c (rb_w32_vsnprintf, rb_w32_snprintf): removed.
+
+	* win32/Makefile.sub (config.h): vsnprintf exists in VC7 or later.
+
+	* win32/mkexports.rb (Exports#initialize): aliases
+	  rb_w32_vsnprintf and rb_w32_snprintf for binary compatibility.
+
+	* sprintf.c (rb_str_format): uses snprintf instead of sprintf.
+
+	* numeric.c (flo_to_s, rb_num2long, rb_num2ll): ditto.
+
 Mon Dec 22 10:59:31 2008  Yukihiro Matsumoto  <matz@r...>
 
 	* string.c (rb_str_upto): should return enumerator if called
Index: win32/win32.c
===================================================================
--- win32/win32.c	(revision 20908)
+++ win32/win32.c	(revision 20909)
@@ -4553,26 +4553,6 @@
 }
 
 int
-rb_w32_vsnprintf(char *buf, size_t size, const char *format, va_list va)
-{
-    int ret = _vsnprintf(buf, size, format, va);
-    if (size > 0) buf[size - 1] = 0;
-    return ret;
-}
-
-int
-rb_w32_snprintf(char *buf, size_t size, const char *format, ...)
-{
-    int ret;
-    va_list va;
-
-    va_start(va, format);
-    ret = vsnprintf(buf, size, format, va);
-    va_end(va);
-    return ret;
-}
-
-int
 rb_w32_mkdir(const char *path, int mode)
 {
     int ret = -1;
Index: win32/Makefile.sub
===================================================================
--- win32/Makefile.sub	(revision 20908)
+++ win32/Makefile.sub	(revision 20909)
@@ -423,7 +423,9 @@
 #define HAVE_STRTOUL 1
 #define HAVE_FLOCK 1
 #define HAVE_SNPRINTF 1
+!if $(MSC_VER) >= 1300
 #define HAVE_VSNPRINTF 1
+!endif
 #define HAVE_ISNAN 1
 #define HAVE_FINITE 1
 #define HAVE_HYPOT 1
Index: win32/mkexports.rb
===================================================================
--- win32/mkexports.rb	(revision 20908)
+++ win32/mkexports.rb	(revision 20909)
@@ -51,6 +51,8 @@
       end
     end
     syms["NtInitialize"] ||= "ruby_sysinit" if syms["ruby_sysinit"]
+    syms["rb_w32_vsnprintf"] ||= "vsnprintf"
+    syms["rb_w32_snprintf"] ||= "snprintf"
     @syms = syms
   end
 
Index: sprintf.c
===================================================================
--- sprintf.c	(revision 20908)
+++ sprintf.c	(revision 20909)
@@ -25,7 +25,7 @@
 #define BITSPERDIG (SIZEOF_BDIGITS*CHAR_BIT)
 #define EXTENDSIGN(n, l) (((~0 << (n)) >> (((n)*(l)) % BITSPERDIG)) & ~(~0 << (n)))
 
-static void fmt_setup(char*,int,int,int,int);
+static void fmt_setup(char*,size_t,int,int,int,int);
 
 static char*
 remove_sign_bits(char *str, int base)
@@ -800,8 +800,8 @@
 			    sc = ' ';
 			    width--;
 			}
-			sprintf(fbuf, "%%l%c", c);
-			sprintf(nbuf, fbuf, v);
+			snprintf(fbuf, sizeof(fbuf), "%%l%c", c);
+			snprintf(nbuf, sizeof(nbuf), fbuf, v);
 			s = nbuf;
 		    }
 		    else {
@@ -809,8 +809,8 @@
 			if (v < 0) {
 			    dots = 1;
 			}
-			sprintf(fbuf, "%%l%c", *p == 'X' ? 'x' : *p);
-			sprintf(++s, fbuf, v);
+			snprintf(fbuf, sizeof(fbuf), "%%l%c", *p == 'X' ? 'x' : *p);
+			snprintf(++s, sizeof(nbuf) - 1, fbuf, v);
 			if (v < 0) {
 			    char d = 0;
 
@@ -980,7 +980,7 @@
 			need = width;
 
 		    CHECK(need);
-		    sprintf(&buf[blen], "%*s", need, "");
+		    snprintf(&buf[blen], need, "%*s", need, "");
 		    if (flags & FMINUS) {
 			if (!isnan(fval) && fval < 0.0)
 			    buf[blen++] = '-';
@@ -1004,7 +1004,7 @@
 		    break;
 		}
 
-		fmt_setup(fbuf, *p, flags, width, prec);
+		fmt_setup(fbuf, sizeof(fbuf), *p, flags, width, prec);
 		need = 0;
 		if (*p != 'e' && *p != 'E') {
 		    i = INT_MIN;
@@ -1018,7 +1018,7 @@
 		need += 20;
 
 		CHECK(need);
-		sprintf(&buf[blen], fbuf, fval);
+		snprintf(&buf[blen], need, fbuf, fval);
 		blen += strlen(&buf[blen]);
 	    }
 	    break;
@@ -1041,8 +1041,9 @@
 }
 
 static void
-fmt_setup(char *buf, int c, int flags, int width, int prec)
+fmt_setup(char *buf, size_t size, int c, int flags, int width, int prec)
 {
+    char *end = buf + size;
     *buf++ = '%';
     if (flags & FSHARP) *buf++ = '#';
     if (flags & FPLUS)  *buf++ = '+';
@@ -1051,12 +1052,12 @@
     if (flags & FSPACE) *buf++ = ' ';
 
     if (flags & FWIDTH) {
-	sprintf(buf, "%d", width);
+	snprintf(buf, end - buf, "%d", width);
 	buf += strlen(buf);
     }
 
     if (flags & FPREC) {
-	sprintf(buf, ".%d", prec);
+	snprintf(buf, end - buf, ".%d", prec);
 	buf += strlen(buf);
     }
 
@@ -1084,7 +1085,15 @@
 #undef snprintf
 #define FLOATING_POINT 1
 #define BSD__dtoa ruby_dtoa
+#undef HAVE_VSNPRINTF
+#undef HAVE_SNPRINTF
+#if _MSC_VER >= 1300
+#pragma warning(disable: 4273)
+#endif
 #include "missing/vsnprintf.c"
+#if _MSC_VER >= 1300
+#pragma warning(default: 4273)
+#endif
 
 static int
 ruby__sfvwrite(register rb_printf_buffer *fp, register struct __suio *uio)
Index: numeric.c
===================================================================
--- numeric.c	(revision 20908)
+++ numeric.c	(revision 20909)
@@ -530,12 +530,12 @@
     else if(isnan(value))
 	return rb_usascii_str_new2("NaN");
 
-    sprintf(buf, "%#.15g", value); /* ensure to print decimal point */
+    snprintf(buf, sizeof(buf), "%#.15g", value); /* ensure to print decimal point */
     if (!(e = strchr(buf, 'e'))) {
 	e = buf + strlen(buf);
     }
     if (!ISDIGIT(e[-1])) { /* reformat if ended with decimal point (ex 111111111111111.) */
-	sprintf(buf, "%#.14e", value);
+	snprintf(buf, sizeof(buf), "%#.14e", value);
 	if (!(e = strchr(buf, 'e'))) {
 	    e = buf + strlen(buf);
 	}
@@ -1554,7 +1554,7 @@
 	    char buf[24];
 	    char *s;
 
-	    sprintf(buf, "%-.10g", RFLOAT_VALUE(val));
+	    snprintf(buf, sizeof(buf), "%-.10g", RFLOAT_VALUE(val));
 	    if ((s = strchr(buf, ' ')) != 0) *s = '\0';
 	    rb_raise(rb_eRangeError, "float %s out of range of integer", buf);
 	}
@@ -1700,7 +1700,7 @@
 	    char buf[24];
 	    char *s;
 
-	    sprintf(buf, "%-.10g", RFLOAT_VALUE(val));
+	    snprintf(buf, sizeof(buf), "%-.10g", RFLOAT_VALUE(val));
 	    if ((s = strchr(buf, ' ')) != 0) *s = '\0';
 	    rb_raise(rb_eRangeError, "float %s out of range of long long", buf);
 	}

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

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