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

ruby-changes:10897

From: usa <ko1@a...>
Date: Fri, 20 Feb 2009 23:29:11 +0900 (JST)
Subject: [ruby-changes:10897] Ruby:r22471 (trunk): * util.c (rv_alloc, freedtoa): use our normal xmalloc()/xfree() because

usa	2009-02-20 23:29:00 +0900 (Fri, 20 Feb 2009)

  New Revision: 22471

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

  Log:
    * util.c (rv_alloc, freedtoa): use our normal xmalloc()/xfree() because
      couldn't free the returned pointer from ruby_dtoa().
    * missing/vsnprintf.c (cvt): receive buffer and use/return it instead
      of returning the pointer returned from BSD__dtoa().
    
    * missing/vsnprintf.c (BSD_vfprintf): pass buf to cvt() as the buffer.
      [ruby-core:22184]

  Modified files:
    trunk/ChangeLog
    trunk/missing/vsnprintf.c
    trunk/util.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 22470)
+++ ChangeLog	(revision 22471)
@@ -1,3 +1,14 @@
+Fri Feb 20 23:28:11 2009  NAKAMURA Usaku  <usa@r...>
+
+	* util.c (rv_alloc, freedtoa): use our normal xmalloc()/xfree() because
+	  couldn't free the returned pointer from ruby_dtoa().
+
+	* missing/vsnprintf.c (cvt): receive buffer and use/return it instead
+	  of returning the pointer returned from BSD__dtoa().
+
+	* missing/vsnprintf.c (BSD_vfprintf): pass buf to cvt() as the buffer.
+	  [ruby-core:22184]
+
 Thu Feb 19 22:59:09 2009  Tanaka Akira  <akr@f...>
 
 	* ext/socket/ancdata.c (make_io_for_unix_rights): cmsg_len may be
Index: util.c
===================================================================
--- util.c	(revision 22470)
+++ util.c	(revision 22471)
@@ -3058,20 +3058,11 @@
 static char *
 rv_alloc(int i)
 {
-    int j, k, *r;
-
-    j = sizeof(ULong);
-    for (k = 0;
-            sizeof(Bigint) - sizeof(ULong) - sizeof(int) + j <= i;
-            j <<= 1)
-        k++;
-    r = (int*)Balloc(k);
-    *r = k;
     return
 #ifndef MULTIPLE_THREADS
         dtoa_result =
 #endif
-        (char *)(r+1);
+        xmalloc(i);
 }
 
 static char *
@@ -3096,9 +3087,7 @@
 static void
 freedtoa(char *s)
 {
-    Bigint *b = (Bigint *)((int *)s - 1);
-    b->maxwds = 1 << (b->k = *(int*)b);
-    Bfree(b);
+    xfree(s);
 }
 #endif
 
Index: missing/vsnprintf.c
===================================================================
--- missing/vsnprintf.c	(revision 22470)
+++ missing/vsnprintf.c	(revision 22471)
@@ -494,7 +494,7 @@
 #define	BUF		(MAXEXP+MAXFRACT+1)	/* + decimal point */
 #define	DEFPREC		6
 
-static char *cvt __P((double, int, int, char *, int *, int, int *));
+static char *cvt __P((double, int, int, char *, int *, int, int *, char *));
 static int exponent __P((char *, int, int));
 
 #else /* no FLOATING_POINT */
@@ -783,7 +783,7 @@
 			}
 			flags |= FPT;
 			cp = cvt(_double, prec, flags, &softsign,
-				&expt, ch, &ndig);
+				&expt, ch, &ndig, buf);
 			if (ch == 'g' || ch == 'G') {
 				if (expt <= -4 || (expt > prec && expt > 1))
 					ch = (ch == 'g') ? 'e' : 'E';
@@ -1076,10 +1076,10 @@
 extern char *BSD__dtoa __P((double, int, int, int *, int *, char **));
 
 static char *
-cvt(value, ndigits, flags, sign, decpt, ch, length)
+cvt(value, ndigits, flags, sign, decpt, ch, length, buf)
 	double value;
 	int ndigits, flags, *decpt, ch, *length;
-	char *sign;
+	char *sign, *buf;
 {
 	int mode, dsgn;
 	char *digits, *bp, *rve;
@@ -1098,6 +1098,10 @@
 	    *sign = '\000';
 	}
 	digits = BSD__dtoa(value, mode, ndigits, decpt, &dsgn, &rve);
+	memcpy(buf, digits, rve - digits);
+	xfree(digits);
+	rve = buf + (rve - digits);
+	digits = buf;
 	if (flags & ALT) {	/* Print trailing zeros */
 		bp = digits + ndigits;
 		if (ch == 'f') {

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

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