Mercurial > cpython-lru_cache-weakref
annotate Modules/zlib/example.c @ 87690:66c1c9f32567 default tip
Add use_weakref option to functools.lru_cache
The use_weakref option makes lru_cache create weak references to the function
arguments when creating the cache key, which prevents them from staying in the
memory forever even after all other references to them are gone.
This is a proof of concept for http://bugs.python.org/issue19859
| author | Radomir Dopieralski <devel@sheep.art.pl> |
|---|---|
| date | Tue, 03 Dec 2013 16:02:48 +0100 |
| parents | 224aa49f22f1 |
| children |
| rev | line source |
|---|---|
|
36186
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
1 /* example.c -- usage example of the zlib compression library |
|
86546
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
2 * Copyright (C) 1995-2006, 2011 Jean-loup Gailly. |
|
36186
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
3 * For conditions of distribution and use, see copyright notice in zlib.h |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
4 */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
5 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
6 /* @(#) $Id$ */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
7 |
|
63336
467019588fcc
Import files from zlib 1.2.5.
Martin v. Löwis <martin@v.loewis.de>
parents:
42622
diff
changeset
|
8 #include "zlib.h" |
|
36186
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
9 #include <stdio.h> |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
10 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
11 #ifdef STDC |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
12 # include <string.h> |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
13 # include <stdlib.h> |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
14 #endif |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
15 |
|
63336
467019588fcc
Import files from zlib 1.2.5.
Martin v. Löwis <martin@v.loewis.de>
parents:
42622
diff
changeset
|
16 #if defined(VMS) || defined(RISCOS) |
|
36186
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
17 # define TESTFILE "foo-gz" |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
18 #else |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
19 # define TESTFILE "foo.gz" |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
20 #endif |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
21 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
22 #define CHECK_ERR(err, msg) { \ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
23 if (err != Z_OK) { \ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
24 fprintf(stderr, "%s error: %d\n", msg, err); \ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
25 exit(1); \ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
26 } \ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
27 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
28 |
|
86546
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
29 z_const char hello[] = "hello, hello!"; |
|
36186
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
30 /* "hello world" would be more standard, but the repeated "hello" |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
31 * stresses the compression code better, sorry... |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
32 */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
33 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
34 const char dictionary[] = "hello"; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
35 uLong dictId; /* Adler32 value of the dictionary */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
36 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
37 void test_deflate OF((Byte *compr, uLong comprLen)); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
38 void test_inflate OF((Byte *compr, uLong comprLen, |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
39 Byte *uncompr, uLong uncomprLen)); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
40 void test_large_deflate OF((Byte *compr, uLong comprLen, |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
41 Byte *uncompr, uLong uncomprLen)); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
42 void test_large_inflate OF((Byte *compr, uLong comprLen, |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
43 Byte *uncompr, uLong uncomprLen)); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
44 void test_flush OF((Byte *compr, uLong *comprLen)); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
45 void test_sync OF((Byte *compr, uLong comprLen, |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
46 Byte *uncompr, uLong uncomprLen)); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
47 void test_dict_deflate OF((Byte *compr, uLong comprLen)); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
48 void test_dict_inflate OF((Byte *compr, uLong comprLen, |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
49 Byte *uncompr, uLong uncomprLen)); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
50 int main OF((int argc, char *argv[])); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
51 |
|
86546
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
52 |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
53 #ifdef Z_SOLO |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
54 |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
55 void *myalloc OF((void *, unsigned, unsigned)); |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
56 void myfree OF((void *, void *)); |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
57 |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
58 void *myalloc(q, n, m) |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
59 void *q; |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
60 unsigned n, m; |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
61 { |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
62 q = Z_NULL; |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
63 return calloc(n, m); |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
64 } |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
65 |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
66 void myfree(void *q, void *p) |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
67 { |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
68 q = Z_NULL; |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
69 free(p); |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
70 } |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
71 |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
72 static alloc_func zalloc = myalloc; |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
73 static free_func zfree = myfree; |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
74 |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
75 #else /* !Z_SOLO */ |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
76 |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
77 static alloc_func zalloc = (alloc_func)0; |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
78 static free_func zfree = (free_func)0; |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
79 |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
80 void test_compress OF((Byte *compr, uLong comprLen, |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
81 Byte *uncompr, uLong uncomprLen)); |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
82 void test_gzio OF((const char *fname, |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
83 Byte *uncompr, uLong uncomprLen)); |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
84 |
|
36186
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
85 /* =========================================================================== |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
86 * Test compress() and uncompress() |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
87 */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
88 void test_compress(compr, comprLen, uncompr, uncomprLen) |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
89 Byte *compr, *uncompr; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
90 uLong comprLen, uncomprLen; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
91 { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
92 int err; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
93 uLong len = (uLong)strlen(hello)+1; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
94 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
95 err = compress(compr, &comprLen, (const Bytef*)hello, len); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
96 CHECK_ERR(err, "compress"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
97 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
98 strcpy((char*)uncompr, "garbage"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
99 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
100 err = uncompress(uncompr, &uncomprLen, compr, comprLen); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
101 CHECK_ERR(err, "uncompress"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
102 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
103 if (strcmp((char*)uncompr, hello)) { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
104 fprintf(stderr, "bad uncompress\n"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
105 exit(1); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
106 } else { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
107 printf("uncompress(): %s\n", (char *)uncompr); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
108 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
109 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
110 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
111 /* =========================================================================== |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
112 * Test read/write of .gz files |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
113 */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
114 void test_gzio(fname, uncompr, uncomprLen) |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
115 const char *fname; /* compressed file name */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
116 Byte *uncompr; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
117 uLong uncomprLen; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
118 { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
119 #ifdef NO_GZCOMPRESS |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
120 fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
121 #else |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
122 int err; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
123 int len = (int)strlen(hello)+1; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
124 gzFile file; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
125 z_off_t pos; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
126 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
127 file = gzopen(fname, "wb"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
128 if (file == NULL) { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
129 fprintf(stderr, "gzopen error\n"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
130 exit(1); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
131 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
132 gzputc(file, 'h'); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
133 if (gzputs(file, "ello") != 4) { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
134 fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err)); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
135 exit(1); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
136 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
137 if (gzprintf(file, ", %s!", "hello") != 8) { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
138 fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err)); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
139 exit(1); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
140 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
141 gzseek(file, 1L, SEEK_CUR); /* add one zero byte */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
142 gzclose(file); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
143 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
144 file = gzopen(fname, "rb"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
145 if (file == NULL) { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
146 fprintf(stderr, "gzopen error\n"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
147 exit(1); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
148 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
149 strcpy((char*)uncompr, "garbage"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
150 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
151 if (gzread(file, uncompr, (unsigned)uncomprLen) != len) { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
152 fprintf(stderr, "gzread err: %s\n", gzerror(file, &err)); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
153 exit(1); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
154 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
155 if (strcmp((char*)uncompr, hello)) { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
156 fprintf(stderr, "bad gzread: %s\n", (char*)uncompr); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
157 exit(1); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
158 } else { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
159 printf("gzread(): %s\n", (char*)uncompr); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
160 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
161 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
162 pos = gzseek(file, -8L, SEEK_CUR); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
163 if (pos != 6 || gztell(file) != pos) { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
164 fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n", |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
165 (long)pos, (long)gztell(file)); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
166 exit(1); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
167 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
168 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
169 if (gzgetc(file) != ' ') { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
170 fprintf(stderr, "gzgetc error\n"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
171 exit(1); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
172 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
173 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
174 if (gzungetc(' ', file) != ' ') { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
175 fprintf(stderr, "gzungetc error\n"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
176 exit(1); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
177 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
178 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
179 gzgets(file, (char*)uncompr, (int)uncomprLen); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
180 if (strlen((char*)uncompr) != 7) { /* " hello!" */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
181 fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err)); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
182 exit(1); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
183 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
184 if (strcmp((char*)uncompr, hello + 6)) { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
185 fprintf(stderr, "bad gzgets after gzseek\n"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
186 exit(1); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
187 } else { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
188 printf("gzgets() after gzseek: %s\n", (char*)uncompr); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
189 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
190 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
191 gzclose(file); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
192 #endif |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
193 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
194 |
|
86546
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
195 #endif /* Z_SOLO */ |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
196 |
|
36186
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
197 /* =========================================================================== |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
198 * Test deflate() with small buffers |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
199 */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
200 void test_deflate(compr, comprLen) |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
201 Byte *compr; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
202 uLong comprLen; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
203 { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
204 z_stream c_stream; /* compression stream */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
205 int err; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
206 uLong len = (uLong)strlen(hello)+1; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
207 |
|
86546
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
208 c_stream.zalloc = zalloc; |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
209 c_stream.zfree = zfree; |
|
36186
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
210 c_stream.opaque = (voidpf)0; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
211 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
212 err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
213 CHECK_ERR(err, "deflateInit"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
214 |
|
86546
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
215 c_stream.next_in = (z_const unsigned char *)hello; |
|
36186
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
216 c_stream.next_out = compr; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
217 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
218 while (c_stream.total_in != len && c_stream.total_out < comprLen) { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
219 c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
220 err = deflate(&c_stream, Z_NO_FLUSH); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
221 CHECK_ERR(err, "deflate"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
222 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
223 /* Finish the stream, still forcing small buffers: */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
224 for (;;) { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
225 c_stream.avail_out = 1; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
226 err = deflate(&c_stream, Z_FINISH); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
227 if (err == Z_STREAM_END) break; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
228 CHECK_ERR(err, "deflate"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
229 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
230 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
231 err = deflateEnd(&c_stream); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
232 CHECK_ERR(err, "deflateEnd"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
233 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
234 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
235 /* =========================================================================== |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
236 * Test inflate() with small buffers |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
237 */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
238 void test_inflate(compr, comprLen, uncompr, uncomprLen) |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
239 Byte *compr, *uncompr; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
240 uLong comprLen, uncomprLen; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
241 { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
242 int err; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
243 z_stream d_stream; /* decompression stream */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
244 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
245 strcpy((char*)uncompr, "garbage"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
246 |
|
86546
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
247 d_stream.zalloc = zalloc; |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
248 d_stream.zfree = zfree; |
|
36186
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
249 d_stream.opaque = (voidpf)0; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
250 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
251 d_stream.next_in = compr; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
252 d_stream.avail_in = 0; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
253 d_stream.next_out = uncompr; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
254 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
255 err = inflateInit(&d_stream); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
256 CHECK_ERR(err, "inflateInit"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
257 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
258 while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
259 d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
260 err = inflate(&d_stream, Z_NO_FLUSH); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
261 if (err == Z_STREAM_END) break; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
262 CHECK_ERR(err, "inflate"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
263 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
264 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
265 err = inflateEnd(&d_stream); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
266 CHECK_ERR(err, "inflateEnd"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
267 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
268 if (strcmp((char*)uncompr, hello)) { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
269 fprintf(stderr, "bad inflate\n"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
270 exit(1); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
271 } else { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
272 printf("inflate(): %s\n", (char *)uncompr); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
273 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
274 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
275 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
276 /* =========================================================================== |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
277 * Test deflate() with large buffers and dynamic change of compression level |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
278 */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
279 void test_large_deflate(compr, comprLen, uncompr, uncomprLen) |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
280 Byte *compr, *uncompr; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
281 uLong comprLen, uncomprLen; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
282 { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
283 z_stream c_stream; /* compression stream */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
284 int err; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
285 |
|
86546
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
286 c_stream.zalloc = zalloc; |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
287 c_stream.zfree = zfree; |
|
36186
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
288 c_stream.opaque = (voidpf)0; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
289 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
290 err = deflateInit(&c_stream, Z_BEST_SPEED); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
291 CHECK_ERR(err, "deflateInit"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
292 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
293 c_stream.next_out = compr; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
294 c_stream.avail_out = (uInt)comprLen; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
295 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
296 /* At this point, uncompr is still mostly zeroes, so it should compress |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
297 * very well: |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
298 */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
299 c_stream.next_in = uncompr; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
300 c_stream.avail_in = (uInt)uncomprLen; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
301 err = deflate(&c_stream, Z_NO_FLUSH); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
302 CHECK_ERR(err, "deflate"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
303 if (c_stream.avail_in != 0) { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
304 fprintf(stderr, "deflate not greedy\n"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
305 exit(1); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
306 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
307 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
308 /* Feed in already compressed data and switch to no compression: */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
309 deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
310 c_stream.next_in = compr; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
311 c_stream.avail_in = (uInt)comprLen/2; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
312 err = deflate(&c_stream, Z_NO_FLUSH); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
313 CHECK_ERR(err, "deflate"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
314 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
315 /* Switch back to compressing mode: */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
316 deflateParams(&c_stream, Z_BEST_COMPRESSION, Z_FILTERED); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
317 c_stream.next_in = uncompr; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
318 c_stream.avail_in = (uInt)uncomprLen; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
319 err = deflate(&c_stream, Z_NO_FLUSH); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
320 CHECK_ERR(err, "deflate"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
321 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
322 err = deflate(&c_stream, Z_FINISH); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
323 if (err != Z_STREAM_END) { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
324 fprintf(stderr, "deflate should report Z_STREAM_END\n"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
325 exit(1); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
326 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
327 err = deflateEnd(&c_stream); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
328 CHECK_ERR(err, "deflateEnd"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
329 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
330 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
331 /* =========================================================================== |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
332 * Test inflate() with large buffers |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
333 */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
334 void test_large_inflate(compr, comprLen, uncompr, uncomprLen) |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
335 Byte *compr, *uncompr; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
336 uLong comprLen, uncomprLen; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
337 { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
338 int err; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
339 z_stream d_stream; /* decompression stream */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
340 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
341 strcpy((char*)uncompr, "garbage"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
342 |
|
86546
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
343 d_stream.zalloc = zalloc; |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
344 d_stream.zfree = zfree; |
|
36186
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
345 d_stream.opaque = (voidpf)0; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
346 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
347 d_stream.next_in = compr; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
348 d_stream.avail_in = (uInt)comprLen; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
349 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
350 err = inflateInit(&d_stream); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
351 CHECK_ERR(err, "inflateInit"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
352 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
353 for (;;) { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
354 d_stream.next_out = uncompr; /* discard the output */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
355 d_stream.avail_out = (uInt)uncomprLen; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
356 err = inflate(&d_stream, Z_NO_FLUSH); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
357 if (err == Z_STREAM_END) break; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
358 CHECK_ERR(err, "large inflate"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
359 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
360 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
361 err = inflateEnd(&d_stream); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
362 CHECK_ERR(err, "inflateEnd"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
363 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
364 if (d_stream.total_out != 2*uncomprLen + comprLen/2) { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
365 fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
366 exit(1); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
367 } else { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
368 printf("large_inflate(): OK\n"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
369 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
370 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
371 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
372 /* =========================================================================== |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
373 * Test deflate() with full flush |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
374 */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
375 void test_flush(compr, comprLen) |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
376 Byte *compr; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
377 uLong *comprLen; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
378 { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
379 z_stream c_stream; /* compression stream */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
380 int err; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
381 uInt len = (uInt)strlen(hello)+1; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
382 |
|
86546
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
383 c_stream.zalloc = zalloc; |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
384 c_stream.zfree = zfree; |
|
36186
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
385 c_stream.opaque = (voidpf)0; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
386 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
387 err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
388 CHECK_ERR(err, "deflateInit"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
389 |
|
86546
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
390 c_stream.next_in = (z_const unsigned char *)hello; |
|
36186
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
391 c_stream.next_out = compr; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
392 c_stream.avail_in = 3; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
393 c_stream.avail_out = (uInt)*comprLen; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
394 err = deflate(&c_stream, Z_FULL_FLUSH); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
395 CHECK_ERR(err, "deflate"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
396 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
397 compr[3]++; /* force an error in first compressed block */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
398 c_stream.avail_in = len - 3; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
399 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
400 err = deflate(&c_stream, Z_FINISH); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
401 if (err != Z_STREAM_END) { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
402 CHECK_ERR(err, "deflate"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
403 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
404 err = deflateEnd(&c_stream); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
405 CHECK_ERR(err, "deflateEnd"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
406 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
407 *comprLen = c_stream.total_out; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
408 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
409 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
410 /* =========================================================================== |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
411 * Test inflateSync() |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
412 */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
413 void test_sync(compr, comprLen, uncompr, uncomprLen) |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
414 Byte *compr, *uncompr; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
415 uLong comprLen, uncomprLen; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
416 { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
417 int err; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
418 z_stream d_stream; /* decompression stream */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
419 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
420 strcpy((char*)uncompr, "garbage"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
421 |
|
86546
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
422 d_stream.zalloc = zalloc; |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
423 d_stream.zfree = zfree; |
|
36186
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
424 d_stream.opaque = (voidpf)0; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
425 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
426 d_stream.next_in = compr; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
427 d_stream.avail_in = 2; /* just read the zlib header */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
428 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
429 err = inflateInit(&d_stream); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
430 CHECK_ERR(err, "inflateInit"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
431 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
432 d_stream.next_out = uncompr; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
433 d_stream.avail_out = (uInt)uncomprLen; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
434 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
435 inflate(&d_stream, Z_NO_FLUSH); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
436 CHECK_ERR(err, "inflate"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
437 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
438 d_stream.avail_in = (uInt)comprLen-2; /* read all compressed data */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
439 err = inflateSync(&d_stream); /* but skip the damaged part */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
440 CHECK_ERR(err, "inflateSync"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
441 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
442 err = inflate(&d_stream, Z_FINISH); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
443 if (err != Z_DATA_ERROR) { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
444 fprintf(stderr, "inflate should report DATA_ERROR\n"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
445 /* Because of incorrect adler32 */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
446 exit(1); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
447 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
448 err = inflateEnd(&d_stream); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
449 CHECK_ERR(err, "inflateEnd"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
450 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
451 printf("after inflateSync(): hel%s\n", (char *)uncompr); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
452 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
453 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
454 /* =========================================================================== |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
455 * Test deflate() with preset dictionary |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
456 */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
457 void test_dict_deflate(compr, comprLen) |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
458 Byte *compr; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
459 uLong comprLen; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
460 { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
461 z_stream c_stream; /* compression stream */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
462 int err; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
463 |
|
86546
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
464 c_stream.zalloc = zalloc; |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
465 c_stream.zfree = zfree; |
|
36186
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
466 c_stream.opaque = (voidpf)0; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
467 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
468 err = deflateInit(&c_stream, Z_BEST_COMPRESSION); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
469 CHECK_ERR(err, "deflateInit"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
470 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
471 err = deflateSetDictionary(&c_stream, |
|
86546
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
472 (const Bytef*)dictionary, (int)sizeof(dictionary)); |
|
36186
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
473 CHECK_ERR(err, "deflateSetDictionary"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
474 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
475 dictId = c_stream.adler; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
476 c_stream.next_out = compr; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
477 c_stream.avail_out = (uInt)comprLen; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
478 |
|
86546
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
479 c_stream.next_in = (z_const unsigned char *)hello; |
|
36186
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
480 c_stream.avail_in = (uInt)strlen(hello)+1; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
481 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
482 err = deflate(&c_stream, Z_FINISH); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
483 if (err != Z_STREAM_END) { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
484 fprintf(stderr, "deflate should report Z_STREAM_END\n"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
485 exit(1); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
486 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
487 err = deflateEnd(&c_stream); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
488 CHECK_ERR(err, "deflateEnd"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
489 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
490 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
491 /* =========================================================================== |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
492 * Test inflate() with a preset dictionary |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
493 */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
494 void test_dict_inflate(compr, comprLen, uncompr, uncomprLen) |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
495 Byte *compr, *uncompr; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
496 uLong comprLen, uncomprLen; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
497 { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
498 int err; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
499 z_stream d_stream; /* decompression stream */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
500 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
501 strcpy((char*)uncompr, "garbage"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
502 |
|
86546
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
503 d_stream.zalloc = zalloc; |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
504 d_stream.zfree = zfree; |
|
36186
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
505 d_stream.opaque = (voidpf)0; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
506 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
507 d_stream.next_in = compr; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
508 d_stream.avail_in = (uInt)comprLen; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
509 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
510 err = inflateInit(&d_stream); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
511 CHECK_ERR(err, "inflateInit"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
512 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
513 d_stream.next_out = uncompr; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
514 d_stream.avail_out = (uInt)uncomprLen; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
515 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
516 for (;;) { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
517 err = inflate(&d_stream, Z_NO_FLUSH); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
518 if (err == Z_STREAM_END) break; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
519 if (err == Z_NEED_DICT) { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
520 if (d_stream.adler != dictId) { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
521 fprintf(stderr, "unexpected dictionary"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
522 exit(1); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
523 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
524 err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary, |
|
86546
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
525 (int)sizeof(dictionary)); |
|
36186
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
526 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
527 CHECK_ERR(err, "inflate with dict"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
528 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
529 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
530 err = inflateEnd(&d_stream); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
531 CHECK_ERR(err, "inflateEnd"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
532 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
533 if (strcmp((char*)uncompr, hello)) { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
534 fprintf(stderr, "bad inflate with dict\n"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
535 exit(1); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
536 } else { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
537 printf("inflate with dictionary: %s\n", (char *)uncompr); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
538 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
539 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
540 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
541 /* =========================================================================== |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
542 * Usage: example [output.gz [input.gz]] |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
543 */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
544 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
545 int main(argc, argv) |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
546 int argc; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
547 char *argv[]; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
548 { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
549 Byte *compr, *uncompr; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
550 uLong comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
551 uLong uncomprLen = comprLen; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
552 static const char* myVersion = ZLIB_VERSION; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
553 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
554 if (zlibVersion()[0] != myVersion[0]) { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
555 fprintf(stderr, "incompatible zlib version\n"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
556 exit(1); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
557 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
558 } else if (strcmp(zlibVersion(), ZLIB_VERSION) != 0) { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
559 fprintf(stderr, "warning: different zlib version\n"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
560 } |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
561 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
562 printf("zlib version %s = 0x%04x, compile flags = 0x%lx\n", |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
563 ZLIB_VERSION, ZLIB_VERNUM, zlibCompileFlags()); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
564 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
565 compr = (Byte*)calloc((uInt)comprLen, 1); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
566 uncompr = (Byte*)calloc((uInt)uncomprLen, 1); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
567 /* compr and uncompr are cleared to avoid reading uninitialized |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
568 * data and to ensure that uncompr compresses well. |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
569 */ |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
570 if (compr == Z_NULL || uncompr == Z_NULL) { |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
571 printf("out of memory\n"); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
572 exit(1); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
573 } |
|
86546
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
574 |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
575 #ifdef Z_SOLO |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
576 argc = strlen(argv[0]); |
|
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
577 #else |
|
36186
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
578 test_compress(compr, comprLen, uncompr, uncomprLen); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
579 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
580 test_gzio((argc > 1 ? argv[1] : TESTFILE), |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
581 uncompr, uncomprLen); |
|
86546
224aa49f22f1
Issue #18527: Upgrade internal copy of zlib to 1.2.8
Christian Heimes <christian@cheimes.de>
parents:
63336
diff
changeset
|
582 #endif |
|
36186
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
583 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
584 test_deflate(compr, comprLen); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
585 test_inflate(compr, comprLen, uncompr, uncomprLen); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
586 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
587 test_large_deflate(compr, comprLen, uncompr, uncomprLen); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
588 test_large_inflate(compr, comprLen, uncompr, uncomprLen); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
589 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
590 test_flush(compr, &comprLen); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
591 test_sync(compr, comprLen, uncompr, uncomprLen); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
592 comprLen = uncomprLen; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
593 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
594 test_dict_deflate(compr, comprLen); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
595 test_dict_inflate(compr, comprLen, uncompr, uncomprLen); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
596 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
597 free(compr); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
598 free(uncompr); |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
599 |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
600 return 0; |
|
81fa47d2d477
Import zlib into Python tree.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
601 } |
