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
16e2fca4
Kaydet (Commit)
16e2fca4
authored
Agu 03, 2012
tarafından
Jesus Cea
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Closes #15469: Correct __sizeof__ support for deque
üst
e9c53189
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
1 deletion
+39
-1
test_deque.py
Lib/test/test_deque.py
+16
-0
NEWS
Misc/NEWS
+3
-0
_collectionsmodule.c
Modules/_collectionsmodule.c
+20
-1
No files found.
Lib/test/test_deque.py
Dosyayı görüntüle @
16e2fca4
...
@@ -7,6 +7,7 @@ import copy
...
@@ -7,6 +7,7 @@ import copy
import
pickle
import
pickle
from
io
import
StringIO
from
io
import
StringIO
import
random
import
random
import
struct
BIG
=
100000
BIG
=
100000
...
@@ -518,6 +519,21 @@ class TestBasic(unittest.TestCase):
...
@@ -518,6 +519,21 @@ class TestBasic(unittest.TestCase):
gc
.
collect
()
gc
.
collect
()
self
.
assertTrue
(
ref
()
is
None
,
"Cycle was not collected"
)
self
.
assertTrue
(
ref
()
is
None
,
"Cycle was not collected"
)
check_sizeof
=
support
.
check_sizeof
@support.cpython_only
def
test_sizeof
(
self
):
BLOCKLEN
=
62
basesize
=
support
.
calcobjsize
(
'2P4PlP'
)
blocksize
=
struct
.
calcsize
(
'2P
%
dP'
%
BLOCKLEN
)
self
.
assertEqual
(
object
.
__sizeof__
(
deque
()),
basesize
)
check
=
self
.
check_sizeof
check
(
deque
(),
basesize
+
blocksize
)
check
(
deque
(
'a'
),
basesize
+
blocksize
)
check
(
deque
(
'a'
*
(
BLOCKLEN
//
2
)),
basesize
+
blocksize
)
check
(
deque
(
'a'
*
(
BLOCKLEN
//
2
+
1
)),
basesize
+
2
*
blocksize
)
check
(
deque
(
'a'
*
(
42
*
BLOCKLEN
)),
basesize
+
43
*
blocksize
)
class
TestVariousIteratorArgs
(
unittest
.
TestCase
):
class
TestVariousIteratorArgs
(
unittest
.
TestCase
):
def
test_constructor
(
self
):
def
test_constructor
(
self
):
...
...
Misc/NEWS
Dosyayı görüntüle @
16e2fca4
...
@@ -110,6 +110,9 @@ Library
...
@@ -110,6 +110,9 @@ Library
- Issue #15512: Add a __sizeof__ implementation for parser.
- Issue #15512: Add a __sizeof__ implementation for parser.
Patch by Serhiy Storchaka.
Patch by Serhiy Storchaka.
- Issue #15469: Add a __sizeof__ implementation for deque objects.
Patch by Serhiy Storchaka.
- Issue #15489: Add a __sizeof__ implementation for BytesIO objects.
- Issue #15489: Add a __sizeof__ implementation for BytesIO objects.
Patch by Serhiy Storchaka.
Patch by Serhiy Storchaka.
...
...
Modules/_collectionsmodule.c
Dosyayı görüntüle @
16e2fca4
...
@@ -932,6 +932,23 @@ deque_init(dequeobject *deque, PyObject *args, PyObject *kwdargs)
...
@@ -932,6 +932,23 @@ deque_init(dequeobject *deque, PyObject *args, PyObject *kwdargs)
return
0
;
return
0
;
}
}
static
PyObject
*
deque_sizeof
(
dequeobject
*
deque
,
void
*
unused
)
{
Py_ssize_t
res
;
Py_ssize_t
blocks
;
res
=
sizeof
(
dequeobject
);
blocks
=
(
deque
->
leftindex
+
deque
->
len
+
BLOCKLEN
-
1
)
/
BLOCKLEN
;
assert
(
deque
->
leftindex
+
deque
->
len
-
1
==
(
blocks
-
1
)
*
BLOCKLEN
+
deque
->
rightindex
);
res
+=
blocks
*
sizeof
(
block
);
return
PyLong_FromSsize_t
(
res
);
}
PyDoc_STRVAR
(
sizeof_doc
,
"D.__sizeof__() -- size of D in memory, in bytes"
);
static
PyObject
*
static
PyObject
*
deque_get_maxlen
(
dequeobject
*
deque
)
deque_get_maxlen
(
dequeobject
*
deque
)
{
{
...
@@ -995,7 +1012,9 @@ static PyMethodDef deque_methods[] = {
...
@@ -995,7 +1012,9 @@ static PyMethodDef deque_methods[] = {
{
"reverse"
,
(
PyCFunction
)
deque_reverse
,
{
"reverse"
,
(
PyCFunction
)
deque_reverse
,
METH_NOARGS
,
reverse_doc
},
METH_NOARGS
,
reverse_doc
},
{
"rotate"
,
(
PyCFunction
)
deque_rotate
,
{
"rotate"
,
(
PyCFunction
)
deque_rotate
,
METH_VARARGS
,
rotate_doc
},
METH_VARARGS
,
rotate_doc
},
{
"__sizeof__"
,
(
PyCFunction
)
deque_sizeof
,
METH_NOARGS
,
sizeof_doc
},
{
NULL
,
NULL
}
/* sentinel */
{
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