Pablo Galindo | 3f5fc70 | 2018-12-30 09:24:03 +0000 | [diff] [blame] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
| 5 | static PyObject * |
| 6 | tuplegetter_new_impl(PyTypeObject *type, Py_ssize_t index, PyObject *doc); |
| 7 | |
| 8 | static PyObject * |
| 9 | tuplegetter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 10 | { |
| 11 | PyObject *return_value = NULL; |
| 12 | Py_ssize_t index; |
| 13 | PyObject *doc; |
| 14 | |
| 15 | if ((type == &tuplegetter_type) && |
| 16 | !_PyArg_NoKeywords("_tuplegetter", kwargs)) { |
| 17 | goto exit; |
| 18 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 19 | if (!_PyArg_CheckPositional("_tuplegetter", PyTuple_GET_SIZE(args), 2, 2)) { |
Pablo Galindo | 3f5fc70 | 2018-12-30 09:24:03 +0000 | [diff] [blame] | 20 | goto exit; |
| 21 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 22 | if (PyFloat_Check(PyTuple_GET_ITEM(args, 0))) { |
| 23 | PyErr_SetString(PyExc_TypeError, |
| 24 | "integer argument expected, got float" ); |
| 25 | goto exit; |
| 26 | } |
| 27 | { |
| 28 | Py_ssize_t ival = -1; |
| 29 | PyObject *iobj = PyNumber_Index(PyTuple_GET_ITEM(args, 0)); |
| 30 | if (iobj != NULL) { |
| 31 | ival = PyLong_AsSsize_t(iobj); |
| 32 | Py_DECREF(iobj); |
| 33 | } |
| 34 | if (ival == -1 && PyErr_Occurred()) { |
| 35 | goto exit; |
| 36 | } |
| 37 | index = ival; |
| 38 | } |
| 39 | doc = PyTuple_GET_ITEM(args, 1); |
Pablo Galindo | 3f5fc70 | 2018-12-30 09:24:03 +0000 | [diff] [blame] | 40 | return_value = tuplegetter_new_impl(type, index, doc); |
| 41 | |
| 42 | exit: |
| 43 | return return_value; |
| 44 | } |
Serhiy Storchaka | 4fa9591 | 2019-01-11 16:01:14 +0200 | [diff] [blame] | 45 | /*[clinic end generated code: output=51bd572577ca7111 input=a9049054013a1b77]*/ |