2018-12-30 05:24:03 -04:00
|
|
|
/*[clinic input]
|
|
|
|
preserve
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
2023-08-31 18:42:34 -03:00
|
|
|
#include "pycore_abstract.h" // _PyNumber_Index()
|
2023-10-17 09:30:31 -03:00
|
|
|
#include "pycore_modsupport.h" // _PyArg_CheckPositional()
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2019-06-05 20:05:25 -03:00
|
|
|
PyDoc_STRVAR(_collections__count_elements__doc__,
|
|
|
|
"_count_elements($module, mapping, iterable, /)\n"
|
|
|
|
"--\n"
|
|
|
|
"\n"
|
|
|
|
"Count elements in the iterable, updating the mapping");
|
|
|
|
|
|
|
|
#define _COLLECTIONS__COUNT_ELEMENTS_METHODDEF \
|
2022-05-03 15:25:41 -03:00
|
|
|
{"_count_elements", _PyCFunction_CAST(_collections__count_elements), METH_FASTCALL, _collections__count_elements__doc__},
|
2019-06-05 20:05:25 -03:00
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_collections__count_elements_impl(PyObject *module, PyObject *mapping,
|
|
|
|
PyObject *iterable);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_collections__count_elements(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
|
|
|
PyObject *mapping;
|
|
|
|
PyObject *iterable;
|
|
|
|
|
|
|
|
if (!_PyArg_CheckPositional("_count_elements", nargs, 2, 2)) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
mapping = args[0];
|
|
|
|
iterable = args[1];
|
|
|
|
return_value = _collections__count_elements_impl(module, mapping, iterable);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2018-12-30 05:24:03 -04:00
|
|
|
static PyObject *
|
|
|
|
tuplegetter_new_impl(PyTypeObject *type, Py_ssize_t index, PyObject *doc);
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
tuplegetter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
2023-04-12 09:51:28 -03:00
|
|
|
PyTypeObject *base_tp = clinic_state()->tuplegetter_type;
|
2018-12-30 05:24:03 -04:00
|
|
|
Py_ssize_t index;
|
|
|
|
PyObject *doc;
|
|
|
|
|
2023-01-31 16:42:03 -04:00
|
|
|
if ((type == base_tp || type->tp_init == base_tp->tp_init) &&
|
2018-12-30 05:24:03 -04:00
|
|
|
!_PyArg_NoKeywords("_tuplegetter", kwargs)) {
|
|
|
|
goto exit;
|
|
|
|
}
|
2019-01-11 10:01:14 -04:00
|
|
|
if (!_PyArg_CheckPositional("_tuplegetter", PyTuple_GET_SIZE(args), 2, 2)) {
|
2018-12-30 05:24:03 -04:00
|
|
|
goto exit;
|
|
|
|
}
|
2019-01-11 10:01:14 -04:00
|
|
|
{
|
|
|
|
Py_ssize_t ival = -1;
|
2020-05-28 04:33:45 -03:00
|
|
|
PyObject *iobj = _PyNumber_Index(PyTuple_GET_ITEM(args, 0));
|
2019-01-11 10:01:14 -04:00
|
|
|
if (iobj != NULL) {
|
|
|
|
ival = PyLong_AsSsize_t(iobj);
|
|
|
|
Py_DECREF(iobj);
|
|
|
|
}
|
|
|
|
if (ival == -1 && PyErr_Occurred()) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
index = ival;
|
|
|
|
}
|
|
|
|
doc = PyTuple_GET_ITEM(args, 1);
|
2018-12-30 05:24:03 -04:00
|
|
|
return_value = tuplegetter_new_impl(type, index, doc);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
2023-10-17 09:30:31 -03:00
|
|
|
/*[clinic end generated code: output=c896a72f8c45930d input=a9049054013a1b77]*/
|