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
47137250
Kaydet (Commit)
47137250
authored
Tem 05, 2009
tarafından
Alexandre Vassalotti
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add the fix for issue 4509 to the mapping methods.
üst
1d2e8b90
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
26 deletions
+31
-26
test_array.py
Lib/test/test_array.py
+21
-26
arraymodule.c
Modules/arraymodule.c
+10
-0
No files found.
Lib/test/test_array.py
Dosyayı görüntüle @
47137250
...
@@ -723,22 +723,37 @@ class BaseTest(unittest.TestCase):
...
@@ -723,22 +723,37 @@ class BaseTest(unittest.TestCase):
def
test_buffer
(
self
):
def
test_buffer
(
self
):
a
=
array
.
array
(
self
.
typecode
,
self
.
example
)
a
=
array
.
array
(
self
.
typecode
,
self
.
example
)
m
=
memoryview
(
a
)
m
=
memoryview
(
a
)
b
=
bytes
(
m
)
expected
=
m
.
tobytes
()
self
.
assertEqual
(
b
,
a
.
tostring
())
self
.
assertEqual
(
a
.
tostring
(),
expected
)
self
.
assertEqual
(
b
[
0
],
a
.
tostring
()[
0
])
self
.
assertEqual
(
a
.
tostring
()[
0
],
expected
[
0
])
# Resizing is forbidden when there are buffer exports
# Resizing is forbidden when there are buffer exports.
# For issue 4509, we also check after each error that
# the array was not modified.
self
.
assertRaises
(
BufferError
,
a
.
append
,
a
[
0
])
self
.
assertRaises
(
BufferError
,
a
.
append
,
a
[
0
])
self
.
assertEqual
(
m
.
tobytes
(),
expected
)
self
.
assertRaises
(
BufferError
,
a
.
extend
,
a
[
0
:
1
])
self
.
assertRaises
(
BufferError
,
a
.
extend
,
a
[
0
:
1
])
self
.
assertEqual
(
m
.
tobytes
(),
expected
)
self
.
assertRaises
(
BufferError
,
a
.
remove
,
a
[
0
])
self
.
assertRaises
(
BufferError
,
a
.
remove
,
a
[
0
])
self
.
assertEqual
(
m
.
tobytes
(),
expected
)
self
.
assertRaises
(
BufferError
,
a
.
pop
,
0
)
self
.
assertEqual
(
m
.
tobytes
(),
expected
)
self
.
assertRaises
(
BufferError
,
a
.
fromlist
,
a
.
tolist
())
self
.
assertRaises
(
BufferError
,
a
.
fromlist
,
a
.
tolist
())
self
.
assertEqual
(
m
.
tobytes
(),
expected
)
self
.
assertRaises
(
BufferError
,
a
.
fromstring
,
a
.
tostring
())
self
.
assertRaises
(
BufferError
,
a
.
fromstring
,
a
.
tostring
())
self
.
assertEqual
(
m
.
tobytes
(),
expected
)
if
self
.
typecode
==
'u'
:
if
self
.
typecode
==
'u'
:
self
.
assertRaises
(
BufferError
,
a
.
fromunicode
,
a
.
tounicode
())
self
.
assertRaises
(
BufferError
,
a
.
fromunicode
,
a
.
tounicode
())
self
.
assertEqual
(
m
.
tobytes
(),
expected
)
self
.
assertRaises
(
BufferError
,
operator
.
imul
,
a
,
2
)
self
.
assertEqual
(
m
.
tobytes
(),
expected
)
self
.
assertRaises
(
BufferError
,
operator
.
imul
,
a
,
0
)
self
.
assertEqual
(
m
.
tobytes
(),
expected
)
self
.
assertRaises
(
BufferError
,
operator
.
setitem
,
a
,
slice
(
0
,
0
),
a
)
self
.
assertRaises
(
BufferError
,
operator
.
setitem
,
a
,
slice
(
0
,
0
),
a
)
self
.
assertEqual
(
m
.
tobytes
(),
expected
)
self
.
assertRaises
(
BufferError
,
operator
.
delitem
,
a
,
0
)
self
.
assertRaises
(
BufferError
,
operator
.
delitem
,
a
,
0
)
self
.
assertEqual
(
m
.
tobytes
(),
expected
)
self
.
assertRaises
(
BufferError
,
operator
.
delitem
,
a
,
slice
(
0
,
1
))
self
.
assertRaises
(
BufferError
,
operator
.
delitem
,
a
,
slice
(
0
,
1
))
self
.
assertRaises
(
BufferError
,
operator
.
imul
,
a
,
2
)
self
.
assertEqual
(
m
.
tobytes
(),
expected
)
self
.
assertRaises
(
BufferError
,
operator
.
imul
,
a
,
0
)
def
test_weakref
(
self
):
def
test_weakref
(
self
):
s
=
array
.
array
(
self
.
typecode
,
self
.
example
)
s
=
array
.
array
(
self
.
typecode
,
self
.
example
)
...
@@ -767,26 +782,6 @@ class BaseTest(unittest.TestCase):
...
@@ -767,26 +782,6 @@ class BaseTest(unittest.TestCase):
a
=
array
.
array
(
'H'
,
b
"1234"
)
a
=
array
.
array
(
'H'
,
b
"1234"
)
self
.
assertEqual
(
len
(
a
)
*
a
.
itemsize
,
4
)
self
.
assertEqual
(
len
(
a
)
*
a
.
itemsize
,
4
)
def
test_memoryview_no_resize
(
self
):
# Test for issue 4509.
a
=
array
.
array
(
self
.
typecode
,
self
.
example
)
m
=
memoryview
(
a
)
expected
=
m
.
tobytes
()
self
.
assertRaises
(
BufferError
,
a
.
pop
,
0
)
self
.
assertEqual
(
m
.
tobytes
(),
expected
)
self
.
assertRaises
(
BufferError
,
a
.
remove
,
a
[
0
])
self
.
assertEqual
(
m
.
tobytes
(),
expected
)
self
.
assertRaises
(
BufferError
,
a
.
__setitem__
,
slice
(
0
,
0
),
a
)
self
.
assertEqual
(
m
.
tobytes
(),
expected
)
self
.
assertRaises
(
BufferError
,
a
.
__delitem__
,
slice
(
0
,
len
(
a
)))
self
.
assertEqual
(
m
.
tobytes
(),
expected
)
self
.
assertRaises
(
BufferError
,
a
.
__imul__
,
2
)
self
.
assertEqual
(
m
.
tobytes
(),
expected
)
self
.
assertRaises
(
BufferError
,
a
.
__iadd__
,
a
)
self
.
assertEqual
(
m
.
tobytes
(),
expected
)
self
.
assertRaises
(
BufferError
,
a
.
extend
,
a
)
self
.
assertEqual
(
m
.
tobytes
(),
expected
)
class
StringTest
(
BaseTest
):
class
StringTest
(
BaseTest
):
...
...
Modules/arraymodule.c
Dosyayı görüntüle @
47137250
...
@@ -1699,6 +1699,16 @@ array_ass_subscr(arrayobject* self, PyObject* item, PyObject* value)
...
@@ -1699,6 +1699,16 @@ array_ass_subscr(arrayobject* self, PyObject* item, PyObject* value)
if
((
step
>
0
&&
stop
<
start
)
||
if
((
step
>
0
&&
stop
<
start
)
||
(
step
<
0
&&
stop
>
start
))
(
step
<
0
&&
stop
>
start
))
stop
=
start
;
stop
=
start
;
/* Issue #4509: If the array has exported buffers and the slice
assignment would change the size of the array, fail early to make
sure we don't modify it. */
if
((
needed
==
0
||
slicelength
!=
needed
)
&&
self
->
ob_exports
>
0
)
{
PyErr_SetString
(
PyExc_BufferError
,
"cannot resize an array that is exporting buffers"
);
return
-
1
;
}
if
(
step
==
1
)
{
if
(
step
==
1
)
{
if
(
slicelength
>
needed
)
{
if
(
slicelength
>
needed
)
{
memmove
(
self
->
ob_item
+
(
start
+
needed
)
*
itemsize
,
memmove
(
self
->
ob_item
+
(
start
+
needed
)
*
itemsize
,
...
...
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