LCOV - code coverage report
Current view: top level - Objects/clinic - listobject.c.h (source / functions) Hit Total Coverage
Test: CPython lcov report Lines: 95 101 94.1 %
Date: 2022-07-07 18:19:46 Functions: 10 10 100.0 %

          Line data    Source code
       1             : /*[clinic input]
       2             : preserve
       3             : [clinic start generated code]*/
       4             : 
       5             : PyDoc_STRVAR(list_insert__doc__,
       6             : "insert($self, index, object, /)\n"
       7             : "--\n"
       8             : "\n"
       9             : "Insert object before index.");
      10             : 
      11             : #define LIST_INSERT_METHODDEF    \
      12             :     {"insert", _PyCFunction_CAST(list_insert), METH_FASTCALL, list_insert__doc__},
      13             : 
      14             : static PyObject *
      15             : list_insert_impl(PyListObject *self, Py_ssize_t index, PyObject *object);
      16             : 
      17             : static PyObject *
      18       34302 : list_insert(PyListObject *self, PyObject *const *args, Py_ssize_t nargs)
      19             : {
      20       34302 :     PyObject *return_value = NULL;
      21             :     Py_ssize_t index;
      22             :     PyObject *object;
      23             : 
      24       34302 :     if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) {
      25           1 :         goto exit;
      26             :     }
      27             :     {
      28       34301 :         Py_ssize_t ival = -1;
      29       34301 :         PyObject *iobj = _PyNumber_Index(args[0]);
      30       34301 :         if (iobj != NULL) {
      31       34301 :             ival = PyLong_AsSsize_t(iobj);
      32       34301 :             Py_DECREF(iobj);
      33             :         }
      34       34301 :         if (ival == -1 && PyErr_Occurred()) {
      35           0 :             goto exit;
      36             :         }
      37       34301 :         index = ival;
      38             :     }
      39       34301 :     object = args[1];
      40       34301 :     return_value = list_insert_impl(self, index, object);
      41             : 
      42       34302 : exit:
      43       34302 :     return return_value;
      44             : }
      45             : 
      46             : PyDoc_STRVAR(list_clear__doc__,
      47             : "clear($self, /)\n"
      48             : "--\n"
      49             : "\n"
      50             : "Remove all items from list.");
      51             : 
      52             : #define LIST_CLEAR_METHODDEF    \
      53             :     {"clear", (PyCFunction)list_clear, METH_NOARGS, list_clear__doc__},
      54             : 
      55             : static PyObject *
      56             : list_clear_impl(PyListObject *self);
      57             : 
      58             : static PyObject *
      59        7981 : list_clear(PyListObject *self, PyObject *Py_UNUSED(ignored))
      60             : {
      61        7981 :     return list_clear_impl(self);
      62             : }
      63             : 
      64             : PyDoc_STRVAR(list_copy__doc__,
      65             : "copy($self, /)\n"
      66             : "--\n"
      67             : "\n"
      68             : "Return a shallow copy of the list.");
      69             : 
      70             : #define LIST_COPY_METHODDEF    \
      71             :     {"copy", (PyCFunction)list_copy, METH_NOARGS, list_copy__doc__},
      72             : 
      73             : static PyObject *
      74             : list_copy_impl(PyListObject *self);
      75             : 
      76             : static PyObject *
      77        2523 : list_copy(PyListObject *self, PyObject *Py_UNUSED(ignored))
      78             : {
      79        2523 :     return list_copy_impl(self);
      80             : }
      81             : 
      82             : PyDoc_STRVAR(list_append__doc__,
      83             : "append($self, object, /)\n"
      84             : "--\n"
      85             : "\n"
      86             : "Append object to the end of the list.");
      87             : 
      88             : #define LIST_APPEND_METHODDEF    \
      89             :     {"append", (PyCFunction)list_append, METH_O, list_append__doc__},
      90             : 
      91             : PyDoc_STRVAR(list_extend__doc__,
      92             : "extend($self, iterable, /)\n"
      93             : "--\n"
      94             : "\n"
      95             : "Extend list by appending elements from the iterable.");
      96             : 
      97             : #define LIST_EXTEND_METHODDEF    \
      98             :     {"extend", (PyCFunction)list_extend, METH_O, list_extend__doc__},
      99             : 
     100             : PyDoc_STRVAR(list_pop__doc__,
     101             : "pop($self, index=-1, /)\n"
     102             : "--\n"
     103             : "\n"
     104             : "Remove and return item at index (default last).\n"
     105             : "\n"
     106             : "Raises IndexError if list is empty or index is out of range.");
     107             : 
     108             : #define LIST_POP_METHODDEF    \
     109             :     {"pop", _PyCFunction_CAST(list_pop), METH_FASTCALL, list_pop__doc__},
     110             : 
     111             : static PyObject *
     112             : list_pop_impl(PyListObject *self, Py_ssize_t index);
     113             : 
     114             : static PyObject *
     115     2681210 : list_pop(PyListObject *self, PyObject *const *args, Py_ssize_t nargs)
     116             : {
     117     2681210 :     PyObject *return_value = NULL;
     118     2681210 :     Py_ssize_t index = -1;
     119             : 
     120     2681210 :     if (!_PyArg_CheckPositional("pop", nargs, 0, 1)) {
     121           1 :         goto exit;
     122             :     }
     123     2681210 :     if (nargs < 1) {
     124     2373060 :         goto skip_optional;
     125             :     }
     126             :     {
     127      308147 :         Py_ssize_t ival = -1;
     128      308147 :         PyObject *iobj = _PyNumber_Index(args[0]);
     129      308147 :         if (iobj != NULL) {
     130      308147 :             ival = PyLong_AsSsize_t(iobj);
     131      308147 :             Py_DECREF(iobj);
     132             :         }
     133      308147 :         if (ival == -1 && PyErr_Occurred()) {
     134           0 :             goto exit;
     135             :         }
     136      308147 :         index = ival;
     137             :     }
     138     2681210 : skip_optional:
     139     2681210 :     return_value = list_pop_impl(self, index);
     140             : 
     141     2681210 : exit:
     142     2681210 :     return return_value;
     143             : }
     144             : 
     145             : PyDoc_STRVAR(list_sort__doc__,
     146             : "sort($self, /, *, key=None, reverse=False)\n"
     147             : "--\n"
     148             : "\n"
     149             : "Sort the list in ascending order and return None.\n"
     150             : "\n"
     151             : "The sort is in-place (i.e. the list itself is modified) and stable (i.e. the\n"
     152             : "order of two equal elements is maintained).\n"
     153             : "\n"
     154             : "If a key function is given, apply it once to each list item and sort them,\n"
     155             : "ascending or descending, according to their function values.\n"
     156             : "\n"
     157             : "The reverse flag can be set to sort in descending order.");
     158             : 
     159             : #define LIST_SORT_METHODDEF    \
     160             :     {"sort", _PyCFunction_CAST(list_sort), METH_FASTCALL|METH_KEYWORDS, list_sort__doc__},
     161             : 
     162             : static PyObject *
     163             : list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse);
     164             : 
     165             : static PyObject *
     166      868576 : list_sort(PyListObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     167             : {
     168      868576 :     PyObject *return_value = NULL;
     169             :     static const char * const _keywords[] = {"key", "reverse", NULL};
     170             :     static _PyArg_Parser _parser = {NULL, _keywords, "sort", 0};
     171             :     PyObject *argsbuf[2];
     172      868576 :     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
     173      868576 :     PyObject *keyfunc = Py_None;
     174      868576 :     int reverse = 0;
     175             : 
     176      868576 :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
     177      868576 :     if (!args) {
     178           6 :         goto exit;
     179             :     }
     180      868570 :     if (!noptargs) {
     181      560088 :         goto skip_optional_kwonly;
     182             :     }
     183      308482 :     if (args[0]) {
     184      302602 :         keyfunc = args[0];
     185      302602 :         if (!--noptargs) {
     186      297976 :             goto skip_optional_kwonly;
     187             :         }
     188             :     }
     189       10506 :     reverse = _PyLong_AsInt(args[1]);
     190       10506 :     if (reverse == -1 && PyErr_Occurred()) {
     191           0 :         goto exit;
     192             :     }
     193       10506 : skip_optional_kwonly:
     194      868570 :     return_value = list_sort_impl(self, keyfunc, reverse);
     195             : 
     196      868576 : exit:
     197      868576 :     return return_value;
     198             : }
     199             : 
     200             : PyDoc_STRVAR(list_reverse__doc__,
     201             : "reverse($self, /)\n"
     202             : "--\n"
     203             : "\n"
     204             : "Reverse *IN PLACE*.");
     205             : 
     206             : #define LIST_REVERSE_METHODDEF    \
     207             :     {"reverse", (PyCFunction)list_reverse, METH_NOARGS, list_reverse__doc__},
     208             : 
     209             : static PyObject *
     210             : list_reverse_impl(PyListObject *self);
     211             : 
     212             : static PyObject *
     213       77541 : list_reverse(PyListObject *self, PyObject *Py_UNUSED(ignored))
     214             : {
     215       77541 :     return list_reverse_impl(self);
     216             : }
     217             : 
     218             : PyDoc_STRVAR(list_index__doc__,
     219             : "index($self, value, start=0, stop=sys.maxsize, /)\n"
     220             : "--\n"
     221             : "\n"
     222             : "Return first index of value.\n"
     223             : "\n"
     224             : "Raises ValueError if the value is not present.");
     225             : 
     226             : #define LIST_INDEX_METHODDEF    \
     227             :     {"index", _PyCFunction_CAST(list_index), METH_FASTCALL, list_index__doc__},
     228             : 
     229             : static PyObject *
     230             : list_index_impl(PyListObject *self, PyObject *value, Py_ssize_t start,
     231             :                 Py_ssize_t stop);
     232             : 
     233             : static PyObject *
     234      105148 : list_index(PyListObject *self, PyObject *const *args, Py_ssize_t nargs)
     235             : {
     236      105148 :     PyObject *return_value = NULL;
     237             :     PyObject *value;
     238      105148 :     Py_ssize_t start = 0;
     239      105148 :     Py_ssize_t stop = PY_SSIZE_T_MAX;
     240             : 
     241      105148 :     if (!_PyArg_CheckPositional("index", nargs, 1, 3)) {
     242           1 :         goto exit;
     243             :     }
     244      105147 :     value = args[0];
     245      105147 :     if (nargs < 2) {
     246       36036 :         goto skip_optional;
     247             :     }
     248       69111 :     if (!_PyEval_SliceIndexNotNone(args[1], &start)) {
     249           0 :         goto exit;
     250             :     }
     251       69111 :     if (nargs < 3) {
     252         119 :         goto skip_optional;
     253             :     }
     254       68992 :     if (!_PyEval_SliceIndexNotNone(args[2], &stop)) {
     255           0 :         goto exit;
     256             :     }
     257       68992 : skip_optional:
     258      105147 :     return_value = list_index_impl(self, value, start, stop);
     259             : 
     260      105148 : exit:
     261      105148 :     return return_value;
     262             : }
     263             : 
     264             : PyDoc_STRVAR(list_count__doc__,
     265             : "count($self, value, /)\n"
     266             : "--\n"
     267             : "\n"
     268             : "Return number of occurrences of value.");
     269             : 
     270             : #define LIST_COUNT_METHODDEF    \
     271             :     {"count", (PyCFunction)list_count, METH_O, list_count__doc__},
     272             : 
     273             : PyDoc_STRVAR(list_remove__doc__,
     274             : "remove($self, value, /)\n"
     275             : "--\n"
     276             : "\n"
     277             : "Remove first occurrence of value.\n"
     278             : "\n"
     279             : "Raises ValueError if the value is not present.");
     280             : 
     281             : #define LIST_REMOVE_METHODDEF    \
     282             :     {"remove", (PyCFunction)list_remove, METH_O, list_remove__doc__},
     283             : 
     284             : PyDoc_STRVAR(list___init____doc__,
     285             : "list(iterable=(), /)\n"
     286             : "--\n"
     287             : "\n"
     288             : "Built-in mutable sequence.\n"
     289             : "\n"
     290             : "If no argument is given, the constructor creates a new empty list.\n"
     291             : "The argument must be an iterable if specified.");
     292             : 
     293             : static int
     294             : list___init___impl(PyListObject *self, PyObject *iterable);
     295             : 
     296             : static int
     297     4298310 : list___init__(PyObject *self, PyObject *args, PyObject *kwargs)
     298             : {
     299     4298310 :     int return_value = -1;
     300     4298310 :     PyObject *iterable = NULL;
     301             : 
     302     4298310 :     if ((Py_IS_TYPE(self, &PyList_Type) ||
     303     4298310 :          Py_TYPE(self)->tp_new == PyList_Type.tp_new) &&
     304       47281 :         !_PyArg_NoKeywords("list", kwargs)) {
     305           1 :         goto exit;
     306             :     }
     307     4298310 :     if (!_PyArg_CheckPositional("list", PyTuple_GET_SIZE(args), 0, 1)) {
     308           0 :         goto exit;
     309             :     }
     310     4298310 :     if (PyTuple_GET_SIZE(args) < 1) {
     311       98445 :         goto skip_optional;
     312             :     }
     313     4199860 :     iterable = PyTuple_GET_ITEM(args, 0);
     314     4298310 : skip_optional:
     315     4298310 :     return_value = list___init___impl((PyListObject *)self, iterable);
     316             : 
     317     4298310 : exit:
     318     4298310 :     return return_value;
     319             : }
     320             : 
     321             : PyDoc_STRVAR(list___sizeof____doc__,
     322             : "__sizeof__($self, /)\n"
     323             : "--\n"
     324             : "\n"
     325             : "Return the size of the list in memory, in bytes.");
     326             : 
     327             : #define LIST___SIZEOF___METHODDEF    \
     328             :     {"__sizeof__", (PyCFunction)list___sizeof__, METH_NOARGS, list___sizeof____doc__},
     329             : 
     330             : static PyObject *
     331             : list___sizeof___impl(PyListObject *self);
     332             : 
     333             : static PyObject *
     334          10 : list___sizeof__(PyListObject *self, PyObject *Py_UNUSED(ignored))
     335             : {
     336          10 :     return list___sizeof___impl(self);
     337             : }
     338             : 
     339             : PyDoc_STRVAR(list___reversed____doc__,
     340             : "__reversed__($self, /)\n"
     341             : "--\n"
     342             : "\n"
     343             : "Return a reverse iterator over the list.");
     344             : 
     345             : #define LIST___REVERSED___METHODDEF    \
     346             :     {"__reversed__", (PyCFunction)list___reversed__, METH_NOARGS, list___reversed____doc__},
     347             : 
     348             : static PyObject *
     349             : list___reversed___impl(PyListObject *self);
     350             : 
     351             : static PyObject *
     352       96642 : list___reversed__(PyListObject *self, PyObject *Py_UNUSED(ignored))
     353             : {
     354       96642 :     return list___reversed___impl(self);
     355             : }
     356             : /*[clinic end generated code: output=eab97a76b1568a03 input=a9049054013a1b77]*/

Generated by: LCOV version 1.14