Pablo Galindo | 3f5fc70 | 2018-12-30 09:24:03 +0000 | [diff] [blame] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
Raymond Hettinger | e985804 | 2019-06-05 16:05:25 -0700 | [diff] [blame] | 5 | PyDoc_STRVAR(_collections__count_elements__doc__, |
| 6 | "_count_elements($module, mapping, iterable, /)\n" |
| 7 | "--\n" |
| 8 | "\n" |
| 9 | "Count elements in the iterable, updating the mapping"); |
| 10 | |
| 11 | #define _COLLECTIONS__COUNT_ELEMENTS_METHODDEF \ |
| 12 | {"_count_elements", (PyCFunction)(void(*)(void))_collections__count_elements, METH_FASTCALL, _collections__count_elements__doc__}, |
| 13 | |
| 14 | static PyObject * |
| 15 | _collections__count_elements_impl(PyObject *module, PyObject *mapping, |
| 16 | PyObject *iterable); |
| 17 | |
| 18 | static PyObject * |
| 19 | _collections__count_elements(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 20 | { |
| 21 | PyObject *return_value = NULL; |
| 22 | PyObject *mapping; |
| 23 | PyObject *iterable; |
| 24 | |
| 25 | if (!_PyArg_CheckPositional("_count_elements", nargs, 2, 2)) { |
| 26 | goto exit; |
| 27 | } |
| 28 | mapping = args[0]; |
| 29 | iterable = args[1]; |
| 30 | return_value = _collections__count_elements_impl(module, mapping, iterable); |
| 31 | |
| 32 | exit: |
| 33 | return return_value; |
| 34 | } |
| 35 | |
Pablo Galindo | 3f5fc70 | 2018-12-30 09:24:03 +0000 | [diff] [blame] | 36 | static PyObject * |
| 37 | tuplegetter_new_impl(PyTypeObject *type, Py_ssize_t index, PyObject *doc); |
| 38 | |
| 39 | static PyObject * |
| 40 | tuplegetter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 41 | { |
| 42 | PyObject *return_value = NULL; |
| 43 | Py_ssize_t index; |
| 44 | PyObject *doc; |
| 45 | |
| 46 | if ((type == &tuplegetter_type) && |
| 47 | !_PyArg_NoKeywords("_tuplegetter", kwargs)) { |
| 48 | goto exit; |
| 49 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 50 | if (!_PyArg_CheckPositional("_tuplegetter", PyTuple_GET_SIZE(args), 2, 2)) { |
Pablo Galindo | 3f5fc70 | 2018-12-30 09:24:03 +0000 | [diff] [blame] | 51 | goto exit; |
| 52 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 53 | if (PyFloat_Check(PyTuple_GET_ITEM(args, 0))) { |
| 54 | PyErr_SetString(PyExc_TypeError, |
| 55 | "integer argument expected, got float" ); |
| 56 | goto exit; |
| 57 | } |
| 58 | { |
| 59 | Py_ssize_t ival = -1; |
| 60 | PyObject *iobj = PyNumber_Index(PyTuple_GET_ITEM(args, 0)); |
| 61 | if (iobj != NULL) { |
| 62 | ival = PyLong_AsSsize_t(iobj); |
| 63 | Py_DECREF(iobj); |
| 64 | } |
| 65 | if (ival == -1 && PyErr_Occurred()) { |
| 66 | goto exit; |
| 67 | } |
| 68 | index = ival; |
| 69 | } |
| 70 | doc = PyTuple_GET_ITEM(args, 1); |
Pablo Galindo | 3f5fc70 | 2018-12-30 09:24:03 +0000 | [diff] [blame] | 71 | return_value = tuplegetter_new_impl(type, index, doc); |
| 72 | |
| 73 | exit: |
| 74 | return return_value; |
| 75 | } |
Raymond Hettinger | e985804 | 2019-06-05 16:05:25 -0700 | [diff] [blame] | 76 | /*[clinic end generated code: output=9d2bfcc9df5faf35 input=a9049054013a1b77]*/ |