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
b0900e6a
Kaydet (Commit)
b0900e6a
authored
Ara 16, 2004
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
SF #1085304: Make array.array pickle-able
üst
e6bdb37e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
0 deletions
+46
-0
test_array.py
Lib/test/test_array.py
+19
-0
NEWS
Misc/NEWS
+2
-0
arraymodule.c
Modules/arraymodule.c
+25
-0
No files found.
Lib/test/test_array.py
Dosyayı görüntüle @
b0900e6a
...
...
@@ -7,6 +7,10 @@ import unittest
from
test
import
test_support
from
weakref
import
proxy
import
array
,
cStringIO
,
math
from
cPickle
import
loads
,
dumps
class
ArraySubclass
(
array
.
array
):
pass
tests
=
[]
# list to accumulate all tests
typecodes
=
"cubBhHiIlLfd"
...
...
@@ -81,6 +85,21 @@ class BaseTest(unittest.TestCase):
self
.
assertNotEqual
(
id
(
a
),
id
(
b
))
self
.
assertEqual
(
a
,
b
)
def
test_pickle
(
self
):
for
protocol
in
(
0
,
1
,
2
):
a
=
array
.
array
(
self
.
typecode
,
self
.
example
)
b
=
loads
(
dumps
(
a
,
protocol
))
self
.
assertNotEqual
(
id
(
a
),
id
(
b
))
self
.
assertEqual
(
a
,
b
)
a
=
ArraySubclass
(
self
.
typecode
,
self
.
example
)
a
.
x
=
10
b
=
loads
(
dumps
(
a
,
protocol
))
self
.
assertNotEqual
(
id
(
a
),
id
(
b
))
self
.
assertEqual
(
a
,
b
)
self
.
assertEqual
(
a
.
x
,
b
.
x
)
self
.
assertEqual
(
type
(
a
),
type
(
b
))
def
test_insert
(
self
):
a
=
array
.
array
(
self
.
typecode
,
self
.
example
)
a
.
insert
(
0
,
self
.
example
[
0
])
...
...
Misc/NEWS
Dosyayı görüntüle @
b0900e6a
...
...
@@ -17,6 +17,8 @@ Core and builtins
Extension Modules
-----------------
- array.array objects are now picklable.
- the cPickle module no longer accepts the deprecated None option in the
args tuple returned by __reduce__().
...
...
Modules/arraymodule.c
Dosyayı görüntüle @
b0900e6a
...
...
@@ -1132,6 +1132,29 @@ PyDoc_STRVAR(byteswap_doc,
Byteswap all items of the array. If the items in the array are not 1, 2,
\n
\
4, or 8 bytes in size, RuntimeError is raised."
);
static
PyObject
*
array_reduce
(
arrayobject
*
array
)
{
PyObject
*
dict
,
*
result
;
dict
=
PyObject_GetAttrString
((
PyObject
*
)
array
,
"__dict__"
);
if
(
dict
==
NULL
)
{
PyErr_Clear
();
dict
=
Py_None
;
Py_INCREF
(
dict
);
}
result
=
Py_BuildValue
(
"O(cs#)O"
,
array
->
ob_type
,
array
->
ob_descr
->
typecode
,
array
->
ob_item
,
array
->
ob_size
*
array
->
ob_descr
->
itemsize
,
dict
);
Py_DECREF
(
dict
);
return
result
;
}
PyDoc_STRVAR
(
array_doc
,
"Return state information for pickling."
);
static
PyObject
*
array_reverse
(
arrayobject
*
self
,
PyObject
*
unused
)
{
...
...
@@ -1490,6 +1513,8 @@ PyMethodDef array_methods[] = {
pop_doc
},
{
"read"
,
(
PyCFunction
)
array_fromfile
,
METH_VARARGS
,
fromfile_doc
},
{
"__reduce__"
,
(
PyCFunction
)
array_reduce
,
METH_NOARGS
,
array_doc
},
{
"remove"
,
(
PyCFunction
)
array_remove
,
METH_O
,
remove_doc
},
{
"reverse"
,
(
PyCFunction
)
array_reverse
,
METH_NOARGS
,
...
...
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