diff -r 967f368b7f75 Modules/_collectionsmodule.c --- a/Modules/_collectionsmodule.c Sun Jan 19 00:38:36 2014 +0200 +++ b/Modules/_collectionsmodule.c Sun Jan 19 04:13:59 2014 +0200 @@ -7,6 +7,19 @@ All rights reserved. */ +/*[clinic input] +module collections +class collections.deque +class collections.Counter +[clinic start generated code]*/ +/*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ + +/*[python input] +class dequeobject_converter(self_converter): + type = "dequeobject *" +[python start generated code]*/ +/*[python end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ + /* The block length may be set to any number over 1. Larger numbers * reduce the number of calls to the memory allocator, give faster * indexing and rotation, and reduce the link::data overhead ratio. @@ -578,21 +591,55 @@ return rv; } +/*[clinic input] +collections.deque.rotate + + self: dequeobject + n: Py_ssize_t = 1 + Number of steps to rotate to the right (to the left if negative) + / + +Rotate the deque n steps to the right (default n=1). +[clinic start generated code]*/ + +PyDoc_STRVAR(collections_deque_rotate__doc__, +"rotate(n=1)\n" +"Rotate the deque n steps to the right (default n=1).\n" +"\n" +" n\n" +" Number of steps to rotate to the right (to the left if negative)"); + +#define COLLECTIONS_DEQUE_ROTATE_METHODDEF \ + {"rotate", (PyCFunction)collections_deque_rotate, METH_VARARGS, collections_deque_rotate__doc__}, + static PyObject * -deque_rotate(dequeobject *deque, PyObject *args) +collections_deque_rotate_impl(dequeobject *self, Py_ssize_t n); + +static PyObject * +collections_deque_rotate(PyObject *self, PyObject *args) { - Py_ssize_t n=1; + PyObject *return_value = NULL; + Py_ssize_t n = 1; - if (!PyArg_ParseTuple(args, "|n:rotate", &n)) - return NULL; - if (_deque_rotate(deque, n) == 0) + if (!PyArg_ParseTuple(args, + "|n:rotate", + &n)) + goto exit; + return_value = collections_deque_rotate_impl((dequeobject *)self, n); + +exit: + return return_value; +} + +static PyObject * +collections_deque_rotate_impl(dequeobject *self, Py_ssize_t n) +/*[clinic end generated code: checksum=911f7bd289febeb22aa90169649523e5834852f2]*/ +{ + if (_deque_rotate(self, n) == 0) Py_RETURN_NONE; return NULL; } -PyDoc_STRVAR(rotate_doc, -"Rotate the deque n steps to the right (default n=1). If n is negative, rotates left."); - static PyObject * deque_reverse(dequeobject *deque, PyObject *unused) { @@ -1135,8 +1182,7 @@ METH_NOARGS, reversed_doc}, {"reverse", (PyCFunction)deque_reverse, METH_NOARGS, reverse_doc}, - {"rotate", (PyCFunction)deque_rotate, - METH_VARARGS, rotate_doc}, + COLLECTIONS_DEQUE_ROTATE_METHODDEF {"__sizeof__", (PyCFunction)deque_sizeof, METH_NOARGS, sizeof_doc}, {NULL, NULL} /* sentinel */ @@ -1757,17 +1803,50 @@ /* helper function for Counter *********************************************/ -PyDoc_STRVAR(_count_elements_doc, -"_count_elements(mapping, iterable) -> None\n\ -\n\ -Count elements in the iterable, updating the mappping"); +/*[clinic input] +collections.Counter._count_elements + + mapping: object + iterable: object + / + +Count elements in the iterable, updating the mappping +[clinic start generated code]*/ + +PyDoc_STRVAR(collections_Counter__count_elements__doc__, +"_count_elements(mapping, iterable)\n" +"Count elements in the iterable, updating the mappping"); + +#define COLLECTIONS_COUNTER__COUNT_ELEMENTS_METHODDEF \ + {"_count_elements", (PyCFunction)collections_Counter__count_elements, METH_VARARGS, collections_Counter__count_elements__doc__}, static PyObject * -_count_elements(PyObject *self, PyObject *args) +collections_Counter__count_elements_impl(PyObject *self, PyObject *mapping, PyObject *iterable); + +static PyObject * +collections_Counter__count_elements(PyObject *self, PyObject *args) +{ + PyObject *return_value = NULL; + PyObject *mapping; + PyObject *iterable; + + if (!PyArg_UnpackTuple(args, "_count_elements", + 2, 2, + &mapping, &iterable)) + goto exit; + return_value = collections_Counter__count_elements_impl(self, mapping, iterable); + +exit: + return return_value; +} + +static PyObject * +collections_Counter__count_elements_impl(PyObject *self, PyObject *mapping, PyObject *iterable) +/*[clinic end generated code: checksum=f446302908a73a3d575c1c2129a077b1b74f475a]*/ { _Py_IDENTIFIER(get); _Py_IDENTIFIER(__setitem__); - PyObject *it, *iterable, *mapping, *oldval; + PyObject *it, *oldval; PyObject *newval = NULL; PyObject *key = NULL; PyObject *zero = NULL; @@ -1778,9 +1857,6 @@ 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; @@ -1865,7 +1941,7 @@ "); static struct PyMethodDef module_functions[] = { - {"_count_elements", _count_elements, METH_VARARGS, _count_elements_doc}, + COLLECTIONS_COUNTER__COUNT_ELEMENTS_METHODDEF {NULL, NULL} /* sentinel */ };

AltStyle によって変換されたページ (->オリジナル) /