Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
9f65899d
Kaydet (Commit)
9f65899d
authored
12 years ago
tarafından
Meador Inge
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Issue #15402: Add a __sizeof__ method to struct.Struct.
Initial patch by Serhiy Storchaka.
üst
fe114f02
b14d8c9b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
0 deletions
+31
-0
test_struct.py
Lib/test/test_struct.py
+10
-0
NEWS
Misc/NEWS
+4
-0
_struct.c
Modules/_struct.c
+17
-0
No files found.
Lib/test/test_struct.py
Dosyayı görüntüle @
9f65899d
...
...
@@ -572,6 +572,16 @@ class StructTest(unittest.TestCase):
s
=
struct
.
Struct
(
'i'
)
s
.
__init__
(
'ii'
)
def
test_sizeof
(
self
):
self
.
assertGreater
(
sys
.
getsizeof
(
struct
.
Struct
(
'BHILfdspP'
)),
sys
.
getsizeof
(
struct
.
Struct
(
'B'
)))
self
.
assertGreaterEqual
(
sys
.
getsizeof
(
struct
.
Struct
(
'123B'
)),
sys
.
getsizeof
(
struct
.
Struct
(
'B'
)))
self
.
assertGreaterEqual
(
sys
.
getsizeof
(
struct
.
Struct
(
'B'
*
123
)),
sys
.
getsizeof
(
struct
.
Struct
(
'123B'
)))
self
.
assertGreaterEqual
(
sys
.
getsizeof
(
struct
.
Struct
(
'123xB'
)),
sys
.
getsizeof
(
struct
.
Struct
(
'B'
)))
def
test_main
():
run_unittest
(
StructTest
)
...
...
This diff is collapsed.
Click to expand it.
Misc/NEWS
Dosyayı görüntüle @
9f65899d
...
...
@@ -52,6 +52,10 @@ Core and Builtins
Library
-------
-
Issue
#
15402
:
An
issue
in
the
struct
module
that
caused
sys
.
getsizeof
to
return
incorrect
results
for
struct
.
Struct
instances
has
been
fixed
.
Initial
patch
by
Serhiy
Storchaka
.
-
Issue
#
15232
:
when
mangle_from
is
True
,
email
.
Generator
now
correctly
mangles
lines
that
start
with
'From'
that
occur
in
a
MIME
preamble
or
epilogue
.
...
...
This diff is collapsed.
Click to expand it.
Modules/_struct.c
Dosyayı görüntüle @
9f65899d
...
...
@@ -1752,6 +1752,22 @@ s_get_size(PyStructObject *self, void *unused)
return
PyLong_FromSsize_t
(
self
->
s_size
);
}
PyDoc_STRVAR
(
s_sizeof__doc__
,
"S.__sizeof__() -> size of S in memory, in bytes"
);
static
PyObject
*
s_sizeof
(
PyStructObject
*
self
)
{
Py_ssize_t
size
;
formatcode
*
code
;
size
=
sizeof
(
PyStructObject
)
+
sizeof
(
formatcode
);
for
(
code
=
self
->
s_codes
;
code
->
fmtdef
!=
NULL
;
code
++
)
{
size
+=
sizeof
(
formatcode
);
}
return
PyLong_FromSsize_t
(
size
);
}
/* List of functions */
static
struct
PyMethodDef
s_methods
[]
=
{
...
...
@@ -1760,6 +1776,7 @@ static struct PyMethodDef s_methods[] = {
{
"unpack"
,
s_unpack
,
METH_O
,
s_unpack__doc__
},
{
"unpack_from"
,
(
PyCFunction
)
s_unpack_from
,
METH_VARARGS
|
METH_KEYWORDS
,
s_unpack_from__doc__
},
{
"__sizeof__"
,
(
PyCFunction
)
s_sizeof
,
METH_NOARGS
,
s_sizeof__doc__
},
{
NULL
,
NULL
}
/* sentinel */
};
...
...
This diff is collapsed.
Click to expand it.
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