| 1 |
/*[clinic input] |
| 2 |
preserve |
| 3 |
[clinic start generated code]*/ |
| 4 |
|
| 5 |
#include "pycore_modsupport.h" // _PyArg_CheckPositional() |
| 6 |
|
| 7 |
PyDoc_STRVAR(tuple_index__doc__, |
| 8 |
"index($self, value, start=0, stop=sys.maxsize, /)\n" |
| 9 |
"--\n" |
| 10 |
"\n" |
| 11 |
"Return first index of value.\n" |
| 12 |
"\n" |
| 13 |
"Raises ValueError if the value is not present."); |
| 14 |
|
| 15 |
#define TUPLE_INDEX_METHODDEF \ |
| 16 |
{"index", _PyCFunction_CAST(tuple_index), METH_FASTCALL, tuple_index__doc__}, |
| 17 |
|
| 18 |
static PyObject * |
| 19 |
tuple_index_impl(PyTupleObject *self, PyObject *value, Py_ssize_t start, |
| 20 |
Py_ssize_t stop); |
| 21 |
|
| 22 |
static PyObject * |
| 23 |
tuple_index(PyObject *self, PyObject *const *args, Py_ssize_t nargs) |
| 24 |
{ |
| 25 |
PyObject *return_value = NULL; |
| 26 |
PyObject *value; |
| 27 |
Py_ssize_t start = 0; |
| 28 |
Py_ssize_t stop = PY_SSIZE_T_MAX; |
| 29 |
|
| 30 |
if (!_PyArg_CheckPositional("index", nargs, 1, 3)) { |
| 31 |
goto exit; |
| 32 |
} |
| 33 |
value = args[0]; |
| 34 |
if (nargs < 2) { |
| 35 |
goto skip_optional; |
| 36 |
} |
| 37 |
if (!_PyEval_SliceIndexNotNone(args[1], &start)) { |
| 38 |
goto exit; |
| 39 |
} |
| 40 |
if (nargs < 3) { |
| 41 |
goto skip_optional; |
| 42 |
} |
| 43 |
if (!_PyEval_SliceIndexNotNone(args[2], &stop)) { |
| 44 |
goto exit; |
| 45 |
} |
| 46 |
skip_optional: |
| 47 |
return_value = tuple_index_impl((PyTupleObject *)self, value, start, stop); |
| 48 |
|
| 49 |
exit: |
| 50 |
return return_value; |
| 51 |
} |
| 52 |
|
| 53 |
PyDoc_STRVAR(tuple_count__doc__, |
| 54 |
"count($self, value, /)\n" |
| 55 |
"--\n" |
| 56 |
"\n" |
| 57 |
"Return number of occurrences of value."); |
| 58 |
|
| 59 |
#define TUPLE_COUNT_METHODDEF \ |
| 60 |
{"count", (PyCFunction)tuple_count, METH_O, tuple_count__doc__}, |
| 61 |
|
| 62 |
static PyObject * |
| 63 |
tuple_count_impl(PyTupleObject *self, PyObject *value); |
| 64 |
|
| 65 |
static PyObject * |
| 66 |
tuple_count(PyObject *self, PyObject *value) |
| 67 |
{ |
| 68 |
PyObject *return_value = NULL; |
| 69 |
|
| 70 |
return_value = tuple_count_impl((PyTupleObject *)self, value); |
| 71 |
|
| 72 |
return return_value; |
| 73 |
} |
| 74 |
|
| 75 |
PyDoc_STRVAR(tuple_new__doc__, |
| 76 |
"tuple(iterable=(), /)\n" |
| 77 |
"--\n" |
| 78 |
"\n" |
| 79 |
"Built-in immutable sequence.\n" |
| 80 |
"\n" |
| 81 |
"If no argument is given, the constructor returns an empty tuple.\n" |
| 82 |
"If iterable is specified the tuple is initialized from iterable\'s items.\n" |
| 83 |
"\n" |
| 84 |
"If the argument is a tuple, the return value is the same object."); |
| 85 |
|
| 86 |
static PyObject * |
| 87 |
tuple_new_impl(PyTypeObject *type, PyObject *iterable); |
| 88 |
|
| 89 |
static PyObject * |
| 90 |
tuple_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 91 |
{ |
| 92 |
PyObject *return_value = NULL; |
| 93 |
PyTypeObject *base_tp = &PyTuple_Type; |
| 94 |
PyObject *iterable = NULL; |
| 95 |
|
| 96 |
if ((type == base_tp || type->tp_init == base_tp->tp_init) && |
| 97 |
!_PyArg_NoKeywords("tuple", kwargs)) { |
| 98 |
goto exit; |
| 99 |
} |
| 100 |
if (!_PyArg_CheckPositional("tuple", PyTuple_GET_SIZE(args), 0, 1)) { |
| 101 |
goto exit; |
| 102 |
} |
| 103 |
if (PyTuple_GET_SIZE(args) < 1) { |
| 104 |
goto skip_optional; |
| 105 |
} |
| 106 |
iterable = PyTuple_GET_ITEM(args, 0); |
| 107 |
skip_optional: |
| 108 |
return_value = tuple_new_impl(type, iterable); |
| 109 |
|
| 110 |
exit: |
| 111 |
return return_value; |
| 112 |
} |
| 113 |
|
| 114 |
PyDoc_STRVAR(tuple___getnewargs____doc__, |
| 115 |
"__getnewargs__($self, /)\n" |
| 116 |
"--\n" |
| 117 |
"\n"); |
| 118 |
|
| 119 |
#define TUPLE___GETNEWARGS___METHODDEF \ |
| 120 |
{"__getnewargs__", (PyCFunction)tuple___getnewargs__, METH_NOARGS, tuple___getnewargs____doc__}, |
| 121 |
|
| 122 |
static PyObject * |
| 123 |
tuple___getnewargs___impl(PyTupleObject *self); |
| 124 |
|
| 125 |
static PyObject * |
| 126 |
tuple___getnewargs__(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 127 |
{ |
| 128 |
return tuple___getnewargs___impl((PyTupleObject *)self); |
| 129 |
} |
| 130 |
/*[clinic end generated code: output=bd11662d62d973c2 input=a9049054013a1b77]*/ |