Serhiy Storchaka | 0b56159 | 2017-03-19 08:47:58 +0200 | [diff] [blame] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
| 5 | PyDoc_STRVAR(tuple_index__doc__, |
| 6 | "index($self, value, start=0, stop=sys.maxsize, /)\n" |
| 7 | "--\n" |
| 8 | "\n" |
| 9 | "Return first index of value.\n" |
| 10 | "\n" |
| 11 | "Raises ValueError if the value is not present."); |
| 12 | |
| 13 | #define TUPLE_INDEX_METHODDEF \ |
| 14 | {"index", (PyCFunction)tuple_index, METH_FASTCALL, tuple_index__doc__}, |
| 15 | |
| 16 | static PyObject * |
| 17 | tuple_index_impl(PyTupleObject *self, PyObject *value, Py_ssize_t start, |
| 18 | Py_ssize_t stop); |
| 19 | |
| 20 | static PyObject * |
| 21 | tuple_index(PyTupleObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
| 22 | { |
| 23 | PyObject *return_value = NULL; |
| 24 | PyObject *value; |
| 25 | Py_ssize_t start = 0; |
| 26 | Py_ssize_t stop = PY_SSIZE_T_MAX; |
| 27 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame^] | 28 | if (!_PyArg_NoStackKeywords("index", kwnames)) { |
Serhiy Storchaka | 0b56159 | 2017-03-19 08:47:58 +0200 | [diff] [blame] | 29 | goto exit; |
| 30 | } |
| 31 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame^] | 32 | if (!_PyArg_ParseStack(args, nargs, "O|O&O&:index", |
| 33 | &value, _PyEval_SliceIndexNotNone, &start, _PyEval_SliceIndexNotNone, &stop)) { |
Serhiy Storchaka | 0b56159 | 2017-03-19 08:47:58 +0200 | [diff] [blame] | 34 | goto exit; |
| 35 | } |
| 36 | return_value = tuple_index_impl(self, value, start, stop); |
| 37 | |
| 38 | exit: |
| 39 | return return_value; |
| 40 | } |
| 41 | |
| 42 | PyDoc_STRVAR(tuple_count__doc__, |
| 43 | "count($self, value, /)\n" |
| 44 | "--\n" |
| 45 | "\n" |
| 46 | "Return number of occurrences of value."); |
| 47 | |
| 48 | #define TUPLE_COUNT_METHODDEF \ |
| 49 | {"count", (PyCFunction)tuple_count, METH_O, tuple_count__doc__}, |
| 50 | |
| 51 | PyDoc_STRVAR(tuple_new__doc__, |
| 52 | "tuple(iterable=(), /)\n" |
| 53 | "--\n" |
| 54 | "\n" |
| 55 | "Built-in immutable sequence.\n" |
| 56 | "\n" |
| 57 | "If no argument is given, the constructor returns an empty tuple.\n" |
| 58 | "If iterable is specified the tuple is initialized from iterable\'s items.\n" |
| 59 | "\n" |
| 60 | "If the argument is a tuple, the return value is the same object."); |
| 61 | |
| 62 | static PyObject * |
| 63 | tuple_new_impl(PyTypeObject *type, PyObject *iterable); |
| 64 | |
| 65 | static PyObject * |
| 66 | tuple_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 67 | { |
| 68 | PyObject *return_value = NULL; |
| 69 | PyObject *iterable = NULL; |
| 70 | |
| 71 | if ((type == &PyTuple_Type) && |
| 72 | !_PyArg_NoKeywords("tuple", kwargs)) { |
| 73 | goto exit; |
| 74 | } |
| 75 | if (!PyArg_UnpackTuple(args, "tuple", |
| 76 | 0, 1, |
| 77 | &iterable)) { |
| 78 | goto exit; |
| 79 | } |
| 80 | return_value = tuple_new_impl(type, iterable); |
| 81 | |
| 82 | exit: |
| 83 | return return_value; |
| 84 | } |
| 85 | |
| 86 | PyDoc_STRVAR(tuple___getnewargs____doc__, |
| 87 | "__getnewargs__($self, /)\n" |
| 88 | "--\n" |
| 89 | "\n"); |
| 90 | |
| 91 | #define TUPLE___GETNEWARGS___METHODDEF \ |
| 92 | {"__getnewargs__", (PyCFunction)tuple___getnewargs__, METH_NOARGS, tuple___getnewargs____doc__}, |
| 93 | |
| 94 | static PyObject * |
| 95 | tuple___getnewargs___impl(PyTupleObject *self); |
| 96 | |
| 97 | static PyObject * |
| 98 | tuple___getnewargs__(PyTupleObject *self, PyObject *Py_UNUSED(ignored)) |
| 99 | { |
| 100 | return tuple___getnewargs___impl(self); |
| 101 | } |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame^] | 102 | /*[clinic end generated code: output=70b4de94a0002ec3 input=a9049054013a1b77]*/ |