Start to remove _PyOS_double_to_string, as mentioned in issue 7117.

This commit is contained in:
Eric Smith 2009-10-26 14:48:55 +00:00
parent 0e0e215308
commit cfaf79c56e
1 changed files with 36 additions and 22 deletions

View File

@ -335,58 +335,72 @@ convert_to_double(PyObject **v, double *dbl)
return 0; return 0;
} }
/* XXX PyFloat_AsString and PyFloat_AsReprString should be deprecated: /* XXX PyFloat_AsString and PyFloat_AsReprString are deprecated:
XXX they pass a char buffer without passing a length. XXX they pass a char buffer without passing a length.
*/ */
void void
PyFloat_AsString(char *buf, PyFloatObject *v) PyFloat_AsString(char *buf, PyFloatObject *v)
{ {
_PyOS_double_to_string(buf, 100, v->ob_fval, 'g', PyFloat_STR_PRECISION, char *tmp = PyOS_double_to_string(v->ob_fval, 'g',
Py_DTSF_ADD_DOT_0, NULL); PyFloat_STR_PRECISION,
Py_DTSF_ADD_DOT_0, NULL);
strcpy(buf, tmp);
PyMem_Free(tmp);
} }
void void
PyFloat_AsReprString(char *buf, PyFloatObject *v) PyFloat_AsReprString(char *buf, PyFloatObject *v)
{ {
_PyOS_double_to_string(buf, 100, v->ob_fval, 'r', 0, char * tmp = PyOS_double_to_string(v->ob_fval, 'r', 0,
Py_DTSF_ADD_DOT_0, NULL); Py_DTSF_ADD_DOT_0, NULL);
strcpy(buf, tmp);
PyMem_Free(tmp);
} }
/* ARGSUSED */ /* ARGSUSED */
static int static int
float_print(PyFloatObject *v, FILE *fp, int flags) float_print(PyFloatObject *v, FILE *fp, int flags)
{ {
char buf[100]; char *buf;
if (flags & Py_PRINT_RAW) if (flags & Py_PRINT_RAW)
_PyOS_double_to_string(buf, sizeof(buf), v->ob_fval, buf = PyOS_double_to_string(v->ob_fval,
'g', PyFloat_STR_PRECISION, 'g', PyFloat_STR_PRECISION,
Py_DTSF_ADD_DOT_0, NULL); Py_DTSF_ADD_DOT_0, NULL);
else else
_PyOS_double_to_string(buf, sizeof(buf), v->ob_fval, buf = PyOS_double_to_string(v->ob_fval,
'r', 0, Py_DTSF_ADD_DOT_0, NULL); 'r', 0, Py_DTSF_ADD_DOT_0, NULL);
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
fputs(buf, fp); fputs(buf, fp);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
PyMem_Free(buf);
return 0; return 0;
} }
static PyObject *
float_str_or_repr(PyFloatObject *v, int precision, char format_code)
{
PyObject *result;
char *buf = PyOS_double_to_string(PyFloat_AS_DOUBLE(v),
format_code, precision,
Py_DTSF_ADD_DOT_0,
NULL);
if (!buf)
return PyErr_NoMemory();
result = PyString_FromString(buf);
PyMem_Free(buf);
return result;
}
static PyObject * static PyObject *
float_repr(PyFloatObject *v) float_repr(PyFloatObject *v)
{ {
char buf[100]; return float_str_or_repr(v, 0, 'r');
_PyOS_double_to_string(buf, sizeof(buf), v->ob_fval, 'r', 0,
Py_DTSF_ADD_DOT_0, NULL);
return PyString_FromString(buf);
} }
static PyObject * static PyObject *
float_str(PyFloatObject *v) float_str(PyFloatObject *v)
{ {
char buf[100]; return float_str_or_repr(v, PyFloat_STR_PRECISION, 'g');
_PyOS_double_to_string(buf, sizeof(buf), v->ob_fval, 'g',
PyFloat_STR_PRECISION,
Py_DTSF_ADD_DOT_0, NULL);
return PyString_FromString(buf);
} }
/* Comparison is pretty much a nightmare. When comparing float to float, /* Comparison is pretty much a nightmare. When comparing float to float,