blob: c3ba1a6698571d4af6037ca1b86263b09e5a749a [file] [log] [blame]
Pablo Galindo3f5fc702018-12-30 09:24:03 +00001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
Raymond Hettingere9858042019-06-05 16:05:25 -07005PyDoc_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
14static PyObject *
15_collections__count_elements_impl(PyObject *module, PyObject *mapping,
16 PyObject *iterable);
17
18static 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
32exit:
33 return return_value;
34}
35
Pablo Galindo3f5fc702018-12-30 09:24:03 +000036static PyObject *
37tuplegetter_new_impl(PyTypeObject *type, Py_ssize_t index, PyObject *doc);
38
39static PyObject *
40tuplegetter_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 Storchaka4fa95912019-01-11 16:01:14 +020050 if (!_PyArg_CheckPositional("_tuplegetter", PyTuple_GET_SIZE(args), 2, 2)) {
Pablo Galindo3f5fc702018-12-30 09:24:03 +000051 goto exit;
52 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +020053 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 Galindo3f5fc702018-12-30 09:24:03 +000071 return_value = tuplegetter_new_impl(type, index, doc);
72
73exit:
74 return return_value;
75}
Raymond Hettingere9858042019-06-05 16:05:25 -070076/*[clinic end generated code: output=9d2bfcc9df5faf35 input=a9049054013a1b77]*/