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
42826566
Kaydet (Commit)
42826566
authored
Kas 15, 2014
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Issue #22193: Fixed integer overflow error in sys.getsizeof().
Fixed an error in _PySys_GetSizeOf declaration.
üst
7aaa67eb
030e92d1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
6 deletions
+42
-6
sysmodule.h
Include/sysmodule.h
+1
-1
test_sys.py
Lib/test/test_sys.py
+31
-0
sysmodule.c
Python/sysmodule.c
+10
-5
No files found.
Include/sysmodule.h
Dosyayı görüntüle @
42826566
...
@@ -34,7 +34,7 @@ PyAPI_FUNC(void) PySys_AddXOption(const wchar_t *);
...
@@ -34,7 +34,7 @@ PyAPI_FUNC(void) PySys_AddXOption(const wchar_t *);
PyAPI_FUNC
(
PyObject
*
)
PySys_GetXOptions
(
void
);
PyAPI_FUNC
(
PyObject
*
)
PySys_GetXOptions
(
void
);
#ifndef Py_LIMITED_API
#ifndef Py_LIMITED_API
PyAPI_
DATA
(
size_t
)
_PySys_GetSizeOf
(
PyObject
*
);
PyAPI_
FUNC
(
size_t
)
_PySys_GetSizeOf
(
PyObject
*
);
#endif
#endif
#ifdef __cplusplus
#ifdef __cplusplus
...
...
Lib/test/test_sys.py
Dosyayı görüntüle @
42826566
...
@@ -770,6 +770,37 @@ class SizeofTest(unittest.TestCase):
...
@@ -770,6 +770,37 @@ class SizeofTest(unittest.TestCase):
# but lists are
# but lists are
self
.
assertEqual
(
sys
.
getsizeof
([]),
vsize
(
'Pn'
)
+
gc_header_size
)
self
.
assertEqual
(
sys
.
getsizeof
([]),
vsize
(
'Pn'
)
+
gc_header_size
)
def
test_errors
(
self
):
class
BadSizeof
:
def
__sizeof__
(
self
):
raise
ValueError
self
.
assertRaises
(
ValueError
,
sys
.
getsizeof
,
BadSizeof
())
class
InvalidSizeof
:
def
__sizeof__
(
self
):
return
None
self
.
assertRaises
(
TypeError
,
sys
.
getsizeof
,
InvalidSizeof
())
sentinel
=
[
"sentinel"
]
self
.
assertIs
(
sys
.
getsizeof
(
InvalidSizeof
(),
sentinel
),
sentinel
)
class
FloatSizeof
:
def
__sizeof__
(
self
):
return
4.5
self
.
assertRaises
(
TypeError
,
sys
.
getsizeof
,
FloatSizeof
())
self
.
assertIs
(
sys
.
getsizeof
(
FloatSizeof
(),
sentinel
),
sentinel
)
class
OverflowSizeof
(
int
):
def
__sizeof__
(
self
):
return
int
(
self
)
self
.
assertEqual
(
sys
.
getsizeof
(
OverflowSizeof
(
sys
.
maxsize
)),
sys
.
maxsize
+
self
.
gc_headsize
)
with
self
.
assertRaises
(
OverflowError
):
sys
.
getsizeof
(
OverflowSizeof
(
sys
.
maxsize
+
1
))
with
self
.
assertRaises
(
ValueError
):
sys
.
getsizeof
(
OverflowSizeof
(
-
1
))
with
self
.
assertRaises
((
ValueError
,
OverflowError
)):
sys
.
getsizeof
(
OverflowSizeof
(
-
sys
.
maxsize
-
1
))
def
test_default
(
self
):
def
test_default
(
self
):
size
=
test
.
support
.
calcvobjsize
size
=
test
.
support
.
calcvobjsize
self
.
assertEqual
(
sys
.
getsizeof
(
True
),
size
(
''
)
+
self
.
longdigit
)
self
.
assertEqual
(
sys
.
getsizeof
(
True
),
size
(
''
)
+
self
.
longdigit
)
...
...
Python/sysmodule.c
Dosyayı görüntüle @
42826566
...
@@ -868,7 +868,7 @@ _PySys_GetSizeOf(PyObject *o)
...
@@ -868,7 +868,7 @@ _PySys_GetSizeOf(PyObject *o)
{
{
PyObject
*
res
=
NULL
;
PyObject
*
res
=
NULL
;
PyObject
*
method
;
PyObject
*
method
;
size_t
size
;
Py_s
size_t
size
;
/* Make sure the type is initialized. float gets initialized late */
/* Make sure the type is initialized. float gets initialized late */
if
(
PyType_Ready
(
Py_TYPE
(
o
))
<
0
)
if
(
PyType_Ready
(
Py_TYPE
(
o
))
<
0
)
...
@@ -889,15 +889,20 @@ _PySys_GetSizeOf(PyObject *o)
...
@@ -889,15 +889,20 @@ _PySys_GetSizeOf(PyObject *o)
if
(
res
==
NULL
)
if
(
res
==
NULL
)
return
(
size_t
)
-
1
;
return
(
size_t
)
-
1
;
size
=
PyLong_AsSize_t
(
res
);
size
=
PyLong_AsS
s
ize_t
(
res
);
Py_DECREF
(
res
);
Py_DECREF
(
res
);
if
(
size
==
(
size_t
)
-
1
&&
PyErr_Occurred
())
if
(
size
==
-
1
&&
PyErr_Occurred
())
return
(
size_t
)
-
1
;
if
(
size
<
0
)
{
PyErr_SetString
(
PyExc_ValueError
,
"__sizeof__() should return >= 0"
);
return
(
size_t
)
-
1
;
return
(
size_t
)
-
1
;
}
/* add gc_head size */
/* add gc_head size */
if
(
PyObject_IS_GC
(
o
))
if
(
PyObject_IS_GC
(
o
))
size
+=
sizeof
(
PyGC_Head
);
return
((
size_t
)
size
)
+
sizeof
(
PyGC_Head
);
return
size
;
return
(
size_t
)
size
;
}
}
static
PyObject
*
static
PyObject
*
...
...
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