[Python-checkins] r71310 - python/branches/py3k-short-float-repr/Python/dtoa.c

mark.dickinson python-checkins at python.org
Mon Apr 6 16:11:15 CEST 2009


Author: mark.dickinson
Date: Mon Apr  6 16:11:14 2009
New Revision: 71310

Log:
Remove static dtoa_result variable.  The penalty for doing this is that
calls to _Py_dg_dtoa must always be matched by a corresponding call to
_Py_dg_freedtoa, to avoid memory leakage.


Modified:
   python/branches/py3k-short-float-repr/Python/dtoa.c

Modified: python/branches/py3k-short-float-repr/Python/dtoa.c
==============================================================================
--- python/branches/py3k-short-float-repr/Python/dtoa.c	(original)
+++ python/branches/py3k-short-float-repr/Python/dtoa.c	Mon Apr  6 16:11:14 2009
@@ -1994,8 +1994,6 @@
 	return -1.0;
 	}
 
- static char *dtoa_result;
-
  static char *
 rv_alloc(int i)
 {
@@ -2008,9 +2006,7 @@
 			k++;
 	r = (int*)Balloc(k);
 	*r = k;
-	return
-	dtoa_result =
-		(char *)(r+1);
+	return (char *)(r+1);
 	}
 
  static char *
@@ -2037,8 +2033,6 @@
 	Bigint *b = (Bigint *)((int *)s - 1);
 	b->maxwds = 1 << (b->k = *(int*)b);
 	Bfree(b);
-	if (s == dtoa_result)
-		dtoa_result = 0;
 	}
 
 /* dtoa for IEEE arithmetic (dmg): convert double to ASCII string.
@@ -2075,6 +2069,9 @@
  *	   calculation.
  */
 
+/* Note: to avoid memory leakage, a successful call to _Py_dg_dtoa should
+   always be matched by a call to _Py_dg_freedtoa. */
+
  char *
 _Py_dg_dtoa
 	(double dd, int mode, int ndigits, int *decpt, int *sign, char **rve)
@@ -2124,11 +2121,6 @@
 	double ds;
 	char *s, *s0;
 
-	if (dtoa_result) {
-		_Py_dg_freedtoa(dtoa_result);
-		dtoa_result = 0;
-		}
-
 	u.d = dd;
 	if (word0(&u) & Sign_bit) {
 		/* set sign for everything, including 0's and NaNs */


More information about the Python-checkins mailing list