[Python-checkins] r70766 - python/branches/py3k-short-float-repr/Modules/_pickle.c
eric.smith
python-checkins at python.org
Tue Mar 31 00:22:43 CEST 2009
Author: eric.smith
Date: Tue Mar 31 00:22:43 2009
New Revision: 70766
Log:
Hooked _pickle up to new float formatter.
Modified:
python/branches/py3k-short-float-repr/Modules/_pickle.c
Modified: python/branches/py3k-short-float-repr/Modules/_pickle.c
==============================================================================
--- python/branches/py3k-short-float-repr/Modules/_pickle.c (original)
+++ python/branches/py3k-short-float-repr/Modules/_pickle.c Tue Mar 31 00:22:43 2009
@@ -1018,14 +1018,27 @@
return -1;
}
else {
- char pdata[250];
- pdata[0] = FLOAT;
- PyOS_ascii_formatd(pdata + 1, sizeof(pdata) - 2, "%.17g", x);
- /* Extend the formatted string with a newline character */
- strcat(pdata, "\n");
+ int result = -1;
+ char *buf = NULL;
+ char op = FLOAT;
- if (pickler_write(self, pdata, strlen(pdata)) < 0)
- return -1;
+ if (pickler_write(self, &op, 1) < 0)
+ goto done;
+
+ buf = PyOS_double_to_string(x, 2, 'g', 17, 0, 0);
+ if (!buf)
+ goto done;
+
+ if (pickler_write(self, buf, strlen(buf)) < 0)
+ goto done;
+
+ if (pickler_write(self, "\n", 1) < 0)
+ goto done;
+
+ result = 0;
+done:
+ PyMem_Free(buf);
+ return result;
}
return 0;
More information about the Python-checkins
mailing list