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
776152b6
Kaydet (Commit)
776152b6
authored
May 22, 2007
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
zlib now uses bytes everywhere, and the test passes.
üst
dcee3c0d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
78 deletions
+104
-78
test_zlib.py
Lib/test/test_zlib.py
+42
-42
zlibmodule.c
Modules/zlibmodule.c
+62
-36
No files found.
Lib/test/test_zlib.py
Dosyayı görüntüle @
776152b6
...
@@ -7,22 +7,22 @@ import random
...
@@ -7,22 +7,22 @@ import random
class
ChecksumTestCase
(
unittest
.
TestCase
):
class
ChecksumTestCase
(
unittest
.
TestCase
):
# checksum test cases
# checksum test cases
def
test_crc32start
(
self
):
def
test_crc32start
(
self
):
self
.
assertEqual
(
zlib
.
crc32
(
""
),
zlib
.
crc32
(
""
,
0
))
self
.
assertEqual
(
zlib
.
crc32
(
b
""
),
zlib
.
crc32
(
b
""
,
0
))
self
.
assert_
(
zlib
.
crc32
(
"abc"
,
0xffffffff
))
self
.
assert_
(
zlib
.
crc32
(
b
"abc"
,
0xffffffff
))
def
test_crc32empty
(
self
):
def
test_crc32empty
(
self
):
self
.
assertEqual
(
zlib
.
crc32
(
""
,
0
),
0
)
self
.
assertEqual
(
zlib
.
crc32
(
b
""
,
0
),
0
)
self
.
assertEqual
(
zlib
.
crc32
(
""
,
1
),
1
)
self
.
assertEqual
(
zlib
.
crc32
(
b
""
,
1
),
1
)
self
.
assertEqual
(
zlib
.
crc32
(
""
,
432
),
432
)
self
.
assertEqual
(
zlib
.
crc32
(
b
""
,
432
),
432
)
def
test_adler32start
(
self
):
def
test_adler32start
(
self
):
self
.
assertEqual
(
zlib
.
adler32
(
""
),
zlib
.
adler32
(
""
,
1
))
self
.
assertEqual
(
zlib
.
adler32
(
b
""
),
zlib
.
adler32
(
b
""
,
1
))
self
.
assert_
(
zlib
.
adler32
(
"abc"
,
0xffffffff
))
self
.
assert_
(
zlib
.
adler32
(
b
"abc"
,
0xffffffff
))
def
test_adler32empty
(
self
):
def
test_adler32empty
(
self
):
self
.
assertEqual
(
zlib
.
adler32
(
""
,
0
),
0
)
self
.
assertEqual
(
zlib
.
adler32
(
b
""
,
0
),
0
)
self
.
assertEqual
(
zlib
.
adler32
(
""
,
1
),
1
)
self
.
assertEqual
(
zlib
.
adler32
(
b
""
,
1
),
1
)
self
.
assertEqual
(
zlib
.
adler32
(
""
,
432
),
432
)
self
.
assertEqual
(
zlib
.
adler32
(
b
""
,
432
),
432
)
def
assertEqual32
(
self
,
seen
,
expected
):
def
assertEqual32
(
self
,
seen
,
expected
):
# 32-bit values masked -- checksums on 32- vs 64- bit machines
# 32-bit values masked -- checksums on 32- vs 64- bit machines
...
@@ -30,13 +30,13 @@ class ChecksumTestCase(unittest.TestCase):
...
@@ -30,13 +30,13 @@ class ChecksumTestCase(unittest.TestCase):
self
.
assertEqual
(
seen
&
0x0FFFFFFFF
,
expected
&
0x0FFFFFFFF
)
self
.
assertEqual
(
seen
&
0x0FFFFFFFF
,
expected
&
0x0FFFFFFFF
)
def
test_penguins
(
self
):
def
test_penguins
(
self
):
self
.
assertEqual32
(
zlib
.
crc32
(
"penguin"
,
0
),
0x0e5c1a120
)
self
.
assertEqual32
(
zlib
.
crc32
(
b
"penguin"
,
0
),
0x0e5c1a120
)
self
.
assertEqual32
(
zlib
.
crc32
(
"penguin"
,
1
),
0x43b6aa94
)
self
.
assertEqual32
(
zlib
.
crc32
(
b
"penguin"
,
1
),
0x43b6aa94
)
self
.
assertEqual32
(
zlib
.
adler32
(
"penguin"
,
0
),
0x0bcf02f6
)
self
.
assertEqual32
(
zlib
.
adler32
(
b
"penguin"
,
0
),
0x0bcf02f6
)
self
.
assertEqual32
(
zlib
.
adler32
(
"penguin"
,
1
),
0x0bd602f7
)
self
.
assertEqual32
(
zlib
.
adler32
(
b
"penguin"
,
1
),
0x0bd602f7
)
self
.
assertEqual
(
zlib
.
crc32
(
"penguin"
),
zlib
.
crc32
(
"penguin"
,
0
))
self
.
assertEqual
(
zlib
.
crc32
(
b
"penguin"
),
zlib
.
crc32
(
b
"penguin"
,
0
))
self
.
assertEqual
(
zlib
.
adler32
(
"penguin"
),
zlib
.
adler32
(
"penguin"
,
1
))
self
.
assertEqual
(
zlib
.
adler32
(
b
"penguin"
),
zlib
.
adler32
(
b
"penguin"
,
1
))
...
@@ -109,10 +109,10 @@ class CompressObjectTestCase(unittest.TestCase):
...
@@ -109,10 +109,10 @@ class CompressObjectTestCase(unittest.TestCase):
for
i
in
range
(
0
,
len
(
data
),
256
):
for
i
in
range
(
0
,
len
(
data
),
256
):
bufs
.
append
(
co
.
compress
(
data
[
i
:
i
+
256
]))
bufs
.
append
(
co
.
compress
(
data
[
i
:
i
+
256
]))
bufs
.
append
(
co
.
flush
())
bufs
.
append
(
co
.
flush
())
combuf
=
''
.
join
(
bufs
)
combuf
=
b
''
.
join
(
bufs
)
dco
=
zlib
.
decompressobj
()
dco
=
zlib
.
decompressobj
()
y1
=
dco
.
decompress
(
''
.
join
(
bufs
))
y1
=
dco
.
decompress
(
b
''
.
join
(
bufs
))
y2
=
dco
.
flush
()
y2
=
dco
.
flush
()
self
.
assertEqual
(
data
,
y1
+
y2
)
self
.
assertEqual
(
data
,
y1
+
y2
)
...
@@ -125,7 +125,7 @@ class CompressObjectTestCase(unittest.TestCase):
...
@@ -125,7 +125,7 @@ class CompressObjectTestCase(unittest.TestCase):
for
i
in
range
(
0
,
len
(
data
),
cx
):
for
i
in
range
(
0
,
len
(
data
),
cx
):
bufs
.
append
(
co
.
compress
(
data
[
i
:
i
+
cx
]))
bufs
.
append
(
co
.
compress
(
data
[
i
:
i
+
cx
]))
bufs
.
append
(
co
.
flush
())
bufs
.
append
(
co
.
flush
())
combuf
=
''
.
join
(
bufs
)
combuf
=
b
''
.
join
(
bufs
)
self
.
assertEqual
(
data
,
zlib
.
decompress
(
combuf
))
self
.
assertEqual
(
data
,
zlib
.
decompress
(
combuf
))
...
@@ -133,8 +133,8 @@ class CompressObjectTestCase(unittest.TestCase):
...
@@ -133,8 +133,8 @@ class CompressObjectTestCase(unittest.TestCase):
bufs
=
[]
bufs
=
[]
for
i
in
range
(
0
,
len
(
combuf
),
dcx
):
for
i
in
range
(
0
,
len
(
combuf
),
dcx
):
bufs
.
append
(
dco
.
decompress
(
combuf
[
i
:
i
+
dcx
]))
bufs
.
append
(
dco
.
decompress
(
combuf
[
i
:
i
+
dcx
]))
self
.
assertEqual
(
''
,
dco
.
unconsumed_tail
,
########
self
.
assertEqual
(
b
''
,
dco
.
unconsumed_tail
,
########
"(A) uct should be '': not
%
d long"
%
"(A) uct should be
b
'': not
%
d long"
%
len
(
dco
.
unconsumed_tail
))
len
(
dco
.
unconsumed_tail
))
if
flush
:
if
flush
:
bufs
.
append
(
dco
.
flush
())
bufs
.
append
(
dco
.
flush
())
...
@@ -145,10 +145,10 @@ class CompressObjectTestCase(unittest.TestCase):
...
@@ -145,10 +145,10 @@ class CompressObjectTestCase(unittest.TestCase):
bufs
.
append
(
chunk
)
bufs
.
append
(
chunk
)
else
:
else
:
break
break
self
.
assertEqual
(
''
,
dco
.
unconsumed_tail
,
########
self
.
assertEqual
(
b
''
,
dco
.
unconsumed_tail
,
########
"(B) uct should be '': not
%
d long"
%
"(B) uct should be
b
'': not
%
d long"
%
len
(
dco
.
unconsumed_tail
))
len
(
dco
.
unconsumed_tail
))
self
.
assertEqual
(
data
,
''
.
join
(
bufs
))
self
.
assertEqual
(
data
,
b
''
.
join
(
bufs
))
# Failure means: "decompressobj with init options failed"
# Failure means: "decompressobj with init options failed"
def
test_decompincflush
(
self
):
def
test_decompincflush
(
self
):
...
@@ -164,7 +164,7 @@ class CompressObjectTestCase(unittest.TestCase):
...
@@ -164,7 +164,7 @@ class CompressObjectTestCase(unittest.TestCase):
for
i
in
range
(
0
,
len
(
data
),
cx
):
for
i
in
range
(
0
,
len
(
data
),
cx
):
bufs
.
append
(
co
.
compress
(
data
[
i
:
i
+
cx
]))
bufs
.
append
(
co
.
compress
(
data
[
i
:
i
+
cx
]))
bufs
.
append
(
co
.
flush
())
bufs
.
append
(
co
.
flush
())
combuf
=
''
.
join
(
bufs
)
combuf
=
b
''
.
join
(
bufs
)
self
.
assertEqual
(
data
,
zlib
.
decompress
(
combuf
),
self
.
assertEqual
(
data
,
zlib
.
decompress
(
combuf
),
'compressed data failure'
)
'compressed data failure'
)
...
@@ -179,7 +179,7 @@ class CompressObjectTestCase(unittest.TestCase):
...
@@ -179,7 +179,7 @@ class CompressObjectTestCase(unittest.TestCase):
bufs
.
append
(
chunk
)
bufs
.
append
(
chunk
)
cb
=
dco
.
unconsumed_tail
cb
=
dco
.
unconsumed_tail
bufs
.
append
(
dco
.
flush
())
bufs
.
append
(
dco
.
flush
())
self
.
assertEqual
(
data
,
''
.
join
(
bufs
),
'Wrong data retrieved'
)
self
.
assertEqual
(
data
,
b
''
.
join
(
bufs
),
'Wrong data retrieved'
)
def
test_decompressmaxlen
(
self
,
flush
=
False
):
def
test_decompressmaxlen
(
self
,
flush
=
False
):
# Check a decompression object with max_length specified
# Check a decompression object with max_length specified
...
@@ -189,7 +189,7 @@ class CompressObjectTestCase(unittest.TestCase):
...
@@ -189,7 +189,7 @@ class CompressObjectTestCase(unittest.TestCase):
for
i
in
range
(
0
,
len
(
data
),
256
):
for
i
in
range
(
0
,
len
(
data
),
256
):
bufs
.
append
(
co
.
compress
(
data
[
i
:
i
+
256
]))
bufs
.
append
(
co
.
compress
(
data
[
i
:
i
+
256
]))
bufs
.
append
(
co
.
flush
())
bufs
.
append
(
co
.
flush
())
combuf
=
''
.
join
(
bufs
)
combuf
=
b
''
.
join
(
bufs
)
self
.
assertEqual
(
data
,
zlib
.
decompress
(
combuf
),
self
.
assertEqual
(
data
,
zlib
.
decompress
(
combuf
),
'compressed data failure'
)
'compressed data failure'
)
...
@@ -211,7 +211,7 @@ class CompressObjectTestCase(unittest.TestCase):
...
@@ -211,7 +211,7 @@ class CompressObjectTestCase(unittest.TestCase):
self
.
failIf
(
len
(
chunk
)
>
max_length
,
self
.
failIf
(
len
(
chunk
)
>
max_length
,
'chunk too big (
%
d>
%
d)'
%
(
len
(
chunk
),
max_length
))
'chunk too big (
%
d>
%
d)'
%
(
len
(
chunk
),
max_length
))
bufs
.
append
(
chunk
)
bufs
.
append
(
chunk
)
self
.
assertEqual
(
data
,
''
.
join
(
bufs
),
'Wrong data retrieved'
)
self
.
assertEqual
(
data
,
b
''
.
join
(
bufs
),
'Wrong data retrieved'
)
def
test_decompressmaxlenflush
(
self
):
def
test_decompressmaxlenflush
(
self
):
self
.
test_decompressmaxlen
(
flush
=
True
)
self
.
test_decompressmaxlen
(
flush
=
True
)
...
@@ -220,7 +220,7 @@ class CompressObjectTestCase(unittest.TestCase):
...
@@ -220,7 +220,7 @@ class CompressObjectTestCase(unittest.TestCase):
# Misc tests of max_length
# Misc tests of max_length
dco
=
zlib
.
decompressobj
()
dco
=
zlib
.
decompressobj
()
self
.
assertRaises
(
ValueError
,
dco
.
decompress
,
""
,
-
1
)
self
.
assertRaises
(
ValueError
,
dco
.
decompress
,
""
,
-
1
)
self
.
assertEqual
(
''
,
dco
.
unconsumed_tail
)
self
.
assertEqual
(
b
''
,
dco
.
unconsumed_tail
)
def
test_flushes
(
self
):
def
test_flushes
(
self
):
# Test flush() with the various options, using all the
# Test flush() with the various options, using all the
...
@@ -237,7 +237,7 @@ class CompressObjectTestCase(unittest.TestCase):
...
@@ -237,7 +237,7 @@ class CompressObjectTestCase(unittest.TestCase):
b
=
obj
.
flush
(
sync
)
b
=
obj
.
flush
(
sync
)
c
=
obj
.
compress
(
data
[
3000
:]
)
c
=
obj
.
compress
(
data
[
3000
:]
)
d
=
obj
.
flush
()
d
=
obj
.
flush
()
self
.
assertEqual
(
zlib
.
decompress
(
''
.
join
([
a
,
b
,
c
,
d
])),
self
.
assertEqual
(
zlib
.
decompress
(
b
''
.
join
([
a
,
b
,
c
,
d
])),
data
,
(
"Decompress failed: flush "
data
,
(
"Decompress failed: flush "
"mode=
%
i, level=
%
i"
)
%
(
sync
,
level
))
"mode=
%
i, level=
%
i"
)
%
(
sync
,
level
))
del
obj
del
obj
...
@@ -284,13 +284,13 @@ class CompressObjectTestCase(unittest.TestCase):
...
@@ -284,13 +284,13 @@ class CompressObjectTestCase(unittest.TestCase):
co
=
zlib
.
compressobj
(
zlib
.
Z_BEST_COMPRESSION
)
co
=
zlib
.
compressobj
(
zlib
.
Z_BEST_COMPRESSION
)
self
.
failUnless
(
co
.
flush
())
# Returns a zlib header
self
.
failUnless
(
co
.
flush
())
# Returns a zlib header
dco
=
zlib
.
decompressobj
()
dco
=
zlib
.
decompressobj
()
self
.
assertEqual
(
dco
.
flush
(),
""
)
# Returns nothing
self
.
assertEqual
(
dco
.
flush
(),
b
""
)
# Returns nothing
if
hasattr
(
zlib
.
compressobj
(),
"copy"
):
if
hasattr
(
zlib
.
compressobj
(),
"copy"
):
def
test_compresscopy
(
self
):
def
test_compresscopy
(
self
):
# Test copying a compression object
# Test copying a compression object
data0
=
HAMLET_SCENE
data0
=
HAMLET_SCENE
data1
=
HAMLET_SCENE
.
swapcase
(
)
data1
=
bytes
(
str
(
HAMLET_SCENE
,
"ascii"
)
.
swapcase
(),
"ascii"
)
c0
=
zlib
.
compressobj
(
zlib
.
Z_BEST_COMPRESSION
)
c0
=
zlib
.
compressobj
(
zlib
.
Z_BEST_COMPRESSION
)
bufs0
=
[]
bufs0
=
[]
bufs0
.
append
(
c0
.
compress
(
data0
))
bufs0
.
append
(
c0
.
compress
(
data0
))
...
@@ -300,11 +300,11 @@ class CompressObjectTestCase(unittest.TestCase):
...
@@ -300,11 +300,11 @@ class CompressObjectTestCase(unittest.TestCase):
bufs0
.
append
(
c0
.
compress
(
data0
))
bufs0
.
append
(
c0
.
compress
(
data0
))
bufs0
.
append
(
c0
.
flush
())
bufs0
.
append
(
c0
.
flush
())
s0
=
''
.
join
(
bufs0
)
s0
=
b
''
.
join
(
bufs0
)
bufs1
.
append
(
c1
.
compress
(
data1
))
bufs1
.
append
(
c1
.
compress
(
data1
))
bufs1
.
append
(
c1
.
flush
())
bufs1
.
append
(
c1
.
flush
())
s1
=
''
.
join
(
bufs1
)
s1
=
b
''
.
join
(
bufs1
)
self
.
assertEqual
(
zlib
.
decompress
(
s0
),
data0
+
data0
)
self
.
assertEqual
(
zlib
.
decompress
(
s0
),
data0
+
data0
)
self
.
assertEqual
(
zlib
.
decompress
(
s1
),
data0
+
data1
)
self
.
assertEqual
(
zlib
.
decompress
(
s1
),
data0
+
data1
)
...
@@ -330,10 +330,10 @@ class CompressObjectTestCase(unittest.TestCase):
...
@@ -330,10 +330,10 @@ class CompressObjectTestCase(unittest.TestCase):
bufs1
=
bufs0
[:]
bufs1
=
bufs0
[:]
bufs0
.
append
(
d0
.
decompress
(
comp
[
32
:]))
bufs0
.
append
(
d0
.
decompress
(
comp
[
32
:]))
s0
=
''
.
join
(
bufs0
)
s0
=
b
''
.
join
(
bufs0
)
bufs1
.
append
(
d1
.
decompress
(
comp
[
32
:]))
bufs1
.
append
(
d1
.
decompress
(
comp
[
32
:]))
s1
=
''
.
join
(
bufs1
)
s1
=
b
''
.
join
(
bufs1
)
self
.
assertEqual
(
s0
,
s1
)
self
.
assertEqual
(
s0
,
s1
)
self
.
assertEqual
(
s0
,
data
)
self
.
assertEqual
(
s0
,
data
)
...
@@ -353,11 +353,10 @@ def genblock(seed, length, step=1024, generator=random):
...
@@ -353,11 +353,10 @@ def genblock(seed, length, step=1024, generator=random):
randint
=
generator
.
randint
randint
=
generator
.
randint
if
length
<
step
or
step
<
2
:
if
length
<
step
or
step
<
2
:
step
=
length
step
=
length
blocks
=
[]
blocks
=
bytes
()
for
i
in
range
(
0
,
length
,
step
):
for
i
in
range
(
0
,
length
,
step
):
blocks
.
append
(
''
.
join
([
chr
(
randint
(
0
,
255
))
blocks
+=
bytes
(
randint
(
0
,
255
)
for
x
in
range
(
step
))
for
x
in
range
(
step
)]))
return
blocks
return
''
.
join
(
blocks
)[:
length
]
...
@@ -370,7 +369,7 @@ def choose_lines(source, number, seed=None, generator=random):
...
@@ -370,7 +369,7 @@ def choose_lines(source, number, seed=None, generator=random):
HAMLET_SCENE
=
"""
HAMLET_SCENE
=
b
"""
LAERTES
LAERTES
O, fear me not.
O, fear me not.
...
@@ -444,4 +443,5 @@ def test_main():
...
@@ -444,4 +443,5 @@ def test_main():
)
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
test_main
()
unittest
.
main
()
# XXX
###test_main()
Modules/zlibmodule.c
Dosyayı görüntüle @
776152b6
...
@@ -96,12 +96,12 @@ newcompobject(PyTypeObject *type)
...
@@ -96,12 +96,12 @@ newcompobject(PyTypeObject *type)
if
(
self
==
NULL
)
if
(
self
==
NULL
)
return
NULL
;
return
NULL
;
self
->
is_initialised
=
0
;
self
->
is_initialised
=
0
;
self
->
unused_data
=
Py
String_FromString
(
""
);
self
->
unused_data
=
Py
Bytes_FromStringAndSize
(
""
,
0
);
if
(
self
->
unused_data
==
NULL
)
{
if
(
self
->
unused_data
==
NULL
)
{
Py_DECREF
(
self
);
Py_DECREF
(
self
);
return
NULL
;
return
NULL
;
}
}
self
->
unconsumed_tail
=
Py
String_FromString
(
""
);
self
->
unconsumed_tail
=
Py
Bytes_FromStringAndSize
(
""
,
0
);
if
(
self
->
unconsumed_tail
==
NULL
)
{
if
(
self
->
unconsumed_tail
==
NULL
)
{
Py_DECREF
(
self
);
Py_DECREF
(
self
);
return
NULL
;
return
NULL
;
...
@@ -174,8 +174,8 @@ PyZlib_compress(PyObject *self, PyObject *args)
...
@@ -174,8 +174,8 @@ PyZlib_compress(PyObject *self, PyObject *args)
err
=
deflateEnd
(
&
zst
);
err
=
deflateEnd
(
&
zst
);
if
(
err
==
Z_OK
)
if
(
err
==
Z_OK
)
ReturnVal
=
Py
String
_FromStringAndSize
((
char
*
)
output
,
ReturnVal
=
Py
Bytes
_FromStringAndSize
((
char
*
)
output
,
zst
.
total_out
);
zst
.
total_out
);
else
else
zlib_error
(
zst
,
err
,
"while finishing compression"
);
zlib_error
(
zst
,
err
,
"while finishing compression"
);
...
@@ -210,12 +210,12 @@ PyZlib_decompress(PyObject *self, PyObject *args)
...
@@ -210,12 +210,12 @@ PyZlib_decompress(PyObject *self, PyObject *args)
zst
.
avail_in
=
length
;
zst
.
avail_in
=
length
;
zst
.
avail_out
=
r_strlen
;
zst
.
avail_out
=
r_strlen
;
if
(
!
(
result_str
=
Py
String
_FromStringAndSize
(
NULL
,
r_strlen
)))
if
(
!
(
result_str
=
Py
Bytes
_FromStringAndSize
(
NULL
,
r_strlen
)))
return
NULL
;
return
NULL
;
zst
.
zalloc
=
(
alloc_func
)
NULL
;
zst
.
zalloc
=
(
alloc_func
)
NULL
;
zst
.
zfree
=
(
free_func
)
Z_NULL
;
zst
.
zfree
=
(
free_func
)
Z_NULL
;
zst
.
next_out
=
(
Byte
*
)
Py
String
_AS_STRING
(
result_str
);
zst
.
next_out
=
(
Byte
*
)
Py
Bytes
_AS_STRING
(
result_str
);
zst
.
next_in
=
(
Byte
*
)
input
;
zst
.
next_in
=
(
Byte
*
)
input
;
err
=
inflateInit2
(
&
zst
,
wsize
);
err
=
inflateInit2
(
&
zst
,
wsize
);
...
@@ -255,12 +255,12 @@ PyZlib_decompress(PyObject *self, PyObject *args)
...
@@ -255,12 +255,12 @@ PyZlib_decompress(PyObject *self, PyObject *args)
/* fall through */
/* fall through */
case
(
Z_OK
):
case
(
Z_OK
):
/* need more memory */
/* need more memory */
if
(
_PyString_Resize
(
&
result_str
,
r_strlen
<<
1
)
<
0
)
{
if
(
PyBytes_Resize
(
result_str
,
r_strlen
<<
1
)
<
0
)
{
inflateEnd
(
&
zst
);
inflateEnd
(
&
zst
);
goto
error
;
goto
error
;
}
}
zst
.
next_out
=
(
unsigned
char
*
)
PyString_AS_STRING
(
result_str
)
\
zst
.
next_out
=
+
r_strlen
;
(
unsigned
char
*
)
PyBytes_AS_STRING
(
result_str
)
+
r_strlen
;
zst
.
avail_out
=
r_strlen
;
zst
.
avail_out
=
r_strlen
;
r_strlen
=
r_strlen
<<
1
;
r_strlen
=
r_strlen
<<
1
;
break
;
break
;
...
@@ -277,7 +277,9 @@ PyZlib_decompress(PyObject *self, PyObject *args)
...
@@ -277,7 +277,9 @@ PyZlib_decompress(PyObject *self, PyObject *args)
goto
error
;
goto
error
;
}
}
_PyString_Resize
(
&
result_str
,
zst
.
total_out
);
if
(
PyBytes_Resize
(
result_str
,
zst
.
total_out
)
<
0
)
goto
error
;
return
result_str
;
return
result_str
;
error:
error:
...
@@ -399,7 +401,7 @@ PyZlib_objcompress(compobject *self, PyObject *args)
...
@@ -399,7 +401,7 @@ PyZlib_objcompress(compobject *self, PyObject *args)
if
(
!
PyArg_ParseTuple
(
args
,
"s#:compress"
,
&
input
,
&
inplen
))
if
(
!
PyArg_ParseTuple
(
args
,
"s#:compress"
,
&
input
,
&
inplen
))
return
NULL
;
return
NULL
;
if
(
!
(
RetVal
=
Py
String
_FromStringAndSize
(
NULL
,
length
)))
if
(
!
(
RetVal
=
Py
Bytes
_FromStringAndSize
(
NULL
,
length
)))
return
NULL
;
return
NULL
;
ENTER_ZLIB
ENTER_ZLIB
...
@@ -408,7 +410,7 @@ PyZlib_objcompress(compobject *self, PyObject *args)
...
@@ -408,7 +410,7 @@ PyZlib_objcompress(compobject *self, PyObject *args)
self
->
zst
.
avail_in
=
inplen
;
self
->
zst
.
avail_in
=
inplen
;
self
->
zst
.
next_in
=
input
;
self
->
zst
.
next_in
=
input
;
self
->
zst
.
avail_out
=
length
;
self
->
zst
.
avail_out
=
length
;
self
->
zst
.
next_out
=
(
unsigned
char
*
)
Py
String
_AS_STRING
(
RetVal
);
self
->
zst
.
next_out
=
(
unsigned
char
*
)
Py
Bytes
_AS_STRING
(
RetVal
);
Py_BEGIN_ALLOW_THREADS
Py_BEGIN_ALLOW_THREADS
err
=
deflate
(
&
(
self
->
zst
),
Z_NO_FLUSH
);
err
=
deflate
(
&
(
self
->
zst
),
Z_NO_FLUSH
);
...
@@ -417,10 +419,13 @@ PyZlib_objcompress(compobject *self, PyObject *args)
...
@@ -417,10 +419,13 @@ PyZlib_objcompress(compobject *self, PyObject *args)
/* while Z_OK and the output buffer is full, there might be more output,
/* while Z_OK and the output buffer is full, there might be more output,
so extend the output buffer and try again */
so extend the output buffer and try again */
while
(
err
==
Z_OK
&&
self
->
zst
.
avail_out
==
0
)
{
while
(
err
==
Z_OK
&&
self
->
zst
.
avail_out
==
0
)
{
if
(
_PyString_Resize
(
&
RetVal
,
length
<<
1
)
<
0
)
if
(
PyBytes_Resize
(
RetVal
,
length
<<
1
)
<
0
)
{
Py_DECREF
(
RetVal
);
RetVal
=
NULL
;
goto
error
;
goto
error
;
self
->
zst
.
next_out
=
(
unsigned
char
*
)
PyString_AS_STRING
(
RetVal
)
\
}
+
length
;
self
->
zst
.
next_out
=
(
unsigned
char
*
)
PyBytes_AS_STRING
(
RetVal
)
+
length
;
self
->
zst
.
avail_out
=
length
;
self
->
zst
.
avail_out
=
length
;
length
=
length
<<
1
;
length
=
length
<<
1
;
...
@@ -439,7 +444,10 @@ PyZlib_objcompress(compobject *self, PyObject *args)
...
@@ -439,7 +444,10 @@ PyZlib_objcompress(compobject *self, PyObject *args)
RetVal
=
NULL
;
RetVal
=
NULL
;
goto
error
;
goto
error
;
}
}
_PyString_Resize
(
&
RetVal
,
self
->
zst
.
total_out
-
start_total_out
);
if
(
PyBytes_Resize
(
RetVal
,
self
->
zst
.
total_out
-
start_total_out
)
<
0
)
{
Py_DECREF
(
RetVal
);
RetVal
=
NULL
;
}
error:
error:
LEAVE_ZLIB
LEAVE_ZLIB
...
@@ -478,7 +486,7 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
...
@@ -478,7 +486,7 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
/* limit amount of data allocated to max_length */
/* limit amount of data allocated to max_length */
if
(
max_length
&&
length
>
max_length
)
if
(
max_length
&&
length
>
max_length
)
length
=
max_length
;
length
=
max_length
;
if
(
!
(
RetVal
=
Py
String
_FromStringAndSize
(
NULL
,
length
)))
if
(
!
(
RetVal
=
Py
Bytes
_FromStringAndSize
(
NULL
,
length
)))
return
NULL
;
return
NULL
;
ENTER_ZLIB
ENTER_ZLIB
...
@@ -487,7 +495,7 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
...
@@ -487,7 +495,7 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
self
->
zst
.
avail_in
=
inplen
;
self
->
zst
.
avail_in
=
inplen
;
self
->
zst
.
next_in
=
input
;
self
->
zst
.
next_in
=
input
;
self
->
zst
.
avail_out
=
length
;
self
->
zst
.
avail_out
=
length
;
self
->
zst
.
next_out
=
(
unsigned
char
*
)
Py
String
_AS_STRING
(
RetVal
);
self
->
zst
.
next_out
=
(
unsigned
char
*
)
Py
Bytes
_AS_STRING
(
RetVal
);
Py_BEGIN_ALLOW_THREADS
Py_BEGIN_ALLOW_THREADS
err
=
inflate
(
&
(
self
->
zst
),
Z_SYNC_FLUSH
);
err
=
inflate
(
&
(
self
->
zst
),
Z_SYNC_FLUSH
);
...
@@ -509,10 +517,13 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
...
@@ -509,10 +517,13 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
if
(
max_length
&&
length
>
max_length
)
if
(
max_length
&&
length
>
max_length
)
length
=
max_length
;
length
=
max_length
;
if
(
_PyString_Resize
(
&
RetVal
,
length
)
<
0
)
if
(
PyBytes_Resize
(
RetVal
,
length
)
<
0
)
{
Py_DECREF
(
RetVal
);
RetVal
=
NULL
;
goto
error
;
goto
error
;
self
->
zst
.
next_out
=
(
unsigned
char
*
)
PyString_AS_STRING
(
RetVal
)
\
}
+
old_length
;
self
->
zst
.
next_out
=
(
unsigned
char
*
)
PyBytes_AS_STRING
(
RetVal
)
+
old_length
;
self
->
zst
.
avail_out
=
length
-
old_length
;
self
->
zst
.
avail_out
=
length
-
old_length
;
Py_BEGIN_ALLOW_THREADS
Py_BEGIN_ALLOW_THREADS
...
@@ -524,7 +535,7 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
...
@@ -524,7 +535,7 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
of specified size. Return the unconsumed tail in an attribute.*/
of specified size. Return the unconsumed tail in an attribute.*/
if
(
max_length
)
{
if
(
max_length
)
{
Py_DECREF
(
self
->
unconsumed_tail
);
Py_DECREF
(
self
->
unconsumed_tail
);
self
->
unconsumed_tail
=
Py
String
_FromStringAndSize
((
char
*
)
self
->
zst
.
next_in
,
self
->
unconsumed_tail
=
Py
Bytes
_FromStringAndSize
((
char
*
)
self
->
zst
.
next_in
,
self
->
zst
.
avail_in
);
self
->
zst
.
avail_in
);
if
(
!
self
->
unconsumed_tail
)
{
if
(
!
self
->
unconsumed_tail
)
{
Py_DECREF
(
RetVal
);
Py_DECREF
(
RetVal
);
...
@@ -541,7 +552,7 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
...
@@ -541,7 +552,7 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
*/
*/
if
(
err
==
Z_STREAM_END
)
{
if
(
err
==
Z_STREAM_END
)
{
Py_XDECREF
(
self
->
unused_data
);
/* Free original empty string */
Py_XDECREF
(
self
->
unused_data
);
/* Free original empty string */
self
->
unused_data
=
Py
String
_FromStringAndSize
(
self
->
unused_data
=
Py
Bytes
_FromStringAndSize
(
(
char
*
)
self
->
zst
.
next_in
,
self
->
zst
.
avail_in
);
(
char
*
)
self
->
zst
.
next_in
,
self
->
zst
.
avail_in
);
if
(
self
->
unused_data
==
NULL
)
{
if
(
self
->
unused_data
==
NULL
)
{
Py_DECREF
(
RetVal
);
Py_DECREF
(
RetVal
);
...
@@ -558,7 +569,10 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
...
@@ -558,7 +569,10 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
goto
error
;
goto
error
;
}
}
_PyString_Resize
(
&
RetVal
,
self
->
zst
.
total_out
-
start_total_out
);
if
(
PyBytes_Resize
(
RetVal
,
self
->
zst
.
total_out
-
start_total_out
)
<
0
)
{
Py_DECREF
(
RetVal
);
RetVal
=
NULL
;
}
error:
error:
LEAVE_ZLIB
LEAVE_ZLIB
...
@@ -588,10 +602,10 @@ PyZlib_flush(compobject *self, PyObject *args)
...
@@ -588,10 +602,10 @@ PyZlib_flush(compobject *self, PyObject *args)
/* Flushing with Z_NO_FLUSH is a no-op, so there's no point in
/* Flushing with Z_NO_FLUSH is a no-op, so there's no point in
doing any work at all; just return an empty string. */
doing any work at all; just return an empty string. */
if
(
flushmode
==
Z_NO_FLUSH
)
{
if
(
flushmode
==
Z_NO_FLUSH
)
{
return
Py
String
_FromStringAndSize
(
NULL
,
0
);
return
Py
Bytes
_FromStringAndSize
(
NULL
,
0
);
}
}
if
(
!
(
RetVal
=
Py
String
_FromStringAndSize
(
NULL
,
length
)))
if
(
!
(
RetVal
=
Py
Bytes
_FromStringAndSize
(
NULL
,
length
)))
return
NULL
;
return
NULL
;
ENTER_ZLIB
ENTER_ZLIB
...
@@ -599,7 +613,7 @@ PyZlib_flush(compobject *self, PyObject *args)
...
@@ -599,7 +613,7 @@ PyZlib_flush(compobject *self, PyObject *args)
start_total_out
=
self
->
zst
.
total_out
;
start_total_out
=
self
->
zst
.
total_out
;
self
->
zst
.
avail_in
=
0
;
self
->
zst
.
avail_in
=
0
;
self
->
zst
.
avail_out
=
length
;
self
->
zst
.
avail_out
=
length
;
self
->
zst
.
next_out
=
(
unsigned
char
*
)
Py
String
_AS_STRING
(
RetVal
);
self
->
zst
.
next_out
=
(
unsigned
char
*
)
Py
Bytes
_AS_STRING
(
RetVal
);
Py_BEGIN_ALLOW_THREADS
Py_BEGIN_ALLOW_THREADS
err
=
deflate
(
&
(
self
->
zst
),
flushmode
);
err
=
deflate
(
&
(
self
->
zst
),
flushmode
);
...
@@ -608,10 +622,13 @@ PyZlib_flush(compobject *self, PyObject *args)
...
@@ -608,10 +622,13 @@ PyZlib_flush(compobject *self, PyObject *args)
/* while Z_OK and the output buffer is full, there might be more output,
/* while Z_OK and the output buffer is full, there might be more output,
so extend the output buffer and try again */
so extend the output buffer and try again */
while
(
err
==
Z_OK
&&
self
->
zst
.
avail_out
==
0
)
{
while
(
err
==
Z_OK
&&
self
->
zst
.
avail_out
==
0
)
{
if
(
_PyString_Resize
(
&
RetVal
,
length
<<
1
)
<
0
)
if
(
PyBytes_Resize
(
RetVal
,
length
<<
1
)
<
0
)
{
Py_DECREF
(
RetVal
);
RetVal
=
NULL
;
goto
error
;
goto
error
;
self
->
zst
.
next_out
=
(
unsigned
char
*
)
PyString_AS_STRING
(
RetVal
)
\
}
+
length
;
self
->
zst
.
next_out
=
(
unsigned
char
*
)
PyBytes_AS_STRING
(
RetVal
)
+
length
;
self
->
zst
.
avail_out
=
length
;
self
->
zst
.
avail_out
=
length
;
length
=
length
<<
1
;
length
=
length
<<
1
;
...
@@ -645,7 +662,10 @@ PyZlib_flush(compobject *self, PyObject *args)
...
@@ -645,7 +662,10 @@ PyZlib_flush(compobject *self, PyObject *args)
goto
error
;
goto
error
;
}
}
_PyString_Resize
(
&
RetVal
,
self
->
zst
.
total_out
-
start_total_out
);
if
(
PyBytes_Resize
(
RetVal
,
self
->
zst
.
total_out
-
start_total_out
)
<
0
)
{
Py_DECREF
(
RetVal
);
RetVal
=
NULL
;
}
error:
error:
LEAVE_ZLIB
LEAVE_ZLIB
...
@@ -773,7 +793,7 @@ PyZlib_unflush(compobject *self, PyObject *args)
...
@@ -773,7 +793,7 @@ PyZlib_unflush(compobject *self, PyObject *args)
if
(
!
PyArg_ParseTuple
(
args
,
"|i:flush"
,
&
length
))
if
(
!
PyArg_ParseTuple
(
args
,
"|i:flush"
,
&
length
))
return
NULL
;
return
NULL
;
if
(
!
(
retval
=
Py
String
_FromStringAndSize
(
NULL
,
length
)))
if
(
!
(
retval
=
Py
Bytes
_FromStringAndSize
(
NULL
,
length
)))
return
NULL
;
return
NULL
;
...
@@ -781,7 +801,7 @@ PyZlib_unflush(compobject *self, PyObject *args)
...
@@ -781,7 +801,7 @@ PyZlib_unflush(compobject *self, PyObject *args)
start_total_out
=
self
->
zst
.
total_out
;
start_total_out
=
self
->
zst
.
total_out
;
self
->
zst
.
avail_out
=
length
;
self
->
zst
.
avail_out
=
length
;
self
->
zst
.
next_out
=
(
Byte
*
)
Py
String
_AS_STRING
(
retval
);
self
->
zst
.
next_out
=
(
Byte
*
)
Py
Bytes
_AS_STRING
(
retval
);
Py_BEGIN_ALLOW_THREADS
Py_BEGIN_ALLOW_THREADS
err
=
inflate
(
&
(
self
->
zst
),
Z_FINISH
);
err
=
inflate
(
&
(
self
->
zst
),
Z_FINISH
);
...
@@ -790,9 +810,12 @@ PyZlib_unflush(compobject *self, PyObject *args)
...
@@ -790,9 +810,12 @@ PyZlib_unflush(compobject *self, PyObject *args)
/* while Z_OK and the output buffer is full, there might be more output,
/* while Z_OK and the output buffer is full, there might be more output,
so extend the output buffer and try again */
so extend the output buffer and try again */
while
((
err
==
Z_OK
||
err
==
Z_BUF_ERROR
)
&&
self
->
zst
.
avail_out
==
0
)
{
while
((
err
==
Z_OK
||
err
==
Z_BUF_ERROR
)
&&
self
->
zst
.
avail_out
==
0
)
{
if
(
_PyString_Resize
(
&
retval
,
length
<<
1
)
<
0
)
if
(
PyBytes_Resize
(
retval
,
length
<<
1
)
<
0
)
{
Py_DECREF
(
retval
);
retval
=
NULL
;
goto
error
;
goto
error
;
self
->
zst
.
next_out
=
(
Byte
*
)
PyString_AS_STRING
(
retval
)
+
length
;
}
self
->
zst
.
next_out
=
(
Byte
*
)
PyBytes_AS_STRING
(
retval
)
+
length
;
self
->
zst
.
avail_out
=
length
;
self
->
zst
.
avail_out
=
length
;
length
=
length
<<
1
;
length
=
length
<<
1
;
...
@@ -814,7 +837,10 @@ PyZlib_unflush(compobject *self, PyObject *args)
...
@@ -814,7 +837,10 @@ PyZlib_unflush(compobject *self, PyObject *args)
goto
error
;
goto
error
;
}
}
}
}
_PyString_Resize
(
&
retval
,
self
->
zst
.
total_out
-
start_total_out
);
if
(
PyBytes_Resize
(
retval
,
self
->
zst
.
total_out
-
start_total_out
)
<
0
)
{
Py_DECREF
(
retval
);
retval
=
NULL
;
}
error:
error:
...
...
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