Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e37f8b2

Browse files
author
Stefan Krah
committed
Issue #14520: Add __sizeof__() method to the Decimal object.
1 parent f69aef7 commit e37f8b2

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

Modules/_decimal/_decimal.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4340,6 +4340,19 @@ dec_reduce(PyObject *self, PyObject *dummy UNUSED)
43404340
return result;
43414341
}
43424342

4343+
/* __sizeof__ */
4344+
static PyObject *
4345+
dec_sizeof(PyObject *v, PyObject *dummy UNUSED)
4346+
{
4347+
Py_ssize_t res;
4348+
4349+
res = sizeof(PyDecObject);
4350+
if (mpd_isdynamic_data(MPD(v))) {
4351+
res += MPD(v)->alloc * sizeof(mpd_uint_t);
4352+
}
4353+
return PyLong_FromSsize_t(res);
4354+
}
4355+
43434356
/* __trunc__ */
43444357
static PyObject *
43454358
dec_trunc(PyObject *self, PyObject *dummy UNUSED)
@@ -4503,6 +4516,7 @@ static PyMethodDef dec_methods [] =
45034516
{ "__floor__", dec_floor, METH_NOARGS, NULL },
45044517
{ "__trunc__", dec_trunc, METH_NOARGS, NULL },
45054518
{ "__complex__", dec_complex, METH_NOARGS, NULL },
4519+
{ "__sizeof__", dec_sizeof, METH_NOARGS, NULL },
45064520

45074521
{ NULL, NULL, 1 }
45084522
};

0 commit comments

Comments
 (0)