blob: c657bcb6449c5e4b3aa872007ff94a1e9ba07ef5 [file] [log] [blame]
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +02001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(zlib_compress__doc__,
Martin Panter1fe0d132016-02-10 10:06:36 +00006"compress($module, /, data, level=Z_DEFAULT_COMPRESSION)\n"
Larry Hastings2623c8c2014-02-08 22:15:29 -08007"--\n"
8"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +02009"Returns a bytes object containing compressed data.\n"
10"\n"
Martin Panter1fe0d132016-02-10 10:06:36 +000011" data\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020012" Binary data to be compressed.\n"
13" level\n"
Martin Panterb0cb42d2016-02-10 10:45:54 +000014" Compression level, in 0-9 or -1.");
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020015
16#define ZLIB_COMPRESS_METHODDEF \
Martin Panter1fe0d132016-02-10 10:06:36 +000017 {"compress", (PyCFunction)zlib_compress, METH_VARARGS|METH_KEYWORDS, zlib_compress__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020018
19static PyObject *
Martin Panter1fe0d132016-02-10 10:06:36 +000020zlib_compress_impl(PyModuleDef *module, Py_buffer *data, int level);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020021
22static PyObject *
Martin Panter1fe0d132016-02-10 10:06:36 +000023zlib_compress(PyModuleDef *module, PyObject *args, PyObject *kwargs)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020024{
25 PyObject *return_value = NULL;
Martin Panter1fe0d132016-02-10 10:06:36 +000026 static char *_keywords[] = {"data", "level", NULL};
27 Py_buffer data = {NULL, NULL};
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020028 int level = Z_DEFAULT_COMPRESSION;
29
Martin Panter1fe0d132016-02-10 10:06:36 +000030 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*|i:compress", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030031 &data, &level)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020032 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030033 }
Martin Panter1fe0d132016-02-10 10:06:36 +000034 return_value = zlib_compress_impl(module, &data, level);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020035
36exit:
Martin Panter1fe0d132016-02-10 10:06:36 +000037 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030038 if (data.obj) {
Martin Panter1fe0d132016-02-10 10:06:36 +000039 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030040 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020041
42 return return_value;
43}
44
45PyDoc_STRVAR(zlib_decompress__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -080046"decompress($module, data, wbits=MAX_WBITS, bufsize=DEF_BUF_SIZE, /)\n"
47"--\n"
48"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020049"Returns a bytes object containing the uncompressed data.\n"
50"\n"
51" data\n"
52" Compressed data.\n"
53" wbits\n"
Martin Panter0fdf41d2016-05-27 07:32:11 +000054" The window buffer size and container format.\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020055" bufsize\n"
56" The initial output buffer size.");
57
58#define ZLIB_DECOMPRESS_METHODDEF \
59 {"decompress", (PyCFunction)zlib_decompress, METH_VARARGS, zlib_decompress__doc__},
60
61static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -040062zlib_decompress_impl(PyModuleDef *module, Py_buffer *data, int wbits,
63 unsigned int bufsize);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020064
65static PyObject *
66zlib_decompress(PyModuleDef *module, PyObject *args)
67{
68 PyObject *return_value = NULL;
69 Py_buffer data = {NULL, NULL};
70 int wbits = MAX_WBITS;
71 unsigned int bufsize = DEF_BUF_SIZE;
72
Serhiy Storchaka247789c2015-04-24 00:40:51 +030073 if (!PyArg_ParseTuple(args, "y*|iO&:decompress",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030074 &data, &wbits, capped_uint_converter, &bufsize)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020075 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030076 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020077 return_value = zlib_decompress_impl(module, &data, wbits, bufsize);
78
79exit:
80 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030081 if (data.obj) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020082 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030083 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020084
85 return return_value;
86}
87
88PyDoc_STRVAR(zlib_compressobj__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -080089"compressobj($module, /, level=Z_DEFAULT_COMPRESSION, method=DEFLATED,\n"
90" wbits=MAX_WBITS, memLevel=DEF_MEM_LEVEL,\n"
91" strategy=Z_DEFAULT_STRATEGY, zdict=None)\n"
92"--\n"
93"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020094"Return a compressor object.\n"
95"\n"
96" level\n"
Martin Panter567d5132016-02-03 07:06:33 +000097" The compression level (an integer in the range 0-9 or -1; default is\n"
98" currently equivalent to 6). Higher compression levels are slower,\n"
99" but produce smaller results.\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200100" method\n"
101" The compression algorithm. If given, this must be DEFLATED.\n"
102" wbits\n"
Martin Panter0fdf41d2016-05-27 07:32:11 +0000103" +9 to +15: The base-two logarithm of the window size. Include a zlib\n"
104" container.\n"
105" -9 to -15: Generate a raw stream.\n"
106" +25 to +31: Include a gzip container.\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200107" memLevel\n"
108" Controls the amount of memory used for internal compression state.\n"
109" Valid values range from 1 to 9. Higher values result in higher memory\n"
110" usage, faster compression, and smaller output.\n"
111" strategy\n"
112" Used to tune the compression algorithm. Possible values are\n"
113" Z_DEFAULT_STRATEGY, Z_FILTERED, and Z_HUFFMAN_ONLY.\n"
114" zdict\n"
115" The predefined compression dictionary - a sequence of bytes\n"
116" containing subsequences that are likely to occur in the input data.");
117
118#define ZLIB_COMPRESSOBJ_METHODDEF \
119 {"compressobj", (PyCFunction)zlib_compressobj, METH_VARARGS|METH_KEYWORDS, zlib_compressobj__doc__},
120
121static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400122zlib_compressobj_impl(PyModuleDef *module, int level, int method, int wbits,
123 int memLevel, int strategy, Py_buffer *zdict);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200124
125static PyObject *
126zlib_compressobj(PyModuleDef *module, PyObject *args, PyObject *kwargs)
127{
128 PyObject *return_value = NULL;
129 static char *_keywords[] = {"level", "method", "wbits", "memLevel", "strategy", "zdict", NULL};
130 int level = Z_DEFAULT_COMPRESSION;
131 int method = DEFLATED;
132 int wbits = MAX_WBITS;
133 int memLevel = DEF_MEM_LEVEL;
134 int strategy = Z_DEFAULT_STRATEGY;
135 Py_buffer zdict = {NULL, NULL};
136
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300137 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|iiiiiy*:compressobj", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300138 &level, &method, &wbits, &memLevel, &strategy, &zdict)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200139 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300140 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200141 return_value = zlib_compressobj_impl(module, level, method, wbits, memLevel, strategy, &zdict);
142
143exit:
144 /* Cleanup for zdict */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300145 if (zdict.obj) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200146 PyBuffer_Release(&zdict);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300147 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200148
149 return return_value;
150}
151
152PyDoc_STRVAR(zlib_decompressobj__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800153"decompressobj($module, /, wbits=MAX_WBITS, zdict=b\'\')\n"
154"--\n"
155"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200156"Return a decompressor object.\n"
157"\n"
158" wbits\n"
Martin Panter0fdf41d2016-05-27 07:32:11 +0000159" The window buffer size and container format.\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200160" zdict\n"
161" The predefined compression dictionary. This must be the same\n"
162" dictionary as used by the compressor that produced the input data.");
163
164#define ZLIB_DECOMPRESSOBJ_METHODDEF \
165 {"decompressobj", (PyCFunction)zlib_decompressobj, METH_VARARGS|METH_KEYWORDS, zlib_decompressobj__doc__},
166
167static PyObject *
168zlib_decompressobj_impl(PyModuleDef *module, int wbits, PyObject *zdict);
169
170static PyObject *
171zlib_decompressobj(PyModuleDef *module, PyObject *args, PyObject *kwargs)
172{
173 PyObject *return_value = NULL;
174 static char *_keywords[] = {"wbits", "zdict", NULL};
175 int wbits = MAX_WBITS;
176 PyObject *zdict = NULL;
177
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300178 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|iO:decompressobj", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300179 &wbits, &zdict)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200180 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300181 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200182 return_value = zlib_decompressobj_impl(module, wbits, zdict);
183
184exit:
185 return return_value;
186}
187
188PyDoc_STRVAR(zlib_Compress_compress__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800189"compress($self, data, /)\n"
190"--\n"
191"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200192"Returns a bytes object containing compressed data.\n"
193"\n"
194" data\n"
195" Binary data to be compressed.\n"
196"\n"
197"After calling this function, some of the input data may still\n"
198"be stored in internal buffers for later processing.\n"
199"Call the flush() method to clear these buffers.");
200
201#define ZLIB_COMPRESS_COMPRESS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300202 {"compress", (PyCFunction)zlib_Compress_compress, METH_O, zlib_Compress_compress__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200203
204static PyObject *
205zlib_Compress_compress_impl(compobject *self, Py_buffer *data);
206
207static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300208zlib_Compress_compress(compobject *self, PyObject *arg)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200209{
210 PyObject *return_value = NULL;
211 Py_buffer data = {NULL, NULL};
212
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300213 if (!PyArg_Parse(arg, "y*:compress", &data)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200214 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300215 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200216 return_value = zlib_Compress_compress_impl(self, &data);
217
218exit:
219 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300220 if (data.obj) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200221 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300222 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200223
224 return return_value;
225}
226
227PyDoc_STRVAR(zlib_Decompress_decompress__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800228"decompress($self, data, max_length=0, /)\n"
229"--\n"
230"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200231"Return a bytes object containing the decompressed version of the data.\n"
232"\n"
233" data\n"
234" The binary data to decompress.\n"
235" max_length\n"
236" The maximum allowable length of the decompressed data.\n"
237" Unconsumed input data will be stored in\n"
238" the unconsumed_tail attribute.\n"
239"\n"
240"After calling this function, some of the input data may still be stored in\n"
241"internal buffers for later processing.\n"
242"Call the flush() method to clear these buffers.");
243
244#define ZLIB_DECOMPRESS_DECOMPRESS_METHODDEF \
245 {"decompress", (PyCFunction)zlib_Decompress_decompress, METH_VARARGS, zlib_Decompress_decompress__doc__},
246
247static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400248zlib_Decompress_decompress_impl(compobject *self, Py_buffer *data,
249 unsigned int max_length);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200250
251static PyObject *
252zlib_Decompress_decompress(compobject *self, PyObject *args)
253{
254 PyObject *return_value = NULL;
255 Py_buffer data = {NULL, NULL};
256 unsigned int max_length = 0;
257
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300258 if (!PyArg_ParseTuple(args, "y*|O&:decompress",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300259 &data, capped_uint_converter, &max_length)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200260 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300261 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200262 return_value = zlib_Decompress_decompress_impl(self, &data, max_length);
263
264exit:
265 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300266 if (data.obj) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200267 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300268 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200269
270 return return_value;
271}
272
273PyDoc_STRVAR(zlib_Compress_flush__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800274"flush($self, mode=zlib.Z_FINISH, /)\n"
275"--\n"
276"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200277"Return a bytes object containing any remaining compressed data.\n"
278"\n"
279" mode\n"
280" One of the constants Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH.\n"
281" If mode == Z_FINISH, the compressor object can no longer be\n"
282" used after calling the flush() method. Otherwise, more data\n"
283" can still be compressed.");
284
285#define ZLIB_COMPRESS_FLUSH_METHODDEF \
286 {"flush", (PyCFunction)zlib_Compress_flush, METH_VARARGS, zlib_Compress_flush__doc__},
287
288static PyObject *
289zlib_Compress_flush_impl(compobject *self, int mode);
290
291static PyObject *
292zlib_Compress_flush(compobject *self, PyObject *args)
293{
294 PyObject *return_value = NULL;
295 int mode = Z_FINISH;
296
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300297 if (!PyArg_ParseTuple(args, "|i:flush",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300298 &mode)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200299 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300300 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200301 return_value = zlib_Compress_flush_impl(self, mode);
302
303exit:
304 return return_value;
305}
306
Larry Hastings7726ac92014-01-31 22:03:12 -0800307#if defined(HAVE_ZLIB_COPY)
308
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200309PyDoc_STRVAR(zlib_Compress_copy__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800310"copy($self, /)\n"
311"--\n"
312"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200313"Return a copy of the compression object.");
314
315#define ZLIB_COMPRESS_COPY_METHODDEF \
316 {"copy", (PyCFunction)zlib_Compress_copy, METH_NOARGS, zlib_Compress_copy__doc__},
317
318static PyObject *
319zlib_Compress_copy_impl(compobject *self);
320
321static PyObject *
322zlib_Compress_copy(compobject *self, PyObject *Py_UNUSED(ignored))
323{
324 return zlib_Compress_copy_impl(self);
325}
326
Larry Hastings7726ac92014-01-31 22:03:12 -0800327#endif /* defined(HAVE_ZLIB_COPY) */
328
Larry Hastings7726ac92014-01-31 22:03:12 -0800329#if defined(HAVE_ZLIB_COPY)
330
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200331PyDoc_STRVAR(zlib_Decompress_copy__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800332"copy($self, /)\n"
333"--\n"
334"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200335"Return a copy of the decompression object.");
336
337#define ZLIB_DECOMPRESS_COPY_METHODDEF \
338 {"copy", (PyCFunction)zlib_Decompress_copy, METH_NOARGS, zlib_Decompress_copy__doc__},
339
340static PyObject *
341zlib_Decompress_copy_impl(compobject *self);
342
343static PyObject *
344zlib_Decompress_copy(compobject *self, PyObject *Py_UNUSED(ignored))
345{
346 return zlib_Decompress_copy_impl(self);
347}
348
Larry Hastings7726ac92014-01-31 22:03:12 -0800349#endif /* defined(HAVE_ZLIB_COPY) */
350
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200351PyDoc_STRVAR(zlib_Decompress_flush__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800352"flush($self, length=zlib.DEF_BUF_SIZE, /)\n"
353"--\n"
354"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200355"Return a bytes object containing any remaining decompressed data.\n"
356"\n"
357" length\n"
358" the initial size of the output buffer.");
359
360#define ZLIB_DECOMPRESS_FLUSH_METHODDEF \
361 {"flush", (PyCFunction)zlib_Decompress_flush, METH_VARARGS, zlib_Decompress_flush__doc__},
362
363static PyObject *
364zlib_Decompress_flush_impl(compobject *self, unsigned int length);
365
366static PyObject *
367zlib_Decompress_flush(compobject *self, PyObject *args)
368{
369 PyObject *return_value = NULL;
370 unsigned int length = DEF_BUF_SIZE;
371
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300372 if (!PyArg_ParseTuple(args, "|O&:flush",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300373 capped_uint_converter, &length)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200374 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300375 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200376 return_value = zlib_Decompress_flush_impl(self, length);
377
378exit:
379 return return_value;
380}
381
382PyDoc_STRVAR(zlib_adler32__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800383"adler32($module, data, value=1, /)\n"
384"--\n"
385"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200386"Compute an Adler-32 checksum of data.\n"
387"\n"
388" value\n"
389" Starting value of the checksum.\n"
390"\n"
391"The returned checksum is an integer.");
392
393#define ZLIB_ADLER32_METHODDEF \
394 {"adler32", (PyCFunction)zlib_adler32, METH_VARARGS, zlib_adler32__doc__},
395
396static PyObject *
397zlib_adler32_impl(PyModuleDef *module, Py_buffer *data, unsigned int value);
398
399static PyObject *
400zlib_adler32(PyModuleDef *module, PyObject *args)
401{
402 PyObject *return_value = NULL;
403 Py_buffer data = {NULL, NULL};
404 unsigned int value = 1;
405
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300406 if (!PyArg_ParseTuple(args, "y*|I:adler32",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300407 &data, &value)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200408 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300409 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200410 return_value = zlib_adler32_impl(module, &data, value);
411
412exit:
413 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300414 if (data.obj) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200415 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300416 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200417
418 return return_value;
419}
420
421PyDoc_STRVAR(zlib_crc32__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800422"crc32($module, data, value=0, /)\n"
423"--\n"
424"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200425"Compute a CRC-32 checksum of data.\n"
426"\n"
427" value\n"
428" Starting value of the checksum.\n"
429"\n"
430"The returned checksum is an integer.");
431
432#define ZLIB_CRC32_METHODDEF \
433 {"crc32", (PyCFunction)zlib_crc32, METH_VARARGS, zlib_crc32__doc__},
434
435static PyObject *
436zlib_crc32_impl(PyModuleDef *module, Py_buffer *data, unsigned int value);
437
438static PyObject *
439zlib_crc32(PyModuleDef *module, PyObject *args)
440{
441 PyObject *return_value = NULL;
442 Py_buffer data = {NULL, NULL};
443 unsigned int value = 0;
444
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300445 if (!PyArg_ParseTuple(args, "y*|I:crc32",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300446 &data, &value)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200447 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300448 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200449 return_value = zlib_crc32_impl(module, &data, value);
450
451exit:
452 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300453 if (data.obj) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200454 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300455 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200456
457 return return_value;
458}
Larry Hastings0759f842015-04-03 13:09:02 -0700459
460#ifndef ZLIB_COMPRESS_COPY_METHODDEF
461 #define ZLIB_COMPRESS_COPY_METHODDEF
462#endif /* !defined(ZLIB_COMPRESS_COPY_METHODDEF) */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300463/*[clinic end generated code: output=9bd8a093baa653b2 input=a9049054013a1b77]*/