[Python-checkins] CVS: python/dist/src/Objects floatobject.c,2.107,2.108
Tim Peters
tim_one@users.sourceforge.net
Wed, 28 Nov 2001 14:43:47 -0800
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv15756/python/Objects
Modified Files:
floatobject.c
Log Message:
PyFloat_AsStringEx(): This function takes an output char* but doesn't
pass the buffer length. Stop using it. It should be deprecated, but too
late in the release cycle to do that now.
New static format_float() does the same thing but requires passing the
buffer length too. Use it instead.
Index: floatobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/floatobject.c,v
retrieving revision 2.107
retrieving revision 2.108
diff -C2 -d -r2.107 -r2.108
*** floatobject.c 2001/11/28 20:52:21 2.107
--- floatobject.c 2001/11/28 22:43:45 2.108
***************
*** 226,231 ****
/* Methods */
! void
! PyFloat_AsStringEx(char *buf, PyFloatObject *v, int precision)
{
register char *cp;
--- 226,231 ----
/* Methods */
! static void
! format_float(char *buf, size_t buflen, PyFloatObject *v, int precision)
{
register char *cp;
***************
*** 235,239 ****
However, %g may print the number as an integer;
in such cases, we append ".0" to the string. */
! sprintf(buf, "%.*g", precision, v->ob_fval);
cp = buf;
if (*cp == '-')
--- 235,241 ----
However, %g may print the number as an integer;
in such cases, we append ".0" to the string. */
!
! assert(PyFloat_Check(v));
! PyOS_snprintf(buf, buflen, "%.*g", precision, v->ob_fval);
cp = buf;
if (*cp == '-')
***************
*** 252,255 ****
--- 254,267 ----
}
+ /* XXX PyFloat_AsStringEx should not be a public API function (for one
+ XXX thing, its signature passes a buffer without a length; for another,
+ XXX it isn't useful outside this file).
+ */
+ void
+ PyFloat_AsStringEx(char *buf, PyFloatObject *v, int precision)
+ {
+ format_float(buf, 100, v, precision);
+ }
+
/* Macro and helper that convert PyObject obj to a C double and store
the value in dbl; this replaces the functionality of the coercion
***************
*** 302,309 ****
#define PREC_STR 12
void
PyFloat_AsString(char *buf, PyFloatObject *v)
{
! PyFloat_AsStringEx(buf, v, PREC_STR);
}
--- 314,324 ----
#define PREC_STR 12
+ /* XXX PyFloat_AsString and PyFloat_AsReprString should be deprecated:
+ XXX they pass a char buffer without passing a length.
+ */
void
PyFloat_AsString(char *buf, PyFloatObject *v)
{
! format_float(buf, 100, v, PREC_STR);
}
***************
*** 311,315 ****
PyFloat_AsReprString(char *buf, PyFloatObject *v)
{
! PyFloat_AsStringEx(buf, v, PREC_REPR);
}
--- 326,330 ----
PyFloat_AsReprString(char *buf, PyFloatObject *v)
{
! format_float(buf, 100, v, PREC_REPR);
}
***************
*** 319,323 ****
{
char buf[100];
! PyFloat_AsStringEx(buf, v, flags&Py_PRINT_RAW ? PREC_STR : PREC_REPR);
fputs(buf, fp);
return 0;
--- 334,339 ----
{
char buf[100];
! format_float(buf, sizeof(buf), v,
! (flags & Py_PRINT_RAW) ? PREC_STR : PREC_REPR);
fputs(buf, fp);
return 0;
***************
*** 328,332 ****
{
char buf[100];
! PyFloat_AsStringEx(buf, v, PREC_REPR);
return PyString_FromString(buf);
}
--- 344,348 ----
{
char buf[100];
! format_float(buf, sizeof(buf), v, PREC_REPR);
return PyString_FromString(buf);
}
***************
*** 336,340 ****
{
char buf[100];
! PyFloat_AsStringEx(buf, v, PREC_STR);
return PyString_FromString(buf);
}
--- 352,356 ----
{
char buf[100];
! format_float(buf, sizeof(buf), v, PREC_STR);
return PyString_FromString(buf);
}