LCOV - code coverage report
Current view: top level - Modules/clinic - _lzmamodule.c.h (source / functions) Hit Total Coverage
Test: CPython 3.12 LCOV report [commit acb105a7c1f] Lines: 86 96 89.6 %
Date: 2022-07-20 13:12:14 Functions: 6 6 100.0 %
Branches: 58 76 76.3 %

           Branch data     Line data    Source code
       1                 :            : /*[clinic input]
       2                 :            : preserve
       3                 :            : [clinic start generated code]*/
       4                 :            : 
       5                 :            : PyDoc_STRVAR(_lzma_LZMACompressor_compress__doc__,
       6                 :            : "compress($self, data, /)\n"
       7                 :            : "--\n"
       8                 :            : "\n"
       9                 :            : "Provide data to the compressor object.\n"
      10                 :            : "\n"
      11                 :            : "Returns a chunk of compressed data if possible, or b\'\' otherwise.\n"
      12                 :            : "\n"
      13                 :            : "When you have finished providing data to the compressor, call the\n"
      14                 :            : "flush() method to finish the compression process.");
      15                 :            : 
      16                 :            : #define _LZMA_LZMACOMPRESSOR_COMPRESS_METHODDEF    \
      17                 :            :     {"compress", (PyCFunction)_lzma_LZMACompressor_compress, METH_O, _lzma_LZMACompressor_compress__doc__},
      18                 :            : 
      19                 :            : static PyObject *
      20                 :            : _lzma_LZMACompressor_compress_impl(Compressor *self, Py_buffer *data);
      21                 :            : 
      22                 :            : static PyObject *
      23                 :      33616 : _lzma_LZMACompressor_compress(Compressor *self, PyObject *arg)
      24                 :            : {
      25                 :      33616 :     PyObject *return_value = NULL;
      26                 :      33616 :     Py_buffer data = {NULL, NULL};
      27                 :            : 
      28         [ +  + ]:      33616 :     if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) {
      29                 :          1 :         goto exit;
      30                 :            :     }
      31         [ -  + ]:      33615 :     if (!PyBuffer_IsContiguous(&data, 'C')) {
      32                 :          0 :         _PyArg_BadArgument("compress", "argument", "contiguous buffer", arg);
      33                 :          0 :         goto exit;
      34                 :            :     }
      35                 :      33615 :     return_value = _lzma_LZMACompressor_compress_impl(self, &data);
      36                 :            : 
      37                 :      33616 : exit:
      38                 :            :     /* Cleanup for data */
      39         [ +  + ]:      33616 :     if (data.obj) {
      40                 :      33615 :        PyBuffer_Release(&data);
      41                 :            :     }
      42                 :            : 
      43                 :      33616 :     return return_value;
      44                 :            : }
      45                 :            : 
      46                 :            : PyDoc_STRVAR(_lzma_LZMACompressor_flush__doc__,
      47                 :            : "flush($self, /)\n"
      48                 :            : "--\n"
      49                 :            : "\n"
      50                 :            : "Finish the compression process.\n"
      51                 :            : "\n"
      52                 :            : "Returns the compressed data left in internal buffers.\n"
      53                 :            : "\n"
      54                 :            : "The compressor object may not be used after this method is called.");
      55                 :            : 
      56                 :            : #define _LZMA_LZMACOMPRESSOR_FLUSH_METHODDEF    \
      57                 :            :     {"flush", (PyCFunction)_lzma_LZMACompressor_flush, METH_NOARGS, _lzma_LZMACompressor_flush__doc__},
      58                 :            : 
      59                 :            : static PyObject *
      60                 :            : _lzma_LZMACompressor_flush_impl(Compressor *self);
      61                 :            : 
      62                 :            : static PyObject *
      63                 :        344 : _lzma_LZMACompressor_flush(Compressor *self, PyObject *Py_UNUSED(ignored))
      64                 :            : {
      65                 :        344 :     return _lzma_LZMACompressor_flush_impl(self);
      66                 :            : }
      67                 :            : 
      68                 :            : PyDoc_STRVAR(_lzma_LZMADecompressor_decompress__doc__,
      69                 :            : "decompress($self, /, data, max_length=-1)\n"
      70                 :            : "--\n"
      71                 :            : "\n"
      72                 :            : "Decompress *data*, returning uncompressed data as bytes.\n"
      73                 :            : "\n"
      74                 :            : "If *max_length* is nonnegative, returns at most *max_length* bytes of\n"
      75                 :            : "decompressed data. If this limit is reached and further output can be\n"
      76                 :            : "produced, *self.needs_input* will be set to ``False``. In this case, the next\n"
      77                 :            : "call to *decompress()* may provide *data* as b\'\' to obtain more of the output.\n"
      78                 :            : "\n"
      79                 :            : "If all of the input data was decompressed and returned (either because this\n"
      80                 :            : "was less than *max_length* bytes, or because *max_length* was negative),\n"
      81                 :            : "*self.needs_input* will be set to True.\n"
      82                 :            : "\n"
      83                 :            : "Attempting to decompress data after the end of stream is reached raises an\n"
      84                 :            : "EOFError.  Any data found after the end of the stream is ignored and saved in\n"
      85                 :            : "the unused_data attribute.");
      86                 :            : 
      87                 :            : #define _LZMA_LZMADECOMPRESSOR_DECOMPRESS_METHODDEF    \
      88                 :            :     {"decompress", _PyCFunction_CAST(_lzma_LZMADecompressor_decompress), METH_FASTCALL|METH_KEYWORDS, _lzma_LZMADecompressor_decompress__doc__},
      89                 :            : 
      90                 :            : static PyObject *
      91                 :            : _lzma_LZMADecompressor_decompress_impl(Decompressor *self, Py_buffer *data,
      92                 :            :                                        Py_ssize_t max_length);
      93                 :            : 
      94                 :            : static PyObject *
      95                 :       4258 : _lzma_LZMADecompressor_decompress(Decompressor *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
      96                 :            : {
      97                 :       4258 :     PyObject *return_value = NULL;
      98                 :            :     static const char * const _keywords[] = {"data", "max_length", NULL};
      99                 :            :     static _PyArg_Parser _parser = {NULL, _keywords, "decompress", 0};
     100                 :            :     PyObject *argsbuf[2];
     101         [ +  + ]:       4258 :     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
     102                 :       4258 :     Py_buffer data = {NULL, NULL};
     103                 :       4258 :     Py_ssize_t max_length = -1;
     104                 :            : 
     105   [ +  +  +  +  :       4258 :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
             +  -  -  + ]
     106         [ +  + ]:       4258 :     if (!args) {
     107                 :          1 :         goto exit;
     108                 :            :     }
     109         [ +  + ]:       4257 :     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
     110                 :          1 :         goto exit;
     111                 :            :     }
     112         [ -  + ]:       4256 :     if (!PyBuffer_IsContiguous(&data, 'C')) {
     113                 :          0 :         _PyArg_BadArgument("decompress", "argument 'data'", "contiguous buffer", args[0]);
     114                 :          0 :         goto exit;
     115                 :            :     }
     116         [ +  + ]:       4256 :     if (!noptargs) {
     117                 :       1344 :         goto skip_optional_pos;
     118                 :            :     }
     119                 :            :     {
     120                 :       2912 :         Py_ssize_t ival = -1;
     121                 :       2912 :         PyObject *iobj = _PyNumber_Index(args[1]);
     122         [ +  + ]:       2912 :         if (iobj != NULL) {
     123                 :       2911 :             ival = PyLong_AsSsize_t(iobj);
     124                 :       2911 :             Py_DECREF(iobj);
     125                 :            :         }
     126   [ +  +  +  + ]:       2912 :         if (ival == -1 && PyErr_Occurred()) {
     127                 :          1 :             goto exit;
     128                 :            :         }
     129                 :       2911 :         max_length = ival;
     130                 :            :     }
     131                 :       4255 : skip_optional_pos:
     132                 :       4255 :     return_value = _lzma_LZMADecompressor_decompress_impl(self, &data, max_length);
     133                 :            : 
     134                 :       4258 : exit:
     135                 :            :     /* Cleanup for data */
     136         [ +  + ]:       4258 :     if (data.obj) {
     137                 :       4256 :        PyBuffer_Release(&data);
     138                 :            :     }
     139                 :            : 
     140                 :       4258 :     return return_value;
     141                 :            : }
     142                 :            : 
     143                 :            : PyDoc_STRVAR(_lzma_LZMADecompressor___init____doc__,
     144                 :            : "LZMADecompressor(format=FORMAT_AUTO, memlimit=None, filters=None)\n"
     145                 :            : "--\n"
     146                 :            : "\n"
     147                 :            : "Create a decompressor object for decompressing data incrementally.\n"
     148                 :            : "\n"
     149                 :            : "  format\n"
     150                 :            : "    Specifies the container format of the input stream.  If this is\n"
     151                 :            : "    FORMAT_AUTO (the default), the decompressor will automatically detect\n"
     152                 :            : "    whether the input is FORMAT_XZ or FORMAT_ALONE.  Streams created with\n"
     153                 :            : "    FORMAT_RAW cannot be autodetected.\n"
     154                 :            : "  memlimit\n"
     155                 :            : "    Limit the amount of memory used by the decompressor.  This will cause\n"
     156                 :            : "    decompression to fail if the input cannot be decompressed within the\n"
     157                 :            : "    given limit.\n"
     158                 :            : "  filters\n"
     159                 :            : "    A custom filter chain.  This argument is required for FORMAT_RAW, and\n"
     160                 :            : "    not accepted with any other format.  When provided, this should be a\n"
     161                 :            : "    sequence of dicts, each indicating the ID and options for a single\n"
     162                 :            : "    filter.\n"
     163                 :            : "\n"
     164                 :            : "For one-shot decompression, use the decompress() function instead.");
     165                 :            : 
     166                 :            : static int
     167                 :            : _lzma_LZMADecompressor___init___impl(Decompressor *self, int format,
     168                 :            :                                      PyObject *memlimit, PyObject *filters);
     169                 :            : 
     170                 :            : static int
     171                 :       1091 : _lzma_LZMADecompressor___init__(PyObject *self, PyObject *args, PyObject *kwargs)
     172                 :            : {
     173                 :       1091 :     int return_value = -1;
     174                 :            :     static const char * const _keywords[] = {"format", "memlimit", "filters", NULL};
     175                 :            :     static _PyArg_Parser _parser = {NULL, _keywords, "LZMADecompressor", 0};
     176                 :            :     PyObject *argsbuf[3];
     177                 :            :     PyObject * const *fastargs;
     178                 :       1091 :     Py_ssize_t nargs = PyTuple_GET_SIZE(args);
     179         [ +  + ]:       1091 :     Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
     180                 :       1091 :     int format = FORMAT_AUTO;
     181                 :       1091 :     PyObject *memlimit = Py_None;
     182                 :       1091 :     PyObject *filters = Py_None;
     183                 :            : 
     184   [ +  +  +  -  :       1091 :     fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 3, 0, argsbuf);
             +  -  +  - ]
     185         [ -  + ]:       1091 :     if (!fastargs) {
     186                 :          0 :         goto exit;
     187                 :            :     }
     188         [ +  + ]:       1091 :     if (!noptargs) {
     189                 :         49 :         goto skip_optional_pos;
     190                 :            :     }
     191         [ +  + ]:       1042 :     if (fastargs[0]) {
     192                 :       1039 :         format = _PyLong_AsInt(fastargs[0]);
     193   [ +  +  +  - ]:       1039 :         if (format == -1 && PyErr_Occurred()) {
     194                 :          2 :             goto exit;
     195                 :            :         }
     196         [ +  + ]:       1037 :         if (!--noptargs) {
     197                 :          4 :             goto skip_optional_pos;
     198                 :            :         }
     199                 :            :     }
     200         [ +  + ]:       1036 :     if (fastargs[1]) {
     201                 :         79 :         memlimit = fastargs[1];
     202         [ +  + ]:         79 :         if (!--noptargs) {
     203                 :          5 :             goto skip_optional_pos;
     204                 :            :         }
     205                 :            :     }
     206                 :       1031 :     filters = fastargs[2];
     207                 :       1089 : skip_optional_pos:
     208                 :       1089 :     return_value = _lzma_LZMADecompressor___init___impl((Decompressor *)self, format, memlimit, filters);
     209                 :            : 
     210                 :       1091 : exit:
     211                 :       1091 :     return return_value;
     212                 :            : }
     213                 :            : 
     214                 :            : PyDoc_STRVAR(_lzma_is_check_supported__doc__,
     215                 :            : "is_check_supported($module, check_id, /)\n"
     216                 :            : "--\n"
     217                 :            : "\n"
     218                 :            : "Test whether the given integrity check is supported.\n"
     219                 :            : "\n"
     220                 :            : "Always returns True for CHECK_NONE and CHECK_CRC32.");
     221                 :            : 
     222                 :            : #define _LZMA_IS_CHECK_SUPPORTED_METHODDEF    \
     223                 :            :     {"is_check_supported", (PyCFunction)_lzma_is_check_supported, METH_O, _lzma_is_check_supported__doc__},
     224                 :            : 
     225                 :            : static PyObject *
     226                 :            : _lzma_is_check_supported_impl(PyObject *module, int check_id);
     227                 :            : 
     228                 :            : static PyObject *
     229                 :          4 : _lzma_is_check_supported(PyObject *module, PyObject *arg)
     230                 :            : {
     231                 :          4 :     PyObject *return_value = NULL;
     232                 :            :     int check_id;
     233                 :            : 
     234                 :          4 :     check_id = _PyLong_AsInt(arg);
     235   [ -  +  -  - ]:          4 :     if (check_id == -1 && PyErr_Occurred()) {
     236                 :          0 :         goto exit;
     237                 :            :     }
     238                 :          4 :     return_value = _lzma_is_check_supported_impl(module, check_id);
     239                 :            : 
     240                 :          4 : exit:
     241                 :          4 :     return return_value;
     242                 :            : }
     243                 :            : 
     244                 :            : PyDoc_STRVAR(_lzma__decode_filter_properties__doc__,
     245                 :            : "_decode_filter_properties($module, filter_id, encoded_props, /)\n"
     246                 :            : "--\n"
     247                 :            : "\n"
     248                 :            : "Return a bytes object encoding the options (properties) of the filter specified by *filter* (a dict).\n"
     249                 :            : "\n"
     250                 :            : "The result does not include the filter ID itself, only the options.");
     251                 :            : 
     252                 :            : #define _LZMA__DECODE_FILTER_PROPERTIES_METHODDEF    \
     253                 :            :     {"_decode_filter_properties", _PyCFunction_CAST(_lzma__decode_filter_properties), METH_FASTCALL, _lzma__decode_filter_properties__doc__},
     254                 :            : 
     255                 :            : static PyObject *
     256                 :            : _lzma__decode_filter_properties_impl(PyObject *module, lzma_vli filter_id,
     257                 :            :                                      Py_buffer *encoded_props);
     258                 :            : 
     259                 :            : static PyObject *
     260                 :        366 : _lzma__decode_filter_properties(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     261                 :            : {
     262                 :        366 :     PyObject *return_value = NULL;
     263                 :            :     lzma_vli filter_id;
     264                 :        366 :     Py_buffer encoded_props = {NULL, NULL};
     265                 :            : 
     266   [ +  -  -  +  :        366 :     if (!_PyArg_CheckPositional("_decode_filter_properties", nargs, 2, 2)) {
                   -  - ]
     267                 :          0 :         goto exit;
     268                 :            :     }
     269         [ -  + ]:        366 :     if (!lzma_vli_converter(args[0], &filter_id)) {
     270                 :          0 :         goto exit;
     271                 :            :     }
     272         [ +  + ]:        366 :     if (PyObject_GetBuffer(args[1], &encoded_props, PyBUF_SIMPLE) != 0) {
     273                 :          1 :         goto exit;
     274                 :            :     }
     275         [ -  + ]:        365 :     if (!PyBuffer_IsContiguous(&encoded_props, 'C')) {
     276                 :          0 :         _PyArg_BadArgument("_decode_filter_properties", "argument 2", "contiguous buffer", args[1]);
     277                 :          0 :         goto exit;
     278                 :            :     }
     279                 :        365 :     return_value = _lzma__decode_filter_properties_impl(module, filter_id, &encoded_props);
     280                 :            : 
     281                 :        366 : exit:
     282                 :            :     /* Cleanup for encoded_props */
     283         [ +  + ]:        366 :     if (encoded_props.obj) {
     284                 :        365 :        PyBuffer_Release(&encoded_props);
     285                 :            :     }
     286                 :            : 
     287                 :        366 :     return return_value;
     288                 :            : }
     289                 :            : /*[clinic end generated code: output=bce20bac13b0f252 input=a9049054013a1b77]*/

Generated by: LCOV version 1.14