1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4 
5 PyDoc_STRVAR(zlib_compress__doc__,
6 "compress($module, data, /, level=Z_DEFAULT_COMPRESSION)\n"
7 "--\n"
8 "\n"
9 "Returns a bytes object containing compressed data.\n"
10 "\n"
11 "  data\n"
12 "    Binary data to be compressed.\n"
13 "  level\n"
14 "    Compression level, in 0-9 or -1.");
15 
16 #define ZLIB_COMPRESS_METHODDEF    \
17     {"compress", (PyCFunction)(void(*)(void))zlib_compress, METH_FASTCALL|METH_KEYWORDS, zlib_compress__doc__},
18 
19 static PyObject *
20 zlib_compress_impl(PyObject *module, Py_buffer *data, int level);
21 
22 static PyObject *
zlib_compress(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)23 zlib_compress(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
24 {
25     PyObject *return_value = NULL;
26     static const char * const _keywords[] = {"", "level", NULL};
27     static _PyArg_Parser _parser = {NULL, _keywords, "compress", 0};
28     PyObject *argsbuf[2];
29     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
30     Py_buffer data = {NULL, NULL};
31     int level = Z_DEFAULT_COMPRESSION;
32 
33     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
34     if (!args) {
35         goto exit;
36     }
37     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
38         goto exit;
39     }
40     if (!PyBuffer_IsContiguous(&data, 'C')) {
41         _PyArg_BadArgument("compress", "argument 1", "contiguous buffer", args[0]);
42         goto exit;
43     }
44     if (!noptargs) {
45         goto skip_optional_pos;
46     }
47     if (PyFloat_Check(args[1])) {
48         PyErr_SetString(PyExc_TypeError,
49                         "integer argument expected, got float" );
50         goto exit;
51     }
52     level = _PyLong_AsInt(args[1]);
53     if (level == -1 && PyErr_Occurred()) {
54         goto exit;
55     }
56 skip_optional_pos:
57     return_value = zlib_compress_impl(module, &data, level);
58 
59 exit:
60     /* Cleanup for data */
61     if (data.obj) {
62        PyBuffer_Release(&data);
63     }
64 
65     return return_value;
66 }
67 
68 PyDoc_STRVAR(zlib_decompress__doc__,
69 "decompress($module, data, /, wbits=MAX_WBITS, bufsize=DEF_BUF_SIZE)\n"
70 "--\n"
71 "\n"
72 "Returns a bytes object containing the uncompressed data.\n"
73 "\n"
74 "  data\n"
75 "    Compressed data.\n"
76 "  wbits\n"
77 "    The window buffer size and container format.\n"
78 "  bufsize\n"
79 "    The initial output buffer size.");
80 
81 #define ZLIB_DECOMPRESS_METHODDEF    \
82     {"decompress", (PyCFunction)(void(*)(void))zlib_decompress, METH_FASTCALL|METH_KEYWORDS, zlib_decompress__doc__},
83 
84 static PyObject *
85 zlib_decompress_impl(PyObject *module, Py_buffer *data, int wbits,
86                      Py_ssize_t bufsize);
87 
88 static PyObject *
zlib_decompress(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)89 zlib_decompress(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
90 {
91     PyObject *return_value = NULL;
92     static const char * const _keywords[] = {"", "wbits", "bufsize", NULL};
93     static _PyArg_Parser _parser = {NULL, _keywords, "decompress", 0};
94     PyObject *argsbuf[3];
95     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
96     Py_buffer data = {NULL, NULL};
97     int wbits = MAX_WBITS;
98     Py_ssize_t bufsize = DEF_BUF_SIZE;
99 
100     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
101     if (!args) {
102         goto exit;
103     }
104     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
105         goto exit;
106     }
107     if (!PyBuffer_IsContiguous(&data, 'C')) {
108         _PyArg_BadArgument("decompress", "argument 1", "contiguous buffer", args[0]);
109         goto exit;
110     }
111     if (!noptargs) {
112         goto skip_optional_pos;
113     }
114     if (args[1]) {
115         if (PyFloat_Check(args[1])) {
116             PyErr_SetString(PyExc_TypeError,
117                             "integer argument expected, got float" );
118             goto exit;
119         }
120         wbits = _PyLong_AsInt(args[1]);
121         if (wbits == -1 && PyErr_Occurred()) {
122             goto exit;
123         }
124         if (!--noptargs) {
125             goto skip_optional_pos;
126         }
127     }
128     if (!ssize_t_converter(args[2], &bufsize)) {
129         goto exit;
130     }
131 skip_optional_pos:
132     return_value = zlib_decompress_impl(module, &data, wbits, bufsize);
133 
134 exit:
135     /* Cleanup for data */
136     if (data.obj) {
137        PyBuffer_Release(&data);
138     }
139 
140     return return_value;
141 }
142 
143 PyDoc_STRVAR(zlib_compressobj__doc__,
144 "compressobj($module, /, level=Z_DEFAULT_COMPRESSION, method=DEFLATED,\n"
145 "            wbits=MAX_WBITS, memLevel=DEF_MEM_LEVEL,\n"
146 "            strategy=Z_DEFAULT_STRATEGY, zdict=None)\n"
147 "--\n"
148 "\n"
149 "Return a compressor object.\n"
150 "\n"
151 "  level\n"
152 "    The compression level (an integer in the range 0-9 or -1; default is\n"
153 "    currently equivalent to 6).  Higher compression levels are slower,\n"
154 "    but produce smaller results.\n"
155 "  method\n"
156 "    The compression algorithm.  If given, this must be DEFLATED.\n"
157 "  wbits\n"
158 "    +9 to +15: The base-two logarithm of the window size.  Include a zlib\n"
159 "        container.\n"
160 "    -9 to -15: Generate a raw stream.\n"
161 "    +25 to +31: Include a gzip container.\n"
162 "  memLevel\n"
163 "    Controls the amount of memory used for internal compression state.\n"
164 "    Valid values range from 1 to 9.  Higher values result in higher memory\n"
165 "    usage, faster compression, and smaller output.\n"
166 "  strategy\n"
167 "    Used to tune the compression algorithm.  Possible values are\n"
168 "    Z_DEFAULT_STRATEGY, Z_FILTERED, and Z_HUFFMAN_ONLY.\n"
169 "  zdict\n"
170 "    The predefined compression dictionary - a sequence of bytes\n"
171 "    containing subsequences that are likely to occur in the input data.");
172 
173 #define ZLIB_COMPRESSOBJ_METHODDEF    \
174     {"compressobj", (PyCFunction)(void(*)(void))zlib_compressobj, METH_FASTCALL|METH_KEYWORDS, zlib_compressobj__doc__},
175 
176 static PyObject *
177 zlib_compressobj_impl(PyObject *module, int level, int method, int wbits,
178                       int memLevel, int strategy, Py_buffer *zdict);
179 
180 static PyObject *
zlib_compressobj(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)181 zlib_compressobj(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
182 {
183     PyObject *return_value = NULL;
184     static const char * const _keywords[] = {"level", "method", "wbits", "memLevel", "strategy", "zdict", NULL};
185     static _PyArg_Parser _parser = {NULL, _keywords, "compressobj", 0};
186     PyObject *argsbuf[6];
187     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
188     int level = Z_DEFAULT_COMPRESSION;
189     int method = DEFLATED;
190     int wbits = MAX_WBITS;
191     int memLevel = DEF_MEM_LEVEL;
192     int strategy = Z_DEFAULT_STRATEGY;
193     Py_buffer zdict = {NULL, NULL};
194 
195     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 6, 0, argsbuf);
196     if (!args) {
197         goto exit;
198     }
199     if (!noptargs) {
200         goto skip_optional_pos;
201     }
202     if (args[0]) {
203         if (PyFloat_Check(args[0])) {
204             PyErr_SetString(PyExc_TypeError,
205                             "integer argument expected, got float" );
206             goto exit;
207         }
208         level = _PyLong_AsInt(args[0]);
209         if (level == -1 && PyErr_Occurred()) {
210             goto exit;
211         }
212         if (!--noptargs) {
213             goto skip_optional_pos;
214         }
215     }
216     if (args[1]) {
217         if (PyFloat_Check(args[1])) {
218             PyErr_SetString(PyExc_TypeError,
219                             "integer argument expected, got float" );
220             goto exit;
221         }
222         method = _PyLong_AsInt(args[1]);
223         if (method == -1 && PyErr_Occurred()) {
224             goto exit;
225         }
226         if (!--noptargs) {
227             goto skip_optional_pos;
228         }
229     }
230     if (args[2]) {
231         if (PyFloat_Check(args[2])) {
232             PyErr_SetString(PyExc_TypeError,
233                             "integer argument expected, got float" );
234             goto exit;
235         }
236         wbits = _PyLong_AsInt(args[2]);
237         if (wbits == -1 && PyErr_Occurred()) {
238             goto exit;
239         }
240         if (!--noptargs) {
241             goto skip_optional_pos;
242         }
243     }
244     if (args[3]) {
245         if (PyFloat_Check(args[3])) {
246             PyErr_SetString(PyExc_TypeError,
247                             "integer argument expected, got float" );
248             goto exit;
249         }
250         memLevel = _PyLong_AsInt(args[3]);
251         if (memLevel == -1 && PyErr_Occurred()) {
252             goto exit;
253         }
254         if (!--noptargs) {
255             goto skip_optional_pos;
256         }
257     }
258     if (args[4]) {
259         if (PyFloat_Check(args[4])) {
260             PyErr_SetString(PyExc_TypeError,
261                             "integer argument expected, got float" );
262             goto exit;
263         }
264         strategy = _PyLong_AsInt(args[4]);
265         if (strategy == -1 && PyErr_Occurred()) {
266             goto exit;
267         }
268         if (!--noptargs) {
269             goto skip_optional_pos;
270         }
271     }
272     if (PyObject_GetBuffer(args[5], &zdict, PyBUF_SIMPLE) != 0) {
273         goto exit;
274     }
275     if (!PyBuffer_IsContiguous(&zdict, 'C')) {
276         _PyArg_BadArgument("compressobj", "argument 'zdict'", "contiguous buffer", args[5]);
277         goto exit;
278     }
279 skip_optional_pos:
280     return_value = zlib_compressobj_impl(module, level, method, wbits, memLevel, strategy, &zdict);
281 
282 exit:
283     /* Cleanup for zdict */
284     if (zdict.obj) {
285        PyBuffer_Release(&zdict);
286     }
287 
288     return return_value;
289 }
290 
291 PyDoc_STRVAR(zlib_decompressobj__doc__,
292 "decompressobj($module, /, wbits=MAX_WBITS, zdict=b\'\')\n"
293 "--\n"
294 "\n"
295 "Return a decompressor object.\n"
296 "\n"
297 "  wbits\n"
298 "    The window buffer size and container format.\n"
299 "  zdict\n"
300 "    The predefined compression dictionary.  This must be the same\n"
301 "    dictionary as used by the compressor that produced the input data.");
302 
303 #define ZLIB_DECOMPRESSOBJ_METHODDEF    \
304     {"decompressobj", (PyCFunction)(void(*)(void))zlib_decompressobj, METH_FASTCALL|METH_KEYWORDS, zlib_decompressobj__doc__},
305 
306 static PyObject *
307 zlib_decompressobj_impl(PyObject *module, int wbits, PyObject *zdict);
308 
309 static PyObject *
zlib_decompressobj(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)310 zlib_decompressobj(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
311 {
312     PyObject *return_value = NULL;
313     static const char * const _keywords[] = {"wbits", "zdict", NULL};
314     static _PyArg_Parser _parser = {NULL, _keywords, "decompressobj", 0};
315     PyObject *argsbuf[2];
316     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
317     int wbits = MAX_WBITS;
318     PyObject *zdict = NULL;
319 
320     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
321     if (!args) {
322         goto exit;
323     }
324     if (!noptargs) {
325         goto skip_optional_pos;
326     }
327     if (args[0]) {
328         if (PyFloat_Check(args[0])) {
329             PyErr_SetString(PyExc_TypeError,
330                             "integer argument expected, got float" );
331             goto exit;
332         }
333         wbits = _PyLong_AsInt(args[0]);
334         if (wbits == -1 && PyErr_Occurred()) {
335             goto exit;
336         }
337         if (!--noptargs) {
338             goto skip_optional_pos;
339         }
340     }
341     zdict = args[1];
342 skip_optional_pos:
343     return_value = zlib_decompressobj_impl(module, wbits, zdict);
344 
345 exit:
346     return return_value;
347 }
348 
349 PyDoc_STRVAR(zlib_Compress_compress__doc__,
350 "compress($self, data, /)\n"
351 "--\n"
352 "\n"
353 "Returns a bytes object containing compressed data.\n"
354 "\n"
355 "  data\n"
356 "    Binary data to be compressed.\n"
357 "\n"
358 "After calling this function, some of the input data may still\n"
359 "be stored in internal buffers for later processing.\n"
360 "Call the flush() method to clear these buffers.");
361 
362 #define ZLIB_COMPRESS_COMPRESS_METHODDEF    \
363     {"compress", (PyCFunction)zlib_Compress_compress, METH_O, zlib_Compress_compress__doc__},
364 
365 static PyObject *
366 zlib_Compress_compress_impl(compobject *self, Py_buffer *data);
367 
368 static PyObject *
zlib_Compress_compress(compobject * self,PyObject * arg)369 zlib_Compress_compress(compobject *self, PyObject *arg)
370 {
371     PyObject *return_value = NULL;
372     Py_buffer data = {NULL, NULL};
373 
374     if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) {
375         goto exit;
376     }
377     if (!PyBuffer_IsContiguous(&data, 'C')) {
378         _PyArg_BadArgument("compress", "argument", "contiguous buffer", arg);
379         goto exit;
380     }
381     return_value = zlib_Compress_compress_impl(self, &data);
382 
383 exit:
384     /* Cleanup for data */
385     if (data.obj) {
386        PyBuffer_Release(&data);
387     }
388 
389     return return_value;
390 }
391 
392 PyDoc_STRVAR(zlib_Decompress_decompress__doc__,
393 "decompress($self, data, /, max_length=0)\n"
394 "--\n"
395 "\n"
396 "Return a bytes object containing the decompressed version of the data.\n"
397 "\n"
398 "  data\n"
399 "    The binary data to decompress.\n"
400 "  max_length\n"
401 "    The maximum allowable length of the decompressed data.\n"
402 "    Unconsumed input data will be stored in\n"
403 "    the unconsumed_tail attribute.\n"
404 "\n"
405 "After calling this function, some of the input data may still be stored in\n"
406 "internal buffers for later processing.\n"
407 "Call the flush() method to clear these buffers.");
408 
409 #define ZLIB_DECOMPRESS_DECOMPRESS_METHODDEF    \
410     {"decompress", (PyCFunction)(void(*)(void))zlib_Decompress_decompress, METH_FASTCALL|METH_KEYWORDS, zlib_Decompress_decompress__doc__},
411 
412 static PyObject *
413 zlib_Decompress_decompress_impl(compobject *self, Py_buffer *data,
414                                 Py_ssize_t max_length);
415 
416 static PyObject *
zlib_Decompress_decompress(compobject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)417 zlib_Decompress_decompress(compobject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
418 {
419     PyObject *return_value = NULL;
420     static const char * const _keywords[] = {"", "max_length", NULL};
421     static _PyArg_Parser _parser = {NULL, _keywords, "decompress", 0};
422     PyObject *argsbuf[2];
423     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
424     Py_buffer data = {NULL, NULL};
425     Py_ssize_t max_length = 0;
426 
427     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
428     if (!args) {
429         goto exit;
430     }
431     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
432         goto exit;
433     }
434     if (!PyBuffer_IsContiguous(&data, 'C')) {
435         _PyArg_BadArgument("decompress", "argument 1", "contiguous buffer", args[0]);
436         goto exit;
437     }
438     if (!noptargs) {
439         goto skip_optional_pos;
440     }
441     if (!ssize_t_converter(args[1], &max_length)) {
442         goto exit;
443     }
444 skip_optional_pos:
445     return_value = zlib_Decompress_decompress_impl(self, &data, max_length);
446 
447 exit:
448     /* Cleanup for data */
449     if (data.obj) {
450        PyBuffer_Release(&data);
451     }
452 
453     return return_value;
454 }
455 
456 PyDoc_STRVAR(zlib_Compress_flush__doc__,
457 "flush($self, mode=zlib.Z_FINISH, /)\n"
458 "--\n"
459 "\n"
460 "Return a bytes object containing any remaining compressed data.\n"
461 "\n"
462 "  mode\n"
463 "    One of the constants Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH.\n"
464 "    If mode == Z_FINISH, the compressor object can no longer be\n"
465 "    used after calling the flush() method.  Otherwise, more data\n"
466 "    can still be compressed.");
467 
468 #define ZLIB_COMPRESS_FLUSH_METHODDEF    \
469     {"flush", (PyCFunction)(void(*)(void))zlib_Compress_flush, METH_FASTCALL, zlib_Compress_flush__doc__},
470 
471 static PyObject *
472 zlib_Compress_flush_impl(compobject *self, int mode);
473 
474 static PyObject *
zlib_Compress_flush(compobject * self,PyObject * const * args,Py_ssize_t nargs)475 zlib_Compress_flush(compobject *self, PyObject *const *args, Py_ssize_t nargs)
476 {
477     PyObject *return_value = NULL;
478     int mode = Z_FINISH;
479 
480     if (!_PyArg_CheckPositional("flush", nargs, 0, 1)) {
481         goto exit;
482     }
483     if (nargs < 1) {
484         goto skip_optional;
485     }
486     if (PyFloat_Check(args[0])) {
487         PyErr_SetString(PyExc_TypeError,
488                         "integer argument expected, got float" );
489         goto exit;
490     }
491     mode = _PyLong_AsInt(args[0]);
492     if (mode == -1 && PyErr_Occurred()) {
493         goto exit;
494     }
495 skip_optional:
496     return_value = zlib_Compress_flush_impl(self, mode);
497 
498 exit:
499     return return_value;
500 }
501 
502 #if defined(HAVE_ZLIB_COPY)
503 
504 PyDoc_STRVAR(zlib_Compress_copy__doc__,
505 "copy($self, /)\n"
506 "--\n"
507 "\n"
508 "Return a copy of the compression object.");
509 
510 #define ZLIB_COMPRESS_COPY_METHODDEF    \
511     {"copy", (PyCFunction)zlib_Compress_copy, METH_NOARGS, zlib_Compress_copy__doc__},
512 
513 static PyObject *
514 zlib_Compress_copy_impl(compobject *self);
515 
516 static PyObject *
zlib_Compress_copy(compobject * self,PyObject * Py_UNUSED (ignored))517 zlib_Compress_copy(compobject *self, PyObject *Py_UNUSED(ignored))
518 {
519     return zlib_Compress_copy_impl(self);
520 }
521 
522 #endif /* defined(HAVE_ZLIB_COPY) */
523 
524 #if defined(HAVE_ZLIB_COPY)
525 
526 PyDoc_STRVAR(zlib_Compress___copy____doc__,
527 "__copy__($self, /)\n"
528 "--\n"
529 "\n");
530 
531 #define ZLIB_COMPRESS___COPY___METHODDEF    \
532     {"__copy__", (PyCFunction)zlib_Compress___copy__, METH_NOARGS, zlib_Compress___copy____doc__},
533 
534 static PyObject *
535 zlib_Compress___copy___impl(compobject *self);
536 
537 static PyObject *
zlib_Compress___copy__(compobject * self,PyObject * Py_UNUSED (ignored))538 zlib_Compress___copy__(compobject *self, PyObject *Py_UNUSED(ignored))
539 {
540     return zlib_Compress___copy___impl(self);
541 }
542 
543 #endif /* defined(HAVE_ZLIB_COPY) */
544 
545 #if defined(HAVE_ZLIB_COPY)
546 
547 PyDoc_STRVAR(zlib_Compress___deepcopy____doc__,
548 "__deepcopy__($self, memo, /)\n"
549 "--\n"
550 "\n");
551 
552 #define ZLIB_COMPRESS___DEEPCOPY___METHODDEF    \
553     {"__deepcopy__", (PyCFunction)zlib_Compress___deepcopy__, METH_O, zlib_Compress___deepcopy____doc__},
554 
555 #endif /* defined(HAVE_ZLIB_COPY) */
556 
557 #if defined(HAVE_ZLIB_COPY)
558 
559 PyDoc_STRVAR(zlib_Decompress_copy__doc__,
560 "copy($self, /)\n"
561 "--\n"
562 "\n"
563 "Return a copy of the decompression object.");
564 
565 #define ZLIB_DECOMPRESS_COPY_METHODDEF    \
566     {"copy", (PyCFunction)zlib_Decompress_copy, METH_NOARGS, zlib_Decompress_copy__doc__},
567 
568 static PyObject *
569 zlib_Decompress_copy_impl(compobject *self);
570 
571 static PyObject *
zlib_Decompress_copy(compobject * self,PyObject * Py_UNUSED (ignored))572 zlib_Decompress_copy(compobject *self, PyObject *Py_UNUSED(ignored))
573 {
574     return zlib_Decompress_copy_impl(self);
575 }
576 
577 #endif /* defined(HAVE_ZLIB_COPY) */
578 
579 #if defined(HAVE_ZLIB_COPY)
580 
581 PyDoc_STRVAR(zlib_Decompress___copy____doc__,
582 "__copy__($self, /)\n"
583 "--\n"
584 "\n");
585 
586 #define ZLIB_DECOMPRESS___COPY___METHODDEF    \
587     {"__copy__", (PyCFunction)zlib_Decompress___copy__, METH_NOARGS, zlib_Decompress___copy____doc__},
588 
589 static PyObject *
590 zlib_Decompress___copy___impl(compobject *self);
591 
592 static PyObject *
zlib_Decompress___copy__(compobject * self,PyObject * Py_UNUSED (ignored))593 zlib_Decompress___copy__(compobject *self, PyObject *Py_UNUSED(ignored))
594 {
595     return zlib_Decompress___copy___impl(self);
596 }
597 
598 #endif /* defined(HAVE_ZLIB_COPY) */
599 
600 #if defined(HAVE_ZLIB_COPY)
601 
602 PyDoc_STRVAR(zlib_Decompress___deepcopy____doc__,
603 "__deepcopy__($self, memo, /)\n"
604 "--\n"
605 "\n");
606 
607 #define ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF    \
608     {"__deepcopy__", (PyCFunction)zlib_Decompress___deepcopy__, METH_O, zlib_Decompress___deepcopy____doc__},
609 
610 #endif /* defined(HAVE_ZLIB_COPY) */
611 
612 PyDoc_STRVAR(zlib_Decompress_flush__doc__,
613 "flush($self, length=zlib.DEF_BUF_SIZE, /)\n"
614 "--\n"
615 "\n"
616 "Return a bytes object containing any remaining decompressed data.\n"
617 "\n"
618 "  length\n"
619 "    the initial size of the output buffer.");
620 
621 #define ZLIB_DECOMPRESS_FLUSH_METHODDEF    \
622     {"flush", (PyCFunction)(void(*)(void))zlib_Decompress_flush, METH_FASTCALL, zlib_Decompress_flush__doc__},
623 
624 static PyObject *
625 zlib_Decompress_flush_impl(compobject *self, Py_ssize_t length);
626 
627 static PyObject *
zlib_Decompress_flush(compobject * self,PyObject * const * args,Py_ssize_t nargs)628 zlib_Decompress_flush(compobject *self, PyObject *const *args, Py_ssize_t nargs)
629 {
630     PyObject *return_value = NULL;
631     Py_ssize_t length = DEF_BUF_SIZE;
632 
633     if (!_PyArg_CheckPositional("flush", nargs, 0, 1)) {
634         goto exit;
635     }
636     if (nargs < 1) {
637         goto skip_optional;
638     }
639     if (!ssize_t_converter(args[0], &length)) {
640         goto exit;
641     }
642 skip_optional:
643     return_value = zlib_Decompress_flush_impl(self, length);
644 
645 exit:
646     return return_value;
647 }
648 
649 PyDoc_STRVAR(zlib_adler32__doc__,
650 "adler32($module, data, value=1, /)\n"
651 "--\n"
652 "\n"
653 "Compute an Adler-32 checksum of data.\n"
654 "\n"
655 "  value\n"
656 "    Starting value of the checksum.\n"
657 "\n"
658 "The returned checksum is an integer.");
659 
660 #define ZLIB_ADLER32_METHODDEF    \
661     {"adler32", (PyCFunction)(void(*)(void))zlib_adler32, METH_FASTCALL, zlib_adler32__doc__},
662 
663 static PyObject *
664 zlib_adler32_impl(PyObject *module, Py_buffer *data, unsigned int value);
665 
666 static PyObject *
zlib_adler32(PyObject * module,PyObject * const * args,Py_ssize_t nargs)667 zlib_adler32(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
668 {
669     PyObject *return_value = NULL;
670     Py_buffer data = {NULL, NULL};
671     unsigned int value = 1;
672 
673     if (!_PyArg_CheckPositional("adler32", nargs, 1, 2)) {
674         goto exit;
675     }
676     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
677         goto exit;
678     }
679     if (!PyBuffer_IsContiguous(&data, 'C')) {
680         _PyArg_BadArgument("adler32", "argument 1", "contiguous buffer", args[0]);
681         goto exit;
682     }
683     if (nargs < 2) {
684         goto skip_optional;
685     }
686     if (PyFloat_Check(args[1])) {
687         PyErr_SetString(PyExc_TypeError,
688                         "integer argument expected, got float" );
689         goto exit;
690     }
691     value = (unsigned int)PyLong_AsUnsignedLongMask(args[1]);
692     if (value == (unsigned int)-1 && PyErr_Occurred()) {
693         goto exit;
694     }
695 skip_optional:
696     return_value = zlib_adler32_impl(module, &data, value);
697 
698 exit:
699     /* Cleanup for data */
700     if (data.obj) {
701        PyBuffer_Release(&data);
702     }
703 
704     return return_value;
705 }
706 
707 PyDoc_STRVAR(zlib_crc32__doc__,
708 "crc32($module, data, value=0, /)\n"
709 "--\n"
710 "\n"
711 "Compute a CRC-32 checksum of data.\n"
712 "\n"
713 "  value\n"
714 "    Starting value of the checksum.\n"
715 "\n"
716 "The returned checksum is an integer.");
717 
718 #define ZLIB_CRC32_METHODDEF    \
719     {"crc32", (PyCFunction)(void(*)(void))zlib_crc32, METH_FASTCALL, zlib_crc32__doc__},
720 
721 static PyObject *
722 zlib_crc32_impl(PyObject *module, Py_buffer *data, unsigned int value);
723 
724 static PyObject *
zlib_crc32(PyObject * module,PyObject * const * args,Py_ssize_t nargs)725 zlib_crc32(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
726 {
727     PyObject *return_value = NULL;
728     Py_buffer data = {NULL, NULL};
729     unsigned int value = 0;
730 
731     if (!_PyArg_CheckPositional("crc32", nargs, 1, 2)) {
732         goto exit;
733     }
734     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
735         goto exit;
736     }
737     if (!PyBuffer_IsContiguous(&data, 'C')) {
738         _PyArg_BadArgument("crc32", "argument 1", "contiguous buffer", args[0]);
739         goto exit;
740     }
741     if (nargs < 2) {
742         goto skip_optional;
743     }
744     if (PyFloat_Check(args[1])) {
745         PyErr_SetString(PyExc_TypeError,
746                         "integer argument expected, got float" );
747         goto exit;
748     }
749     value = (unsigned int)PyLong_AsUnsignedLongMask(args[1]);
750     if (value == (unsigned int)-1 && PyErr_Occurred()) {
751         goto exit;
752     }
753 skip_optional:
754     return_value = zlib_crc32_impl(module, &data, value);
755 
756 exit:
757     /* Cleanup for data */
758     if (data.obj) {
759        PyBuffer_Release(&data);
760     }
761 
762     return return_value;
763 }
764 
765 #ifndef ZLIB_COMPRESS_COPY_METHODDEF
766     #define ZLIB_COMPRESS_COPY_METHODDEF
767 #endif /* !defined(ZLIB_COMPRESS_COPY_METHODDEF) */
768 
769 #ifndef ZLIB_COMPRESS___COPY___METHODDEF
770     #define ZLIB_COMPRESS___COPY___METHODDEF
771 #endif /* !defined(ZLIB_COMPRESS___COPY___METHODDEF) */
772 
773 #ifndef ZLIB_COMPRESS___DEEPCOPY___METHODDEF
774     #define ZLIB_COMPRESS___DEEPCOPY___METHODDEF
775 #endif /* !defined(ZLIB_COMPRESS___DEEPCOPY___METHODDEF) */
776 
777 #ifndef ZLIB_DECOMPRESS_COPY_METHODDEF
778     #define ZLIB_DECOMPRESS_COPY_METHODDEF
779 #endif /* !defined(ZLIB_DECOMPRESS_COPY_METHODDEF) */
780 
781 #ifndef ZLIB_DECOMPRESS___COPY___METHODDEF
782     #define ZLIB_DECOMPRESS___COPY___METHODDEF
783 #endif /* !defined(ZLIB_DECOMPRESS___COPY___METHODDEF) */
784 
785 #ifndef ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF
786     #define ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF
787 #endif /* !defined(ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF) */
788 /*[clinic end generated code: output=faae38ef96b88b16 input=a9049054013a1b77]*/
789