summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
Diffstat (limited to 'Objects')
-rw-r--r--Objects/complexobject.c23
-rw-r--r--Objects/floatobject.c8
-rw-r--r--Objects/stringobject.c2
3 files changed, 20 insertions, 13 deletions
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index c29d48d..4023fa0 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -272,13 +272,19 @@ complex_dealloc(PyObject *op)
static void
complex_to_buf(char *buf, int bufsz, PyComplexObject *v, int precision)
{
- if (v->cval.real == 0.)
- PyOS_snprintf(buf, bufsz, "%.*gj",
- precision, v->cval.imag);
- else
- PyOS_snprintf(buf, bufsz, "(%.*g%+.*gj)",
- precision, v->cval.real,
- precision, v->cval.imag);
+ char format[32];
+ if (v->cval.real == 0.) {
+ PyOS_snprintf(format, 32, "%%.%ig", precision);
+ PyOS_ascii_formatd(buf, bufsz, format, v->cval.imag);
+ strncat(buf, "j", bufsz);
+ } else {
+ char re[64], im[64];
+
+ PyOS_snprintf(format, 32, "%%.%ig", precision);
+ PyOS_ascii_formatd(re, 64, format, v->cval.real);
+ PyOS_ascii_formatd(im, 64, format, v->cval.imag);
+ PyOS_snprintf(buf, bufsz, "(%s+%sj)", re, im);
+ }
}
static int
@@ -662,7 +668,6 @@ static PyMemberDef complex_members[] = {
static PyObject *
complex_subtype_from_string(PyTypeObject *type, PyObject *v)
{
- extern double strtod(const char *, char **);
const char *s, *start;
char *end;
double x=0.0, y=0.0, z;
@@ -774,7 +779,7 @@ complex_subtype_from_string(PyTypeObject *type, PyObject *v)
}
errno = 0;
PyFPE_START_PROTECT("strtod", return 0)
- z = strtod(s, &end) ;
+ z = PyOS_ascii_strtod(s, &end) ;
PyFPE_END_PROTECT(z)
if (errno != 0) {
PyOS_snprintf(buffer, sizeof(buffer),
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index f1c8e42..bbf56c6 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -132,7 +132,7 @@ PyFloat_FromString(PyObject *v, char **pend)
* key off errno.
*/
PyFPE_START_PROTECT("strtod", return NULL)
- x = strtod(s, (char **)&end);
+ x = PyOS_ascii_strtod(s, (char **)&end);
PyFPE_END_PROTECT(x)
errno = 0;
/* Believe it or not, Solaris 2.6 can move end *beyond* the null
@@ -164,7 +164,7 @@ PyFloat_FromString(PyObject *v, char **pend)
/* See above -- may have been strtod being anal
about denorms. */
PyFPE_START_PROTECT("atof", return NULL)
- x = atof(s);
+ x = PyOS_ascii_atof(s);
PyFPE_END_PROTECT(x)
errno = 0; /* whether atof ever set errno is undefined */
}
@@ -223,6 +223,7 @@ static void
format_float(char *buf, size_t buflen, PyFloatObject *v, int precision)
{
register char *cp;
+ char format[32];
/* Subroutine for float_repr and float_print.
We want float numbers to be recognizable as such,
i.e., they should contain a decimal point or an exponent.
@@ -230,7 +231,8 @@ format_float(char *buf, size_t buflen, PyFloatObject *v, int precision)
in such cases, we append ".0" to the string. */
assert(PyFloat_Check(v));
- PyOS_snprintf(buf, buflen, "%.*g", precision, v->ob_fval);
+ PyOS_snprintf(format, 32, "%%.%ig", precision);
+ PyOS_ascii_formatd(buf, buflen, format, v->ob_fval);
cp = buf;
if (*cp == '-')
cp++;
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index 361d84d..b14dc51 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -3582,7 +3582,7 @@ formatfloat(char *buf, size_t buflen, int flags,
PyOS_snprintf(fmt, sizeof(fmt), "%%%s.%d%c",
(flags&F_ALT) ? "#" : "",
prec, type);
- PyOS_snprintf(buf, buflen, fmt, x);
+ PyOS_ascii_formatd(buf, buflen, fmt, x);
return strlen(buf);
}