bpo-12414: Update code_sizeof() to take in account co_extra memory. (#1168)

This commit is contained in:
Dong-hee Na 2017-04-20 16:31:17 +09:00 committed by Serhiy Storchaka
parent 58f3c9dc8f
commit b4dc6af7a7
4 changed files with 16 additions and 5 deletions

View file

@ -451,11 +451,15 @@ code_dealloc(PyCodeObject *co)
static PyObject *
code_sizeof(PyCodeObject *co, void *unused)
{
Py_ssize_t res;
Py_ssize_t res = _PyObject_SIZE(Py_TYPE(co));
_PyCodeObjectExtra *co_extra = (_PyCodeObjectExtra*) co->co_extra;
res = _PyObject_SIZE(Py_TYPE(co));
if (co->co_cell2arg != NULL && co->co_cellvars != NULL)
res += PyTuple_GET_SIZE(co->co_cellvars) * sizeof(Py_ssize_t);
if (co_extra != NULL)
res += co_extra->ce_size * sizeof(co_extra->ce_extras[0]);
return PyLong_FromSsize_t(res);
}