Skip to content

Commit

Permalink
bpo-37165: Convert _count_elements to the argument clinic (GH-13848)
Browse files Browse the repository at this point in the history
(cherry picked from commit e985804)

Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
  • Loading branch information
miss-islington and rhettinger committed Jun 5, 2019
1 parent d74438b commit 21ce245
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Converted _collections._count_elements to use the Argument Clinic.
27 changes: 16 additions & 11 deletions Modules/_collectionsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
#endif

/*[clinic input]
module _collections
class _tuplegetter "_tuplegetterobject *" "&tuplegetter_type"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=ee5ed5baabe35068]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=a8ece4ccad7e30ac]*/

static PyTypeObject tuplegetter_type;
#include "clinic/_collectionsmodule.c.h"
Expand Down Expand Up @@ -2228,17 +2229,24 @@ static PyTypeObject defdict_type = {

/* helper function for Counter *********************************************/

PyDoc_STRVAR(_count_elements_doc,
"_count_elements(mapping, iterable) -> None\n\
\n\
Count elements in the iterable, updating the mapping");
/*[clinic input]
_collections._count_elements
mapping: object
iterable: object
/
Count elements in the iterable, updating the mapping
[clinic start generated code]*/

static PyObject *
_count_elements(PyObject *self, PyObject *args)
_collections__count_elements_impl(PyObject *module, PyObject *mapping,
PyObject *iterable)
/*[clinic end generated code: output=7e0c1789636b3d8f input=e79fad04534a0b45]*/
{
_Py_IDENTIFIER(get);
_Py_IDENTIFIER(__setitem__);
PyObject *it, *iterable, *mapping, *oldval;
PyObject *it, *oldval;
PyObject *newval = NULL;
PyObject *key = NULL;
PyObject *bound_get = NULL;
Expand All @@ -2247,9 +2255,6 @@ _count_elements(PyObject *self, PyObject *args)
PyObject *mapping_setitem;
PyObject *dict_setitem;

if (!PyArg_UnpackTuple(args, "_count_elements", 2, 2, &mapping, &iterable))
return NULL;

it = PyObject_GetIter(iterable);
if (it == NULL)
return NULL;
Expand Down Expand Up @@ -2510,7 +2515,7 @@ PyDoc_STRVAR(module_doc,
");

static struct PyMethodDef module_functions[] = {
{"_count_elements", _count_elements, METH_VARARGS, _count_elements_doc},
_COLLECTIONS__COUNT_ELEMENTS_METHODDEF
{NULL, NULL} /* sentinel */
};

Expand Down
33 changes: 32 additions & 1 deletion Modules/clinic/_collectionsmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 21ce245

Please sign in to comment.