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
2727503b
Kaydet (Commit)
2727503b
authored
Mar 20, 2008
tarafından
Gregory P. Smith
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
crc32 always returns unsigned. cleanup the code a bit and revert r61648 with
the proper fix.
üst
97797a9c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
28 deletions
+16
-28
test_zlib.py
Lib/test/test_zlib.py
+2
-2
binascii.c
Modules/binascii.c
+8
-20
zlibmodule.c
Modules/zlibmodule.c
+6
-6
No files found.
Lib/test/test_zlib.py
Dosyayı görüntüle @
2727503b
...
...
@@ -42,14 +42,14 @@ class ChecksumTestCase(unittest.TestCase):
def
test_crc32_adler32_unsigned
(
self
):
foo
=
'abcdefghijklmnop'
# explicitly test signed behavior
self
.
assertEqual
(
zlib
.
crc32
(
foo
),
-
1808088941
)
self
.
assertEqual
(
zlib
.
crc32
(
foo
),
2486878355
)
self
.
assertEqual
(
zlib
.
crc32
(
'spam'
),
1138425661
)
self
.
assertEqual
(
zlib
.
adler32
(
foo
+
foo
),
3573550353
)
self
.
assertEqual
(
zlib
.
adler32
(
'spam'
),
72286642
)
def
test_same_as_binascii_crc32
(
self
):
foo
=
'abcdefghijklmnop'
crc
=
-
1808088941
crc
=
2486878355
self
.
assertEqual
(
binascii
.
crc32
(
foo
),
crc
)
self
.
assertEqual
(
zlib
.
crc32
(
foo
),
crc
)
self
.
assertEqual
(
binascii
.
crc32
(
'spam'
),
zlib
.
crc32
(
'spam'
))
...
...
Modules/binascii.c
Dosyayı görüntüle @
2727503b
...
...
@@ -898,33 +898,21 @@ static PyObject *
binascii_crc32
(
PyObject
*
self
,
PyObject
*
args
)
{
/* By Jim Ahlstrom; All rights transferred to CNRI */
unsigned
char
*
bin_data
;
unsigned
long
crc
=
0UL
;
/* initial value of CRC */
unsigned
int
crc
=
0
;
/* initial value of CRC */
Py_ssize_t
len
;
long
result
;
unsigned
int
result
;
if
(
!
PyArg_ParseTuple
(
args
,
"s#|
k
:crc32"
,
&
bin_data
,
&
len
,
&
crc
)
)
if
(
!
PyArg_ParseTuple
(
args
,
"s#|
I
:crc32"
,
&
bin_data
,
&
len
,
&
crc
)
)
return
NULL
;
crc
=
~
crc
;
#if SIZEOF_LONG > 4
/* only want the trailing 32 bits */
crc
&=
0xFFFFFFFFUL
;
#endif
while
(
len
--
)
crc
=
crc_32_tab
[(
crc
^
*
bin_data
++
)
&
0xffUL
]
^
(
crc
>>
8
);
while
(
len
--
)
{
crc
=
crc_32_tab
[(
crc
^
*
bin_data
++
)
&
0xff
]
^
(
crc
>>
8
);
/* Note: (crc >> 8) MUST zero fill on left */
}
result
=
(
long
)(
crc
^
0xFFFFFFFFUL
);
#if SIZEOF_LONG > 4
/* Extend the sign bit. This is one way to ensure the result is the
* same across platforms. The other way would be to return an
* unbounded unsigned long, but the evidence suggests that lots of
* code outside this treats the result as if it were a signed 4-byte
* integer.
*/
result
|=
-
(
result
&
(
1L
<<
31
));
#endif
return
PyLong_FromLong
(
result
);
result
=
(
crc
^
0xFFFFFFFF
);
return
PyLong_FromUnsignedLong
(
result
&
0xffffffff
);
}
...
...
Modules/zlibmodule.c
Dosyayı görüntüle @
2727503b
...
...
@@ -915,14 +915,14 @@ PyDoc_STRVAR(adler32__doc__,
static
PyObject
*
PyZlib_adler32
(
PyObject
*
self
,
PyObject
*
args
)
{
u
Long
adler32val
=
adler32
(
0L
,
Z_NULL
,
0
);
u
nsigned
int
adler32val
=
adler32
(
0L
,
Z_NULL
,
0
);
Byte
*
buf
;
int
len
;
if
(
!
PyArg_ParseTuple
(
args
,
"s#|
k
:adler32"
,
&
buf
,
&
len
,
&
adler32val
))
if
(
!
PyArg_ParseTuple
(
args
,
"s#|
I
:adler32"
,
&
buf
,
&
len
,
&
adler32val
))
return
NULL
;
adler32val
=
adler32
(
adler32val
,
buf
,
len
);
return
PyLong_FromUnsignedLong
(
adler32val
&
0xffffffff
);
return
PyLong_FromUnsignedLong
(
adler32val
&
0xffffffff
U
);
}
PyDoc_STRVAR
(
crc32__doc__
,
...
...
@@ -934,13 +934,13 @@ PyDoc_STRVAR(crc32__doc__,
static
PyObject
*
PyZlib_crc32
(
PyObject
*
self
,
PyObject
*
args
)
{
u
Long
crc32val
=
crc32
(
0L
,
Z_NULL
,
0
);
u
nsigned
int
crc32val
=
crc32
(
0L
,
Z_NULL
,
0
);
Byte
*
buf
;
int
len
;
if
(
!
PyArg_ParseTuple
(
args
,
"s#|
k
:crc32"
,
&
buf
,
&
len
,
&
crc32val
))
if
(
!
PyArg_ParseTuple
(
args
,
"s#|
I
:crc32"
,
&
buf
,
&
len
,
&
crc32val
))
return
NULL
;
crc32val
=
crc32
(
crc32val
,
buf
,
len
);
return
PyLong_From
Long
(
crc32val
&
0xffffffff
);
return
PyLong_From
UnsignedLong
(
crc32val
&
0xffffffffU
);
}
...
...
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