LCOV - code coverage report
Current view: top level - Modules/_sqlite/clinic - blob.c.h (source / functions) Hit Total Coverage
Test: CPython 3.12 LCOV report [commit 5e6661bce9] Lines: 0 60 0.0 %
Date: 2023-03-20 08:15:36 Functions: 0 7 0.0 %
Branches: 0 40 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(blob_close__doc__,
      12                 :            : "close($self, /)\n"
      13                 :            : "--\n"
      14                 :            : "\n"
      15                 :            : "Close the blob.");
      16                 :            : 
      17                 :            : #define BLOB_CLOSE_METHODDEF    \
      18                 :            :     {"close", (PyCFunction)blob_close, METH_NOARGS, blob_close__doc__},
      19                 :            : 
      20                 :            : static PyObject *
      21                 :            : blob_close_impl(pysqlite_Blob *self);
      22                 :            : 
      23                 :            : static PyObject *
      24                 :          0 : blob_close(pysqlite_Blob *self, PyObject *Py_UNUSED(ignored))
      25                 :            : {
      26                 :          0 :     return blob_close_impl(self);
      27                 :            : }
      28                 :            : 
      29                 :            : PyDoc_STRVAR(blob_read__doc__,
      30                 :            : "read($self, length=-1, /)\n"
      31                 :            : "--\n"
      32                 :            : "\n"
      33                 :            : "Read data at the current offset position.\n"
      34                 :            : "\n"
      35                 :            : "  length\n"
      36                 :            : "    Read length in bytes.\n"
      37                 :            : "\n"
      38                 :            : "If the end of the blob is reached, the data up to end of file will be returned.\n"
      39                 :            : "When length is not specified, or is negative, Blob.read() will read until the\n"
      40                 :            : "end of the blob.");
      41                 :            : 
      42                 :            : #define BLOB_READ_METHODDEF    \
      43                 :            :     {"read", _PyCFunction_CAST(blob_read), METH_FASTCALL, blob_read__doc__},
      44                 :            : 
      45                 :            : static PyObject *
      46                 :            : blob_read_impl(pysqlite_Blob *self, int length);
      47                 :            : 
      48                 :            : static PyObject *
      49                 :          0 : blob_read(pysqlite_Blob *self, PyObject *const *args, Py_ssize_t nargs)
      50                 :            : {
      51                 :          0 :     PyObject *return_value = NULL;
      52                 :          0 :     int length = -1;
      53                 :            : 
      54   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("read", nargs, 0, 1)) {
                   #  # ]
      55                 :          0 :         goto exit;
      56                 :            :     }
      57         [ #  # ]:          0 :     if (nargs < 1) {
      58                 :          0 :         goto skip_optional;
      59                 :            :     }
      60                 :          0 :     length = _PyLong_AsInt(args[0]);
      61   [ #  #  #  # ]:          0 :     if (length == -1 && PyErr_Occurred()) {
      62                 :          0 :         goto exit;
      63                 :            :     }
      64                 :          0 : skip_optional:
      65                 :          0 :     return_value = blob_read_impl(self, length);
      66                 :            : 
      67                 :          0 : exit:
      68                 :          0 :     return return_value;
      69                 :            : }
      70                 :            : 
      71                 :            : PyDoc_STRVAR(blob_write__doc__,
      72                 :            : "write($self, data, /)\n"
      73                 :            : "--\n"
      74                 :            : "\n"
      75                 :            : "Write data at the current offset.\n"
      76                 :            : "\n"
      77                 :            : "This function cannot change the blob length.  Writing beyond the end of the\n"
      78                 :            : "blob will result in an exception being raised.");
      79                 :            : 
      80                 :            : #define BLOB_WRITE_METHODDEF    \
      81                 :            :     {"write", (PyCFunction)blob_write, METH_O, blob_write__doc__},
      82                 :            : 
      83                 :            : static PyObject *
      84                 :            : blob_write_impl(pysqlite_Blob *self, Py_buffer *data);
      85                 :            : 
      86                 :            : static PyObject *
      87                 :          0 : blob_write(pysqlite_Blob *self, PyObject *arg)
      88                 :            : {
      89                 :          0 :     PyObject *return_value = NULL;
      90                 :          0 :     Py_buffer data = {NULL, NULL};
      91                 :            : 
      92         [ #  # ]:          0 :     if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) {
      93                 :          0 :         goto exit;
      94                 :            :     }
      95         [ #  # ]:          0 :     if (!PyBuffer_IsContiguous(&data, 'C')) {
      96                 :          0 :         _PyArg_BadArgument("write", "argument", "contiguous buffer", arg);
      97                 :          0 :         goto exit;
      98                 :            :     }
      99                 :          0 :     return_value = blob_write_impl(self, &data);
     100                 :            : 
     101                 :          0 : exit:
     102                 :            :     /* Cleanup for data */
     103         [ #  # ]:          0 :     if (data.obj) {
     104                 :          0 :        PyBuffer_Release(&data);
     105                 :            :     }
     106                 :            : 
     107                 :          0 :     return return_value;
     108                 :            : }
     109                 :            : 
     110                 :            : PyDoc_STRVAR(blob_seek__doc__,
     111                 :            : "seek($self, offset, origin=0, /)\n"
     112                 :            : "--\n"
     113                 :            : "\n"
     114                 :            : "Set the current access position to offset.\n"
     115                 :            : "\n"
     116                 :            : "The origin argument defaults to os.SEEK_SET (absolute blob positioning).\n"
     117                 :            : "Other values for origin are os.SEEK_CUR (seek relative to the current position)\n"
     118                 :            : "and os.SEEK_END (seek relative to the blob\'s end).");
     119                 :            : 
     120                 :            : #define BLOB_SEEK_METHODDEF    \
     121                 :            :     {"seek", _PyCFunction_CAST(blob_seek), METH_FASTCALL, blob_seek__doc__},
     122                 :            : 
     123                 :            : static PyObject *
     124                 :            : blob_seek_impl(pysqlite_Blob *self, int offset, int origin);
     125                 :            : 
     126                 :            : static PyObject *
     127                 :          0 : blob_seek(pysqlite_Blob *self, PyObject *const *args, Py_ssize_t nargs)
     128                 :            : {
     129                 :          0 :     PyObject *return_value = NULL;
     130                 :            :     int offset;
     131                 :          0 :     int origin = 0;
     132                 :            : 
     133   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) {
                   #  # ]
     134                 :          0 :         goto exit;
     135                 :            :     }
     136                 :          0 :     offset = _PyLong_AsInt(args[0]);
     137   [ #  #  #  # ]:          0 :     if (offset == -1 && PyErr_Occurred()) {
     138                 :          0 :         goto exit;
     139                 :            :     }
     140         [ #  # ]:          0 :     if (nargs < 2) {
     141                 :          0 :         goto skip_optional;
     142                 :            :     }
     143                 :          0 :     origin = _PyLong_AsInt(args[1]);
     144   [ #  #  #  # ]:          0 :     if (origin == -1 && PyErr_Occurred()) {
     145                 :          0 :         goto exit;
     146                 :            :     }
     147                 :          0 : skip_optional:
     148                 :          0 :     return_value = blob_seek_impl(self, offset, origin);
     149                 :            : 
     150                 :          0 : exit:
     151                 :          0 :     return return_value;
     152                 :            : }
     153                 :            : 
     154                 :            : PyDoc_STRVAR(blob_tell__doc__,
     155                 :            : "tell($self, /)\n"
     156                 :            : "--\n"
     157                 :            : "\n"
     158                 :            : "Return the current access position for the blob.");
     159                 :            : 
     160                 :            : #define BLOB_TELL_METHODDEF    \
     161                 :            :     {"tell", (PyCFunction)blob_tell, METH_NOARGS, blob_tell__doc__},
     162                 :            : 
     163                 :            : static PyObject *
     164                 :            : blob_tell_impl(pysqlite_Blob *self);
     165                 :            : 
     166                 :            : static PyObject *
     167                 :          0 : blob_tell(pysqlite_Blob *self, PyObject *Py_UNUSED(ignored))
     168                 :            : {
     169                 :          0 :     return blob_tell_impl(self);
     170                 :            : }
     171                 :            : 
     172                 :            : PyDoc_STRVAR(blob_enter__doc__,
     173                 :            : "__enter__($self, /)\n"
     174                 :            : "--\n"
     175                 :            : "\n"
     176                 :            : "Blob context manager enter.");
     177                 :            : 
     178                 :            : #define BLOB_ENTER_METHODDEF    \
     179                 :            :     {"__enter__", (PyCFunction)blob_enter, METH_NOARGS, blob_enter__doc__},
     180                 :            : 
     181                 :            : static PyObject *
     182                 :            : blob_enter_impl(pysqlite_Blob *self);
     183                 :            : 
     184                 :            : static PyObject *
     185                 :          0 : blob_enter(pysqlite_Blob *self, PyObject *Py_UNUSED(ignored))
     186                 :            : {
     187                 :          0 :     return blob_enter_impl(self);
     188                 :            : }
     189                 :            : 
     190                 :            : PyDoc_STRVAR(blob_exit__doc__,
     191                 :            : "__exit__($self, type, val, tb, /)\n"
     192                 :            : "--\n"
     193                 :            : "\n"
     194                 :            : "Blob context manager exit.");
     195                 :            : 
     196                 :            : #define BLOB_EXIT_METHODDEF    \
     197                 :            :     {"__exit__", _PyCFunction_CAST(blob_exit), METH_FASTCALL, blob_exit__doc__},
     198                 :            : 
     199                 :            : static PyObject *
     200                 :            : blob_exit_impl(pysqlite_Blob *self, PyObject *type, PyObject *val,
     201                 :            :                PyObject *tb);
     202                 :            : 
     203                 :            : static PyObject *
     204                 :          0 : blob_exit(pysqlite_Blob *self, PyObject *const *args, Py_ssize_t nargs)
     205                 :            : {
     206                 :          0 :     PyObject *return_value = NULL;
     207                 :            :     PyObject *type;
     208                 :            :     PyObject *val;
     209                 :            :     PyObject *tb;
     210                 :            : 
     211   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("__exit__", nargs, 3, 3)) {
                   #  # ]
     212                 :          0 :         goto exit;
     213                 :            :     }
     214                 :          0 :     type = args[0];
     215                 :          0 :     val = args[1];
     216                 :          0 :     tb = args[2];
     217                 :          0 :     return_value = blob_exit_impl(self, type, val, tb);
     218                 :            : 
     219                 :          0 : exit:
     220                 :          0 :     return return_value;
     221                 :            : }
     222                 :            : /*[clinic end generated code: output=ad6a402f70e85977 input=a9049054013a1b77]*/

Generated by: LCOV version 1.14