Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
b4dc6af7
Commit
b4dc6af7
authored
Apr 20, 2017
by
Dong-hee Na
Committed by
Serhiy Storchaka
Apr 20, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-12414: Update code_sizeof() to take in account co_extra memory. (#1168)
parent
58f3c9dc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
5 deletions
+16
-5
Lib/test/test_sys.py
Lib/test/test_sys.py
+5
-3
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+4
-0
Objects/codeobject.c
Objects/codeobject.c
+6
-2
No files found.
Lib/test/test_sys.py
View file @
b4dc6af7
...
...
@@ -922,13 +922,15 @@ class SizeofTest(unittest.TestCase):
return
inner
check
(
get_cell
().
__closure__
[
0
],
size
(
'P'
))
# code
check
(
get_cell
().
__code__
,
size
(
'6i13P'
))
check
(
get_cell
.
__code__
,
size
(
'6i13P'
))
def
check_code_size
(
a
,
expected_size
):
self
.
assertGreaterEqual
(
sys
.
getsizeof
(
a
),
expected_size
)
check_code_size
(
get_cell
().
__code__
,
size
(
'6i13P'
))
check_code_size
(
get_cell
.
__code__
,
size
(
'6i13P'
))
def
get_cell2
(
x
):
def
inner
():
return
x
return
inner
check
(
get_cell2
.
__code__
,
size
(
'6i13P'
)
+
calcsize
(
'n'
))
check
_code_size
(
get_cell2
.
__code__
,
size
(
'6i13P'
)
+
calcsize
(
'n'
))
# complex
check
(
complex
(
0
,
1
),
size
(
'2d'
))
# method_descriptor (descriptor object)
...
...
Misc/ACKS
View file @
b4dc6af7
...
...
@@ -1063,6 +1063,7 @@ R. David Murray
Matti Mäki
Jörg Müller
Kaushik N
Dong-hee Na
Dale Nagata
John Nagle
Takahiro Nakayama
...
...
Misc/NEWS
View file @
b4dc6af7
...
...
@@ -10,6 +10,10 @@ What's New in Python 3.7.0 alpha 1?
Core and Builtins
-----------------
- bpo-12414: sys.getsizeof() on a code object now returns the sizes
which includes the code struct and sizes of objects which it references.
Patch by Dong-hee Na.
- bpo-29839: len() now raises ValueError rather than OverflowError if
__len__() returned a large negative integer.
...
...
Objects/codeobject.c
View file @
b4dc6af7
...
...
@@ -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
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment