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
4af77a02
Kaydet (Commit)
4af77a02
authored
Kas 02, 2012
tarafından
Stefan Krah
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #15814: Use hash function that is compatible with the equality
definition from #15573.
üst
e6996ed5
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
8 deletions
+38
-8
stdtypes.rst
Doc/library/stdtypes.rst
+0
-6
test_buffer.py
Lib/test/test_buffer.py
+30
-2
memoryobject.c
Objects/memoryobject.c
+8
-0
No files found.
Doc/library/stdtypes.rst
Dosyayı görüntüle @
4af77a02
...
...
@@ -2393,12 +2393,6 @@ copying.
.. versionchanged:: 3.3
One-dimensional memoryviews with formats 'B', 'b' or 'c' are now hashable.
.. note::
Hashing of memoryviews with formats other than 'B', 'b' or 'c' as well
as hashing of multi-dimensional memoryviews is possible in version 3.3.0,
but will raise an error in 3.3.1 in order to be compatible with the new
memoryview equality definition.
:class:`memoryview` has several methods:
.. method:: __eq__(exporter)
...
...
Lib/test/test_buffer.py
Dosyayı görüntüle @
4af77a02
...
...
@@ -3999,14 +3999,42 @@ class TestBufferProtocol(unittest.TestCase):
m
=
memoryview
(
x
)
self
.
assertEqual
(
hash
(
m
),
hash
(
x
))
# equality-hash invariant
x
=
ndarray
(
list
(
range
(
12
)),
shape
=
[
12
],
format
=
'B'
)
a
=
memoryview
(
nd
)
y
=
ndarray
(
list
(
range
(
12
)),
shape
=
[
12
],
format
=
'b'
)
b
=
memoryview
(
nd
)
z
=
ndarray
(
list
(
bytes
(
chr
(
x
),
'latin-1'
)
for
x
in
range
(
12
)),
shape
=
[
12
],
format
=
'c'
)
c
=
memoryview
(
nd
)
if
(
a
==
b
):
self
.
assertEqual
(
hash
(
a
),
hash
(
b
))
if
(
a
==
c
):
self
.
assertEqual
(
hash
(
a
),
hash
(
c
))
if
(
b
==
c
):
self
.
assertEqual
(
hash
(
b
),
hash
(
c
))
# non-byte formats
nd
=
ndarray
(
list
(
range
(
12
)),
shape
=
[
2
,
2
,
3
],
format
=
'L'
)
m
=
memoryview
(
nd
)
self
.
assert
Equal
(
hash
(
m
),
hash
(
nd
.
tobytes
())
)
self
.
assert
Raises
(
ValueError
,
m
.
__hash__
)
nd
=
ndarray
(
list
(
range
(
-
6
,
6
)),
shape
=
[
2
,
2
,
3
],
format
=
'h'
)
m
=
memoryview
(
nd
)
self
.
assertEqual
(
hash
(
m
),
hash
(
nd
.
tobytes
()))
self
.
assertRaises
(
ValueError
,
m
.
__hash__
)
nd
=
ndarray
(
list
(
range
(
12
)),
shape
=
[
2
,
2
,
3
],
format
=
'= L'
)
m
=
memoryview
(
nd
)
self
.
assertRaises
(
ValueError
,
m
.
__hash__
)
nd
=
ndarray
(
list
(
range
(
-
6
,
6
)),
shape
=
[
2
,
2
,
3
],
format
=
'< h'
)
m
=
memoryview
(
nd
)
self
.
assertRaises
(
ValueError
,
m
.
__hash__
)
def
test_memoryview_release
(
self
):
...
...
Objects/memoryobject.c
Dosyayı görüntüle @
4af77a02
...
...
@@ -2707,6 +2707,8 @@ memory_hash(PyMemoryViewObject *self)
if
(
self
->
hash
==
-
1
)
{
Py_buffer
*
view
=
&
self
->
view
;
char
*
mem
=
view
->
buf
;
Py_ssize_t
ret
;
char
fmt
;
CHECK_RELEASED_INT
(
self
);
...
...
@@ -2715,6 +2717,12 @@ memory_hash(PyMemoryViewObject *self)
"cannot hash writable memoryview object"
);
return
-
1
;
}
ret
=
get_native_fmtchar
(
&
fmt
,
view
->
format
);
if
(
ret
<
0
||
!
IS_BYTE_FORMAT
(
fmt
))
{
PyErr_SetString
(
PyExc_ValueError
,
"memoryview: hashing is restricted to formats 'B', 'b' or 'c'"
);
return
-
1
;
}
if
(
view
->
obj
!=
NULL
&&
PyObject_Hash
(
view
->
obj
)
==
-
1
)
{
/* Keep the original error message */
return
-
1
;
...
...
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