summaryrefslogtreecommitdiffstats
path: root/Objects/codeobject.c
diff options
context:
space:
mode:
authorDong-hee Na <donghee.na92@gmail.com>2017-04-20 07:31:17 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-04-20 07:31:17 (GMT)
commitb4dc6af7a7862a8996cffed30d39d6add5ee58a3 (patch)
treefa5fe86f4f1aca739168d41dd874ec866dff8eab /Objects/codeobject.c
parent58f3c9dc8f5626abe09ac9738c34f6ba99ce2972 (diff)
downloadcpython-b4dc6af7a7862a8996cffed30d39d6add5ee58a3.zip
cpython-b4dc6af7a7862a8996cffed30d39d6add5ee58a3.tar.gz
cpython-b4dc6af7a7862a8996cffed30d39d6add5ee58a3.tar.bz2
bpo-12414: Update code_sizeof() to take in account co_extra memory. (#1168)
Diffstat (limited to 'Objects/codeobject.c')
-rw-r--r--Objects/codeobject.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index ebc7066..46bc45d 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -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);
}