diff options
author | Eric Smith <eric@trueblade.com> | 2009-10-26 17:46:17 (GMT) |
---|---|---|
committer | Eric Smith <eric@trueblade.com> | 2009-10-26 17:46:17 (GMT) |
commit | c1bdf891458d2f37aa90b27f3ea85379cbb0d967 (patch) | |
tree | 68f44ec3ad2d9d31071dc0136696ae0b96254851 /Objects | |
parent | 975d7576caa8858b2692b8cba77094ca8fdb685e (diff) | |
download | cpython-c1bdf891458d2f37aa90b27f3ea85379cbb0d967.zip cpython-c1bdf891458d2f37aa90b27f3ea85379cbb0d967.tar.gz cpython-c1bdf891458d2f37aa90b27f3ea85379cbb0d967.tar.bz2 |
Finished removing _PyOS_double_to_string, as mentioned in issue 7117.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/stringobject.c | 20 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 25 |
2 files changed, 28 insertions, 17 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c index 70d90d4..b5faf13 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -4336,7 +4336,10 @@ Py_LOCAL_INLINE(int) formatfloat(char *buf, size_t buflen, int flags, int prec, int type, PyObject *v) { + char *tmp; double x; + Py_ssize_t len; + x = PyFloat_AsDouble(v); if (x == -1.0 && PyErr_Occurred()) { PyErr_Format(PyExc_TypeError, "float argument required, " @@ -4381,9 +4384,20 @@ formatfloat(char *buf, size_t buflen, int flags, "formatted float is too long (precision too large?)"); return -1; } - _PyOS_double_to_string(buf, buflen, x, type, prec, - (flags&F_ALT)?Py_DTSF_ALT:0, NULL); - return (int)strlen(buf); + tmp = PyOS_double_to_string(x, type, prec, + (flags&F_ALT)?Py_DTSF_ALT:0, NULL); + if (!tmp) + return -1; + len = strlen(tmp); + if (len >= buflen) { + PyErr_SetString(PyExc_OverflowError, + "formatted float is too long (precision too large?)"); + PyMem_Free(tmp); + return -1; + } + strcpy(buf, tmp); + PyMem_Free(tmp); + return (int)len; } /* _PyString_FormatLong emulates the format codes d, u, o, x and X, and diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 6eac358..65c10b1 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -8289,18 +8289,6 @@ strtounicode(Py_UNICODE *buffer, const char *charbuffer) } static int -doubletounicode(Py_UNICODE *buffer, size_t len, int format_code, - int precision, int flags, double x) -{ - Py_ssize_t result; - - _PyOS_double_to_string((char *)buffer, len, x, format_code, precision, - flags, NULL); - result = strtounicode(buffer, (char *)buffer); - return Py_SAFE_DOWNCAST(result, Py_ssize_t, int); -} - -static int longtounicode(Py_UNICODE *buffer, size_t len, const char *format, long x) { Py_ssize_t result; @@ -8323,6 +8311,8 @@ formatfloat(Py_UNICODE *buf, PyObject *v) { double x; + Py_ssize_t result; + char *tmp; x = PyFloat_AsDouble(v); if (x == -1.0 && PyErr_Occurred()) @@ -8365,8 +8355,15 @@ formatfloat(Py_UNICODE *buf, "formatted float is too long (precision too large?)"); return -1; } - return doubletounicode(buf, buflen, type, prec, - (flags&F_ALT)?Py_DTSF_ALT:0, x); + + tmp = PyOS_double_to_string(x, type, prec, + (flags&F_ALT)?Py_DTSF_ALT:0, NULL); + if (!tmp) + return -1; + + result = strtounicode(buf, tmp); + PyMem_Free(tmp); + return Py_SAFE_DOWNCAST(result, Py_ssize_t, int); } static PyObject* |