|
14 | 14 | #include <ieeefp.h> |
15 | 15 | #endif |
16 | 16 |
|
17 | | -#include "formatter_string.h" |
18 | | - |
19 | | - |
20 | 17 | #ifdef _OSF_SOURCE |
21 | 18 | /* OSF1 5.1 doesn't make this available with XOPEN_SOURCE_EXTENDED defined */ |
22 | 19 | extern int finite(double); |
@@ -1398,26 +1395,22 @@ float__format__(PyObject *self, PyObject *args) |
1398 | 1395 | if (!PyArg_ParseTuple(args, "O:__format__", &format_spec)) |
1399 | 1396 | return NULL; |
1400 | 1397 | if (PyBytes_Check(format_spec)) |
1401 | | - return string_float__format__(self, args); |
| 1398 | + return _PyFloat_FormatAdvanced(self, |
| 1399 | + PyBytes_AS_STRING(format_spec), |
| 1400 | + PyBytes_GET_SIZE(format_spec)); |
1402 | 1401 | if (PyUnicode_Check(format_spec)) { |
1403 | 1402 | /* Convert format_spec to a str */ |
1404 | | - PyObject *result = NULL; |
1405 | | - PyObject *newargs = NULL; |
1406 | | - PyObject *string_format_spec = NULL; |
| 1403 | + PyObject *result; |
| 1404 | + PyObject *str_spec = PyObject_Str(format_spec); |
1407 | 1405 |
|
1408 | | - string_format_spec = PyObject_Str(format_spec); |
1409 | | - if (string_format_spec == NULL) |
1410 | | - goto done; |
1411 | | - |
1412 | | - newargs = Py_BuildValue("(O)", string_format_spec); |
1413 | | - if (newargs == NULL) |
1414 | | - goto done; |
| 1406 | + if (str_spec == NULL) |
| 1407 | + return NULL; |
1415 | 1408 |
|
1416 | | - result = string_float__format__(self, newargs); |
| 1409 | + result = _PyFloat_FormatAdvanced(self, |
| 1410 | + PyBytes_AS_STRING(str_spec), |
| 1411 | + PyBytes_GET_SIZE(str_spec)); |
1417 | 1412 |
|
1418 | | - done: |
1419 | | - Py_XDECREF(string_format_spec); |
1420 | | - Py_XDECREF(newargs); |
| 1413 | + Py_DECREF(str_spec); |
1421 | 1414 | return result; |
1422 | 1415 | } |
1423 | 1416 | PyErr_SetString(PyExc_TypeError, "__format__ requires str or unicode"); |
|
0 commit comments