Mercurial > cpython-lru_cache-weakref
diff Objects/floatobject.c @ 40527:195f689af5af
Remove PyFloat_AsReprString() and PyFloat_AsString() which should not
have been public due to passing buffers without lengths.
| author | Neal Norwitz <nnorwitz@gmail.com> |
|---|---|
| date | Thu, 28 Dec 2006 04:45:06 +0000 |
| parents | 88133417dfd0 |
| children | 4aee3f672f77 |
line wrap: on
line diff
--- a/Objects/floatobject.c Tue Dec 19 22:06:09 2006 +0000 +++ b/Objects/floatobject.c Thu Dec 28 04:45:06 2006 +0000 @@ -220,19 +220,18 @@ /* Methods */ static void -format_float(char *buf, size_t buflen, PyFloatObject *v, int precision) +format_double(char *buf, size_t buflen, double ob_fval, int precision) { register char *cp; char format[32]; - /* Subroutine for float_repr and float_print. + /* Subroutine for float_repr, float_str, float_print and others. We want float numbers to be recognizable as such, i.e., they should contain a decimal point or an exponent. However, %g may print the number as an integer; in such cases, we append ".0" to the string. */ - assert(PyFloat_Check(v)); PyOS_snprintf(format, 32, "%%.%ig", precision); - PyOS_ascii_formatd(buf, buflen, format, v->ob_fval); + PyOS_ascii_formatd(buf, buflen, format, ob_fval); cp = buf; if (*cp == '-') cp++; @@ -249,14 +248,11 @@ } } -/* 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) +static void +format_float(char *buf, size_t buflen, PyFloatObject *v, int precision) { - format_float(buf, 100, v, precision); + assert(PyFloat_Check(v)); + format_double(buf, buflen, PyFloat_AS_DOUBLE(v), precision); } /* Macro and helper that convert PyObject obj to a C double and store @@ -312,21 +308,6 @@ #define PREC_REPR 17 #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); -} - -void -PyFloat_AsReprString(char *buf, PyFloatObject *v) -{ - format_float(buf, 100, v, PREC_REPR); -} - /* ARGSUSED */ static int float_print(PyFloatObject *v, FILE *fp, int flags) @@ -1275,7 +1256,7 @@ if (PyFloat_CheckExact(p) && p->ob_refcnt != 0) { char buf[100]; - PyFloat_AsString(buf, p); + format_float(buf, sizeof(buf), p, PREC_STR); /* XXX(twouters) cast refcount to long until %zd is universally available @@ -1527,6 +1508,14 @@ } } +/* Should only be used by marshal. */ +int +_PyFloat_Repr(double x, char *p, size_t len) +{ + format_double(p, len, x, PREC_REPR); + return (int)strlen(p); +} + double _PyFloat_Unpack4(const unsigned char *p, int le) {
