~pythonregexp2.7/python/issue2636-12

« back to all changes in this revision

Viewing changes to Objects/floatobject.c

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-06-09 14:52:42 UTC
  • mfrom: (39033.1.3 Regexp-2.6)
  • Revision ID: darklord@timehorse.com-20080609145242-9m268zc6u87rp1vp
Merged in changes from the core Regexp branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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);
1397
1394
 
1398
1395
        if (!PyArg_ParseTuple(args, "O:__format__", &format_spec))
1399
1396
                return NULL;
1400
 
        if (PyString_Check(format_spec))
1401
 
                return string_float__format__(self, args);
 
1397
        if (PyBytes_Check(format_spec))
 
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;
1407
 
 
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;
1415
 
 
1416
 
                result = string_float__format__(self, newargs);
1417
 
 
1418
 
                done:
1419
 
                Py_XDECREF(string_format_spec);
1420
 
                Py_XDECREF(newargs);
 
1403
                PyObject *result;
 
1404
                PyObject *str_spec = PyObject_Str(format_spec);
 
1405
 
 
1406
                if (str_spec == NULL)
 
1407
                        return NULL;
 
1408
 
 
1409
                result = _PyFloat_FormatAdvanced(self,
 
1410
                                                 PyBytes_AS_STRING(str_spec),
 
1411
                                                 PyBytes_GET_SIZE(str_spec));
 
1412
 
 
1413
                Py_DECREF(str_spec);
1421
1414
                return result;
1422
1415
        }
1423
1416
        PyErr_SetString(PyExc_TypeError, "__format__ requires str or unicode");