/src/cpython/Objects/clinic/sliceobject.c.h
Line | Count | Source |
1 | | /*[clinic input] |
2 | | preserve |
3 | | [clinic start generated code]*/ |
4 | | |
5 | | #include "pycore_modsupport.h" // _PyArg_CheckPositional() |
6 | | |
7 | | static PyObject * |
8 | | slice_new_impl(PyTypeObject *type, PyObject *start, PyObject *stop, |
9 | | PyObject *step); |
10 | | |
11 | | static PyObject * |
12 | | slice_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
13 | 0 | { |
14 | 0 | PyObject *return_value = NULL; |
15 | 0 | PyTypeObject *base_tp = &PySlice_Type; |
16 | 0 | PyObject *start; |
17 | 0 | PyObject *stop = NULL; |
18 | 0 | PyObject *step = NULL; |
19 | |
|
20 | 0 | if ((type == base_tp || type->tp_init == base_tp->tp_init) && |
21 | 0 | !_PyArg_NoKeywords("slice", kwargs)) { |
22 | 0 | goto exit; |
23 | 0 | } |
24 | 0 | if (!_PyArg_CheckPositional("slice", PyTuple_GET_SIZE(args), 1, 3)) { |
25 | 0 | goto exit; |
26 | 0 | } |
27 | 0 | start = PyTuple_GET_ITEM(args, 0); |
28 | 0 | if (PyTuple_GET_SIZE(args) < 2) { |
29 | 0 | goto skip_optional; |
30 | 0 | } |
31 | 0 | stop = PyTuple_GET_ITEM(args, 1); |
32 | 0 | if (PyTuple_GET_SIZE(args) < 3) { |
33 | 0 | goto skip_optional; |
34 | 0 | } |
35 | 0 | step = PyTuple_GET_ITEM(args, 2); |
36 | 0 | skip_optional: |
37 | 0 | return_value = slice_new_impl(type, start, stop, step); |
38 | |
|
39 | 0 | exit: |
40 | 0 | return return_value; |
41 | 0 | } |
42 | | |
43 | | static PyObject * |
44 | | slice_vectorcall(PyObject *type, PyObject *const *args, |
45 | | size_t nargsf, PyObject *kwnames) |
46 | 16 | { |
47 | 16 | PyObject *return_value = NULL; |
48 | 16 | Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); |
49 | 16 | PyObject *start; |
50 | 16 | PyObject *stop = NULL; |
51 | 16 | PyObject *step = NULL; |
52 | | |
53 | 16 | assert(_PyType_CAST(type)->tp_new == slice_new); |
54 | | /* Make sure the type object is immutable: the generated |
55 | | * vectorcall doesn't deal e.g. with users reassigning __init__. */ |
56 | 16 | assert(PyType_HasFeature(_PyType_CAST(type), Py_TPFLAGS_IMMUTABLETYPE)); |
57 | 16 | if (!_PyArg_NoKwnames("slice", kwnames)) { |
58 | 0 | goto exit; |
59 | 0 | } |
60 | 16 | if (!_PyArg_CheckPositional("slice", nargs, 1, 3)) { |
61 | 0 | goto exit; |
62 | 0 | } |
63 | 16 | start = args[0]; |
64 | 16 | if (nargs < 2) { |
65 | 8 | goto skip_optional; |
66 | 8 | } |
67 | 8 | stop = args[1]; |
68 | 8 | if (nargs < 3) { |
69 | 8 | goto skip_optional; |
70 | 8 | } |
71 | 0 | step = args[2]; |
72 | 16 | skip_optional: |
73 | 16 | return_value = slice_new_impl(_PyType_CAST(type), start, stop, step); |
74 | | |
75 | 16 | exit: |
76 | 16 | return return_value; |
77 | 16 | } |
78 | | /*[clinic end generated code: output=62159046029c6bdf input=a9049054013a1b77]*/ |