LCOV - code coverage report
Current view: top level - Modules/clinic - _bz2module.c.h (source / functions) Hit Total Coverage
Test: CPython 3.12 LCOV report [commit acb105a7c1f] Lines: 37 44 84.1 %
Date: 2022-07-20 13:12:14 Functions: 3 3 100.0 %
Branches: 21 32 65.6 %

           Branch data     Line data    Source code
       1                 :            : /*[clinic input]
       2                 :            : preserve
       3                 :            : [clinic start generated code]*/
       4                 :            : 
       5                 :            : PyDoc_STRVAR(_bz2_BZ2Compressor_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 _BZ2_BZ2COMPRESSOR_COMPRESS_METHODDEF    \
      17                 :            :     {"compress", (PyCFunction)_bz2_BZ2Compressor_compress, METH_O, _bz2_BZ2Compressor_compress__doc__},
      18                 :            : 
      19                 :            : static PyObject *
      20                 :            : _bz2_BZ2Compressor_compress_impl(BZ2Compressor *self, Py_buffer *data);
      21                 :            : 
      22                 :            : static PyObject *
      23                 :      32568 : _bz2_BZ2Compressor_compress(BZ2Compressor *self, PyObject *arg)
      24                 :            : {
      25                 :      32568 :     PyObject *return_value = NULL;
      26                 :      32568 :     Py_buffer data = {NULL, NULL};
      27                 :            : 
      28         [ -  + ]:      32568 :     if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) {
      29                 :          0 :         goto exit;
      30                 :            :     }
      31         [ -  + ]:      32568 :     if (!PyBuffer_IsContiguous(&data, 'C')) {
      32                 :          0 :         _PyArg_BadArgument("compress", "argument", "contiguous buffer", arg);
      33                 :          0 :         goto exit;
      34                 :            :     }
      35                 :      32568 :     return_value = _bz2_BZ2Compressor_compress_impl(self, &data);
      36                 :            : 
      37                 :      32568 : exit:
      38                 :            :     /* Cleanup for data */
      39         [ +  - ]:      32568 :     if (data.obj) {
      40                 :      32568 :        PyBuffer_Release(&data);
      41                 :            :     }
      42                 :            : 
      43                 :      32568 :     return return_value;
      44                 :            : }
      45                 :            : 
      46                 :            : PyDoc_STRVAR(_bz2_BZ2Compressor_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 _BZ2_BZ2COMPRESSOR_FLUSH_METHODDEF    \
      57                 :            :     {"flush", (PyCFunction)_bz2_BZ2Compressor_flush, METH_NOARGS, _bz2_BZ2Compressor_flush__doc__},
      58                 :            : 
      59                 :            : static PyObject *
      60                 :            : _bz2_BZ2Compressor_flush_impl(BZ2Compressor *self);
      61                 :            : 
      62                 :            : static PyObject *
      63                 :        328 : _bz2_BZ2Compressor_flush(BZ2Compressor *self, PyObject *Py_UNUSED(ignored))
      64                 :            : {
      65                 :        328 :     return _bz2_BZ2Compressor_flush_impl(self);
      66                 :            : }
      67                 :            : 
      68                 :            : PyDoc_STRVAR(_bz2_BZ2Decompressor_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 _BZ2_BZ2DECOMPRESSOR_DECOMPRESS_METHODDEF    \
      88                 :            :     {"decompress", _PyCFunction_CAST(_bz2_BZ2Decompressor_decompress), METH_FASTCALL|METH_KEYWORDS, _bz2_BZ2Decompressor_decompress__doc__},
      89                 :            : 
      90                 :            : static PyObject *
      91                 :            : _bz2_BZ2Decompressor_decompress_impl(BZ2Decompressor *self, Py_buffer *data,
      92                 :            :                                      Py_ssize_t max_length);
      93                 :            : 
      94                 :            : static PyObject *
      95                 :       4909 : _bz2_BZ2Decompressor_decompress(BZ2Decompressor *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
      96                 :            : {
      97                 :       4909 :     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         [ +  + ]:       4909 :     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
     102                 :       4909 :     Py_buffer data = {NULL, NULL};
     103                 :       4909 :     Py_ssize_t max_length = -1;
     104                 :            : 
     105   [ +  +  +  +  :       4909 :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
             +  -  -  + ]
     106         [ +  + ]:       4909 :     if (!args) {
     107                 :          1 :         goto exit;
     108                 :            :     }
     109         [ -  + ]:       4908 :     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
     110                 :          0 :         goto exit;
     111                 :            :     }
     112         [ -  + ]:       4908 :     if (!PyBuffer_IsContiguous(&data, 'C')) {
     113                 :          0 :         _PyArg_BadArgument("decompress", "argument 'data'", "contiguous buffer", args[0]);
     114                 :          0 :         goto exit;
     115                 :            :     }
     116         [ +  + ]:       4908 :     if (!noptargs) {
     117                 :        788 :         goto skip_optional_pos;
     118                 :            :     }
     119                 :            :     {
     120                 :       4120 :         Py_ssize_t ival = -1;
     121                 :       4120 :         PyObject *iobj = _PyNumber_Index(args[1]);
     122         [ +  - ]:       4120 :         if (iobj != NULL) {
     123                 :       4120 :             ival = PyLong_AsSsize_t(iobj);
     124                 :       4120 :             Py_DECREF(iobj);
     125                 :            :         }
     126   [ -  +  -  - ]:       4120 :         if (ival == -1 && PyErr_Occurred()) {
     127                 :          0 :             goto exit;
     128                 :            :         }
     129                 :       4120 :         max_length = ival;
     130                 :            :     }
     131                 :       4908 : skip_optional_pos:
     132                 :       4908 :     return_value = _bz2_BZ2Decompressor_decompress_impl(self, &data, max_length);
     133                 :            : 
     134                 :       4909 : exit:
     135                 :            :     /* Cleanup for data */
     136         [ +  + ]:       4909 :     if (data.obj) {
     137                 :       4908 :        PyBuffer_Release(&data);
     138                 :            :     }
     139                 :            : 
     140                 :       4909 :     return return_value;
     141                 :            : }
     142                 :            : /*[clinic end generated code: output=a1175204a414fe2a input=a9049054013a1b77]*/

Generated by: LCOV version 1.14