LCOV - code coverage report
Current view: top level - Modules/clinic - zlibmodule.c.h (source / functions) Hit Total Coverage
Test: CPython lcov report Lines: 262 308 85.1 %
Date: 2022-07-07 18:19:46 Functions: 16 16 100.0 %

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

Generated by: LCOV version 1.14