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 5e6661bce9] Lines: 0 74 0.0 %
Date: 2023-03-20 08:15:36 Functions: 0 5 0.0 %
Branches: 0 68 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*[clinic input]
       2                 :            : preserve
       3                 :            : [clinic start generated code]*/
       4                 :            : 
       5                 :            : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
       6                 :            : #  include "pycore_gc.h"            // PyGC_Head
       7                 :            : #  include "pycore_runtime.h"       // _Py_ID()
       8                 :            : #endif
       9                 :            : 
      10                 :            : 
      11                 :            : PyDoc_STRVAR(_bz2_BZ2Compressor_compress__doc__,
      12                 :            : "compress($self, data, /)\n"
      13                 :            : "--\n"
      14                 :            : "\n"
      15                 :            : "Provide data to the compressor object.\n"
      16                 :            : "\n"
      17                 :            : "Returns a chunk of compressed data if possible, or b\'\' otherwise.\n"
      18                 :            : "\n"
      19                 :            : "When you have finished providing data to the compressor, call the\n"
      20                 :            : "flush() method to finish the compression process.");
      21                 :            : 
      22                 :            : #define _BZ2_BZ2COMPRESSOR_COMPRESS_METHODDEF    \
      23                 :            :     {"compress", (PyCFunction)_bz2_BZ2Compressor_compress, METH_O, _bz2_BZ2Compressor_compress__doc__},
      24                 :            : 
      25                 :            : static PyObject *
      26                 :            : _bz2_BZ2Compressor_compress_impl(BZ2Compressor *self, Py_buffer *data);
      27                 :            : 
      28                 :            : static PyObject *
      29                 :          0 : _bz2_BZ2Compressor_compress(BZ2Compressor *self, PyObject *arg)
      30                 :            : {
      31                 :          0 :     PyObject *return_value = NULL;
      32                 :          0 :     Py_buffer data = {NULL, NULL};
      33                 :            : 
      34         [ #  # ]:          0 :     if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) {
      35                 :          0 :         goto exit;
      36                 :            :     }
      37         [ #  # ]:          0 :     if (!PyBuffer_IsContiguous(&data, 'C')) {
      38                 :          0 :         _PyArg_BadArgument("compress", "argument", "contiguous buffer", arg);
      39                 :          0 :         goto exit;
      40                 :            :     }
      41                 :          0 :     return_value = _bz2_BZ2Compressor_compress_impl(self, &data);
      42                 :            : 
      43                 :          0 : exit:
      44                 :            :     /* Cleanup for data */
      45         [ #  # ]:          0 :     if (data.obj) {
      46                 :          0 :        PyBuffer_Release(&data);
      47                 :            :     }
      48                 :            : 
      49                 :          0 :     return return_value;
      50                 :            : }
      51                 :            : 
      52                 :            : PyDoc_STRVAR(_bz2_BZ2Compressor_flush__doc__,
      53                 :            : "flush($self, /)\n"
      54                 :            : "--\n"
      55                 :            : "\n"
      56                 :            : "Finish the compression process.\n"
      57                 :            : "\n"
      58                 :            : "Returns the compressed data left in internal buffers.\n"
      59                 :            : "\n"
      60                 :            : "The compressor object may not be used after this method is called.");
      61                 :            : 
      62                 :            : #define _BZ2_BZ2COMPRESSOR_FLUSH_METHODDEF    \
      63                 :            :     {"flush", (PyCFunction)_bz2_BZ2Compressor_flush, METH_NOARGS, _bz2_BZ2Compressor_flush__doc__},
      64                 :            : 
      65                 :            : static PyObject *
      66                 :            : _bz2_BZ2Compressor_flush_impl(BZ2Compressor *self);
      67                 :            : 
      68                 :            : static PyObject *
      69                 :          0 : _bz2_BZ2Compressor_flush(BZ2Compressor *self, PyObject *Py_UNUSED(ignored))
      70                 :            : {
      71                 :          0 :     return _bz2_BZ2Compressor_flush_impl(self);
      72                 :            : }
      73                 :            : 
      74                 :            : PyDoc_STRVAR(_bz2_BZ2Compressor__doc__,
      75                 :            : "BZ2Compressor(compresslevel=9, /)\n"
      76                 :            : "--\n"
      77                 :            : "\n"
      78                 :            : "Create a compressor object for compressing data incrementally.\n"
      79                 :            : "\n"
      80                 :            : "  compresslevel\n"
      81                 :            : "    Compression level, as a number between 1 and 9.\n"
      82                 :            : "\n"
      83                 :            : "For one-shot compression, use the compress() function instead.");
      84                 :            : 
      85                 :            : static PyObject *
      86                 :            : _bz2_BZ2Compressor_impl(PyTypeObject *type, int compresslevel);
      87                 :            : 
      88                 :            : static PyObject *
      89                 :          0 : _bz2_BZ2Compressor(PyTypeObject *type, PyObject *args, PyObject *kwargs)
      90                 :            : {
      91                 :          0 :     PyObject *return_value = NULL;
      92                 :          0 :     PyTypeObject *base_tp = clinic_state()->bz2_compressor_type;
      93                 :          0 :     int compresslevel = 9;
      94                 :            : 
      95   [ #  #  #  #  :          0 :     if ((type == base_tp || type->tp_init == base_tp->tp_init) &&
                   #  # ]
      96         [ #  # ]:          0 :         !_PyArg_NoKeywords("BZ2Compressor", kwargs)) {
      97                 :          0 :         goto exit;
      98                 :            :     }
      99   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("BZ2Compressor", PyTuple_GET_SIZE(args), 0, 1)) {
                   #  # ]
     100                 :          0 :         goto exit;
     101                 :            :     }
     102         [ #  # ]:          0 :     if (PyTuple_GET_SIZE(args) < 1) {
     103                 :          0 :         goto skip_optional;
     104                 :            :     }
     105                 :          0 :     compresslevel = _PyLong_AsInt(PyTuple_GET_ITEM(args, 0));
     106   [ #  #  #  # ]:          0 :     if (compresslevel == -1 && PyErr_Occurred()) {
     107                 :          0 :         goto exit;
     108                 :            :     }
     109                 :          0 : skip_optional:
     110                 :          0 :     return_value = _bz2_BZ2Compressor_impl(type, compresslevel);
     111                 :            : 
     112                 :          0 : exit:
     113                 :          0 :     return return_value;
     114                 :            : }
     115                 :            : 
     116                 :            : PyDoc_STRVAR(_bz2_BZ2Decompressor_decompress__doc__,
     117                 :            : "decompress($self, /, data, max_length=-1)\n"
     118                 :            : "--\n"
     119                 :            : "\n"
     120                 :            : "Decompress *data*, returning uncompressed data as bytes.\n"
     121                 :            : "\n"
     122                 :            : "If *max_length* is nonnegative, returns at most *max_length* bytes of\n"
     123                 :            : "decompressed data. If this limit is reached and further output can be\n"
     124                 :            : "produced, *self.needs_input* will be set to ``False``. In this case, the next\n"
     125                 :            : "call to *decompress()* may provide *data* as b\'\' to obtain more of the output.\n"
     126                 :            : "\n"
     127                 :            : "If all of the input data was decompressed and returned (either because this\n"
     128                 :            : "was less than *max_length* bytes, or because *max_length* was negative),\n"
     129                 :            : "*self.needs_input* will be set to True.\n"
     130                 :            : "\n"
     131                 :            : "Attempting to decompress data after the end of stream is reached raises an\n"
     132                 :            : "EOFError.  Any data found after the end of the stream is ignored and saved in\n"
     133                 :            : "the unused_data attribute.");
     134                 :            : 
     135                 :            : #define _BZ2_BZ2DECOMPRESSOR_DECOMPRESS_METHODDEF    \
     136                 :            :     {"decompress", _PyCFunction_CAST(_bz2_BZ2Decompressor_decompress), METH_FASTCALL|METH_KEYWORDS, _bz2_BZ2Decompressor_decompress__doc__},
     137                 :            : 
     138                 :            : static PyObject *
     139                 :            : _bz2_BZ2Decompressor_decompress_impl(BZ2Decompressor *self, Py_buffer *data,
     140                 :            :                                      Py_ssize_t max_length);
     141                 :            : 
     142                 :            : static PyObject *
     143                 :          0 : _bz2_BZ2Decompressor_decompress(BZ2Decompressor *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     144                 :            : {
     145                 :          0 :     PyObject *return_value = NULL;
     146                 :            :     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     147                 :            : 
     148                 :            :     #define NUM_KEYWORDS 2
     149                 :            :     static struct {
     150                 :            :         PyGC_Head _this_is_not_used;
     151                 :            :         PyObject_VAR_HEAD
     152                 :            :         PyObject *ob_item[NUM_KEYWORDS];
     153                 :            :     } _kwtuple = {
     154                 :            :         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     155                 :            :         .ob_item = { &_Py_ID(data), &_Py_ID(max_length), },
     156                 :            :     };
     157                 :            :     #undef NUM_KEYWORDS
     158                 :            :     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     159                 :            : 
     160                 :            :     #else  // !Py_BUILD_CORE
     161                 :            :     #  define KWTUPLE NULL
     162                 :            :     #endif  // !Py_BUILD_CORE
     163                 :            : 
     164                 :            :     static const char * const _keywords[] = {"data", "max_length", NULL};
     165                 :            :     static _PyArg_Parser _parser = {
     166                 :            :         .keywords = _keywords,
     167                 :            :         .fname = "decompress",
     168                 :            :         .kwtuple = KWTUPLE,
     169                 :            :     };
     170                 :            :     #undef KWTUPLE
     171                 :            :     PyObject *argsbuf[2];
     172         [ #  # ]:          0 :     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
     173                 :          0 :     Py_buffer data = {NULL, NULL};
     174                 :          0 :     Py_ssize_t max_length = -1;
     175                 :            : 
     176   [ #  #  #  #  :          0 :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
             #  #  #  # ]
     177         [ #  # ]:          0 :     if (!args) {
     178                 :          0 :         goto exit;
     179                 :            :     }
     180         [ #  # ]:          0 :     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
     181                 :          0 :         goto exit;
     182                 :            :     }
     183         [ #  # ]:          0 :     if (!PyBuffer_IsContiguous(&data, 'C')) {
     184                 :          0 :         _PyArg_BadArgument("decompress", "argument 'data'", "contiguous buffer", args[0]);
     185                 :          0 :         goto exit;
     186                 :            :     }
     187         [ #  # ]:          0 :     if (!noptargs) {
     188                 :          0 :         goto skip_optional_pos;
     189                 :            :     }
     190                 :            :     {
     191                 :          0 :         Py_ssize_t ival = -1;
     192                 :          0 :         PyObject *iobj = _PyNumber_Index(args[1]);
     193         [ #  # ]:          0 :         if (iobj != NULL) {
     194                 :          0 :             ival = PyLong_AsSsize_t(iobj);
     195                 :          0 :             Py_DECREF(iobj);
     196                 :            :         }
     197   [ #  #  #  # ]:          0 :         if (ival == -1 && PyErr_Occurred()) {
     198                 :          0 :             goto exit;
     199                 :            :         }
     200                 :          0 :         max_length = ival;
     201                 :            :     }
     202                 :          0 : skip_optional_pos:
     203                 :          0 :     return_value = _bz2_BZ2Decompressor_decompress_impl(self, &data, max_length);
     204                 :            : 
     205                 :          0 : exit:
     206                 :            :     /* Cleanup for data */
     207         [ #  # ]:          0 :     if (data.obj) {
     208                 :          0 :        PyBuffer_Release(&data);
     209                 :            :     }
     210                 :            : 
     211                 :          0 :     return return_value;
     212                 :            : }
     213                 :            : 
     214                 :            : PyDoc_STRVAR(_bz2_BZ2Decompressor__doc__,
     215                 :            : "BZ2Decompressor()\n"
     216                 :            : "--\n"
     217                 :            : "\n"
     218                 :            : "Create a decompressor object for decompressing data incrementally.\n"
     219                 :            : "\n"
     220                 :            : "For one-shot decompression, use the decompress() function instead.");
     221                 :            : 
     222                 :            : static PyObject *
     223                 :            : _bz2_BZ2Decompressor_impl(PyTypeObject *type);
     224                 :            : 
     225                 :            : static PyObject *
     226                 :          0 : _bz2_BZ2Decompressor(PyTypeObject *type, PyObject *args, PyObject *kwargs)
     227                 :            : {
     228                 :          0 :     PyObject *return_value = NULL;
     229                 :          0 :     PyTypeObject *base_tp = clinic_state()->bz2_decompressor_type;
     230                 :            : 
     231   [ #  #  #  #  :          0 :     if ((type == base_tp || type->tp_init == base_tp->tp_init) &&
                   #  # ]
     232         [ #  # ]:          0 :         !_PyArg_NoPositional("BZ2Decompressor", args)) {
     233                 :          0 :         goto exit;
     234                 :            :     }
     235   [ #  #  #  #  :          0 :     if ((type == base_tp || type->tp_init == base_tp->tp_init) &&
                   #  # ]
     236         [ #  # ]:          0 :         !_PyArg_NoKeywords("BZ2Decompressor", kwargs)) {
     237                 :          0 :         goto exit;
     238                 :            :     }
     239                 :          0 :     return_value = _bz2_BZ2Decompressor_impl(type);
     240                 :            : 
     241                 :          0 : exit:
     242                 :          0 :     return return_value;
     243                 :            : }
     244                 :            : /*[clinic end generated code: output=805400e4805098ec input=a9049054013a1b77]*/

Generated by: LCOV version 1.14