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
2d639d56
Commit
2d639d56
authored
Aug 10, 2012
by
Meador Inge
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #15424: Add a __sizeof__ implementation for array objects.
Patch by Ludwig Hähne.
parent
a939105a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
0 deletions
+32
-0
Lib/test/test_array.py
Lib/test/test_array.py
+13
-0
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/arraymodule.c
Modules/arraymodule.c
+15
-0
No files found.
Lib/test/test_array.py
View file @
2d639d56
...
...
@@ -985,6 +985,19 @@ class UnsignedNumberTest(NumberTest):
upper
=
long
(
pow
(
2
,
a
.
itemsize
*
8
))
-
1L
self
.
check_overflow
(
lower
,
upper
)
@
test_support
.
cpython_only
def
test_sizeof_with_buffer
(
self
):
a
=
array
.
array
(
self
.
typecode
,
self
.
example
)
basesize
=
test_support
.
calcvobjsize
(
'4P'
)
buffer_size
=
a
.
buffer_info
()[
1
]
*
a
.
itemsize
test_support
.
check_sizeof
(
self
,
a
,
basesize
+
buffer_size
)
@
test_support
.
cpython_only
def
test_sizeof_without_buffer
(
self
):
a
=
array
.
array
(
self
.
typecode
)
basesize
=
test_support
.
calcvobjsize
(
'4P'
)
test_support
.
check_sizeof
(
self
,
a
,
basesize
)
class
ByteTest
(
SignedNumberTest
):
typecode
=
'b'
...
...
Misc/ACKS
View file @
2d639d56
...
...
@@ -393,6 +393,7 @@ Jim Hugunin
Greg Humphreys
Eric Huss
Jeremy Hylton
Ludwig Hähne
Gerhard Häring
Fredrik Håård
Catalin Iacob
...
...
Misc/NEWS
View file @
2d639d56
...
...
@@ -94,6 +94,9 @@ Library
- Issue #15567: Fix NameError when running threading._test
- Issue #15424: Add a __sizeof__ implementation for array objects.
Patch by Ludwig Hähne.
- Issue #13052: Fix IDLE crashing when replace string in Search/Replace dialog
ended with '
\
'. Patch by Roger Serwy.
...
...
Modules/arraymodule.c
View file @
2d639d56
...
...
@@ -1532,6 +1532,19 @@ array_reduce(arrayobject *array)
PyDoc_STRVAR
(
reduce_doc
,
"Return state information for pickling."
);
static
PyObject
*
array_sizeof
(
arrayobject
*
self
,
PyObject
*
unused
)
{
Py_ssize_t
res
;
res
=
sizeof
(
arrayobject
)
+
self
->
allocated
*
self
->
ob_descr
->
itemsize
;
return
PyLong_FromSsize_t
(
res
);
}
PyDoc_STRVAR
(
sizeof_doc
,
"__sizeof__() -> int
\n
\
\n
\
Size of the array in memory, in bytes."
);
static
PyObject
*
array_get_typecode
(
arrayobject
*
a
,
void
*
closure
)
{
...
...
@@ -1606,6 +1619,8 @@ static PyMethodDef array_methods[] = {
#endif
{
"write"
,
(
PyCFunction
)
array_tofile_as_write
,
METH_O
,
tofile_doc
},
{
"__sizeof__"
,
(
PyCFunction
)
array_sizeof
,
METH_NOARGS
,
sizeof_doc
},
{
NULL
,
NULL
}
/* sentinel */
};
...
...
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