summaryrefslogtreecommitdiffstats
path: root/Objects/floatobject.c
diff options
context:
space:
mode:
authorEric Smith <eric@trueblade.com>2008-05-30 18:10:04 (GMT)
committerEric Smith <eric@trueblade.com>2008-05-30 18:10:04 (GMT)
commitdc13b79a384691ed966f760a58d73a1b835e7d6b (patch)
tree40aa36feea2e0ee23f41801a8959990914e3fc71 /Objects/floatobject.c
parent30fadc17990baf4005081d2cdcb8d3adc9c45a7a (diff)
downloadcpython-dc13b79a384691ed966f760a58d73a1b835e7d6b.zip
cpython-dc13b79a384691ed966f760a58d73a1b835e7d6b.tar.gz
cpython-dc13b79a384691ed966f760a58d73a1b835e7d6b.tar.bz2
Refactor and clean up str.format() code (and helpers) in advance of optimizations.
Diffstat (limited to 'Objects/floatobject.c')
-rw-r--r--Objects/floatobject.c29
1 files changed, 11 insertions, 18 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 3b49341..baf55aa 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -14,9 +14,6 @@
#include <ieeefp.h>
#endif
-#include "formatter_string.h"
-
-
#ifdef _OSF_SOURCE
/* OSF1 5.1 doesn't make this available with XOPEN_SOURCE_EXTENDED defined */
extern int finite(double);
@@ -1398,26 +1395,22 @@ float__format__(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "O:__format__", &format_spec))
return NULL;
if (PyBytes_Check(format_spec))
- return string_float__format__(self, args);
+ return _PyFloat_FormatAdvanced(self,
+ PyBytes_AS_STRING(format_spec),
+ PyBytes_GET_SIZE(format_spec));
if (PyUnicode_Check(format_spec)) {
/* Convert format_spec to a str */
- PyObject *result = NULL;
- PyObject *newargs = NULL;
- PyObject *string_format_spec = NULL;
+ PyObject *result;
+ PyObject *str_spec = PyObject_Str(format_spec);
- string_format_spec = PyObject_Str(format_spec);
- if (string_format_spec == NULL)
- goto done;
-
- newargs = Py_BuildValue("(O)", string_format_spec);
- if (newargs == NULL)
- goto done;
+ if (str_spec == NULL)
+ return NULL;
- result = string_float__format__(self, newargs);
+ result = _PyFloat_FormatAdvanced(self,
+ PyBytes_AS_STRING(str_spec),
+ PyBytes_GET_SIZE(str_spec));
- done:
- Py_XDECREF(string_format_spec);
- Py_XDECREF(newargs);
+ Py_DECREF(str_spec);
return result;
}
PyErr_SetString(PyExc_TypeError, "__format__ requires str or unicode");