@@ -220,19 +220,18 @@ PyFloat_AsDouble(PyObject *op)
220220/* Methods */
221221
222222static void
223- format_float (char * buf , size_t buflen , PyFloatObject * v , int precision )
223+ format_double (char * buf , size_t buflen , double ob_fval , int precision )
224224{
225225 register char * cp ;
226226 char format [32 ];
227- /* Subroutine for float_repr and float_print.
227+ /* Subroutine for float_repr, float_str, float_print and others .
228228 We want float numbers to be recognizable as such,
229229 i.e., they should contain a decimal point or an exponent.
230230 However, %g may print the number as an integer;
231231 in such cases, we append ".0" to the string. */
232232
233- assert (PyFloat_Check (v ));
234233 PyOS_snprintf (format , 32 , "%%.%ig" , precision );
235- PyOS_ascii_formatd (buf , buflen , format , v -> ob_fval );
234+ PyOS_ascii_formatd (buf , buflen , format , ob_fval );
236235 cp = buf ;
237236 if (* cp == '-' )
238237 cp ++ ;
@@ -249,14 +248,11 @@ format_float(char *buf, size_t buflen, PyFloatObject *v, int precision)
249248 }
250249}
251250
252- /* XXX PyFloat_AsStringEx should not be a public API function (for one
253- XXX thing, its signature passes a buffer without a length; for another,
254- XXX it isn't useful outside this file).
255- */
256- void
257- PyFloat_AsStringEx (char * buf , PyFloatObject * v , int precision )
251+ static void
252+ format_float (char * buf , size_t buflen , PyFloatObject * v , int precision )
258253{
259- format_float (buf , 100 , v , precision );
254+ assert (PyFloat_Check (v ));
255+ format_double (buf , buflen , PyFloat_AS_DOUBLE (v ), precision );
260256}
261257
262258/* Macro and helper that convert PyObject obj to a C double and store
@@ -312,21 +308,6 @@ convert_to_double(PyObject **v, double *dbl)
312308#define PREC_REPR 17
313309#define PREC_STR 12
314310
315- /* XXX PyFloat_AsString and PyFloat_AsReprString should be deprecated:
316- XXX they pass a char buffer without passing a length.
317- */
318- void
319- PyFloat_AsString (char * buf , PyFloatObject * v )
320- {
321- format_float (buf , 100 , v , PREC_STR );
322- }
323-
324- void
325- PyFloat_AsReprString (char * buf , PyFloatObject * v )
326- {
327- format_float (buf , 100 , v , PREC_REPR );
328- }
329-
330311/* ARGSUSED */
331312static int
332313float_print (PyFloatObject * v , FILE * fp , int flags )
@@ -1275,7 +1256,7 @@ PyFloat_Fini(void)
12751256 if (PyFloat_CheckExact (p ) &&
12761257 p -> ob_refcnt != 0 ) {
12771258 char buf [100 ];
1278- PyFloat_AsString (buf , p );
1259+ format_float (buf , sizeof ( buf ), p , PREC_STR );
12791260 /* XXX(twouters) cast refcount to
12801261 long until %zd is universally
12811262 available
@@ -1527,6 +1508,14 @@ _PyFloat_Pack8(double x, unsigned char *p, int le)
15271508 }
15281509}
15291510
1511+ /* Should only be used by marshal. */
1512+ int
1513+ _PyFloat_Repr (double x , char * p , size_t len )
1514+ {
1515+ format_double (p , len , x , PREC_REPR );
1516+ return (int )strlen (p );
1517+ }
1518+
15301519double
15311520_PyFloat_Unpack4 (const unsigned char * p , int le )
15321521{
0 commit comments