_collectionsmodule.c.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*[clinic input]
  2. preserve
  3. [clinic start generated code]*/
  4. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  5. # include "pycore_gc.h" // PyGC_Head
  6. # include "pycore_runtime.h" // _Py_ID()
  7. #endif
  8. PyDoc_STRVAR(_collections__count_elements__doc__,
  9. "_count_elements($module, mapping, iterable, /)\n"
  10. "--\n"
  11. "\n"
  12. "Count elements in the iterable, updating the mapping");
  13. #define _COLLECTIONS__COUNT_ELEMENTS_METHODDEF \
  14. {"_count_elements", _PyCFunction_CAST(_collections__count_elements), METH_FASTCALL, _collections__count_elements__doc__},
  15. static PyObject *
  16. _collections__count_elements_impl(PyObject *module, PyObject *mapping,
  17. PyObject *iterable);
  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. if (!_PyArg_CheckPositional("_count_elements", nargs, 2, 2)) {
  25. goto exit;
  26. }
  27. mapping = args[0];
  28. iterable = args[1];
  29. return_value = _collections__count_elements_impl(module, mapping, iterable);
  30. exit:
  31. return return_value;
  32. }
  33. static PyObject *
  34. tuplegetter_new_impl(PyTypeObject *type, Py_ssize_t index, PyObject *doc);
  35. static PyObject *
  36. tuplegetter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
  37. {
  38. PyObject *return_value = NULL;
  39. PyTypeObject *base_tp = clinic_state()->tuplegetter_type;
  40. Py_ssize_t index;
  41. PyObject *doc;
  42. if ((type == base_tp || type->tp_init == base_tp->tp_init) &&
  43. !_PyArg_NoKeywords("_tuplegetter", kwargs)) {
  44. goto exit;
  45. }
  46. if (!_PyArg_CheckPositional("_tuplegetter", PyTuple_GET_SIZE(args), 2, 2)) {
  47. goto exit;
  48. }
  49. {
  50. Py_ssize_t ival = -1;
  51. PyObject *iobj = _PyNumber_Index(PyTuple_GET_ITEM(args, 0));
  52. if (iobj != NULL) {
  53. ival = PyLong_AsSsize_t(iobj);
  54. Py_DECREF(iobj);
  55. }
  56. if (ival == -1 && PyErr_Occurred()) {
  57. goto exit;
  58. }
  59. index = ival;
  60. }
  61. doc = PyTuple_GET_ITEM(args, 1);
  62. return_value = tuplegetter_new_impl(type, index, doc);
  63. exit:
  64. return return_value;
  65. }
  66. /*[clinic end generated code: output=00e516317d2b8bed input=a9049054013a1b77]*/