3415
3414
if (!PyArg_ParseTuple(args, "O:__format__", &format_spec))
3417
if (PyString_Check(format_spec))
3418
return string_long__format__(self, args);
3416
if (PyBytes_Check(format_spec))
3417
return _PyLong_FormatAdvanced(self,
3418
PyBytes_AS_STRING(format_spec),
3419
PyBytes_GET_SIZE(format_spec));
3419
3420
if (PyUnicode_Check(format_spec)) {
3420
3421
/* Convert format_spec to a str */
3421
PyObject *result = NULL;
3422
PyObject *newargs = NULL;
3423
PyObject *string_format_spec = NULL;
3425
string_format_spec = PyObject_Str(format_spec);
3426
if (string_format_spec == NULL)
3429
newargs = Py_BuildValue("(O)", string_format_spec);
3430
if (newargs == NULL)
3433
result = string_long__format__(self, newargs);
3436
Py_XDECREF(string_format_spec);
3437
Py_XDECREF(newargs);
3423
PyObject *str_spec = PyObject_Str(format_spec);
3425
if (str_spec == NULL)
3428
result = _PyLong_FormatAdvanced(self,
3429
PyBytes_AS_STRING(str_spec),
3430
PyBytes_GET_SIZE(str_spec));
3432
Py_DECREF(str_spec);
3440
3435
PyErr_SetString(PyExc_TypeError, "__format__ requires str or unicode");
3440
long_sizeof(PyLongObject *v)
3444
res = sizeof(PyLongObject) + abs(v->ob_size) * sizeof(digit);
3445
if (v->ob_size != 0)
3446
res -= sizeof(digit);
3447
return PyInt_FromSsize_t(res);
3445
3451
static PyObject *
3446
3452
long_is_finite(PyObject *v)
3460
3466
"Truncating an Integral returns itself."},
3461
3467
{"__getnewargs__", (PyCFunction)long_getnewargs, METH_NOARGS},
3462
3468
{"__format__", (PyCFunction)long__format__, METH_VARARGS},
3469
{"__sizeof__", (PyCFunction)long_sizeof, METH_NOARGS,
3470
"Returns size in memory, in bytes"},
3463
3471
{NULL, NULL} /* sentinel */