summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Smith <eric@trueblade.com>2009-10-26 15:06:39 (GMT)
committerEric Smith <eric@trueblade.com>2009-10-26 15:06:39 (GMT)
commitb05d3be2f1cd448a67f15bc602a78eb22d678ab2 (patch)
tree0e9c90e0e818e0f4e3cc063fa2c89b9734101ddd
parentcfaf79c56eb6fd884f5bc5b52dd49f666c9118a4 (diff)
downloadcpython-b05d3be2f1cd448a67f15bc602a78eb22d678ab2.zip
cpython-b05d3be2f1cd448a67f15bc602a78eb22d678ab2.tar.gz
cpython-b05d3be2f1cd448a67f15bc602a78eb22d678ab2.tar.bz2
Continue removing _PyOS_double_to_string, as mentioned in issue 7117.
-rw-r--r--Modules/cPickle.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/Modules/cPickle.c b/Modules/cPickle.c
index bbc14bf..a2261cc 100644
--- a/Modules/cPickle.c
+++ b/Modules/cPickle.c
@@ -1170,15 +1170,29 @@ save_float(Picklerobject *self, PyObject *args)
return -1;
}
else {
- char c_str[250];
- c_str[0] = FLOAT;
- _PyOS_double_to_string(c_str + 1, sizeof(c_str) - 2, x, 'g',
- 17, 0, NULL);
- /* Extend the formatted string with a newline character */
- strcat(c_str, "\n");
+ int result = -1;
+ char *buf = NULL;
+ char op = FLOAT;
- if (self->write_func(self, c_str, strlen(c_str)) < 0)
- return -1;
+ if (self->write_func(self, &op, 1) < 0)
+ goto done;
+
+ buf = PyOS_double_to_string(x, 'g', 17, 0, NULL);
+ if (!buf) {
+ PyErr_NoMemory();
+ goto done;
+ }
+
+ if (self->write_func(self, buf, strlen(buf)) < 0)
+ goto done;
+
+ if (self->write_func(self, "\n", 1) < 0)
+ goto done;
+
+ result = 0;
+done:
+ PyMem_Free(buf);
+ return result;
}
return 0;