|
5 | 5 | #include "pycore_runtime.h" // _Py_STR() |
6 | 6 | #include "pycore_template.h" |
7 | 7 |
|
| 8 | +#include "clinic/templateobject.c.h" |
| 9 | + |
| 10 | +/*[clinic input] |
| 11 | +class Template "templateobject *" "&_PyTemplate_Type" |
| 12 | +[clinic start generated code]*/ |
| 13 | +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=ee41f8d8c49f0271]*/ |
| 14 | + |
8 | 15 | typedef struct { |
9 | 16 | PyObject_HEAD |
10 | 17 | PyObject *stringsiter; |
@@ -89,21 +96,24 @@ typedef struct { |
89 | 96 | #define templateobject_CAST(op) \ |
90 | 97 | (assert(_PyTemplate_CheckExact(op)), _Py_CAST(templateobject*, (op))) |
91 | 98 |
|
| 99 | +/*[clinic input] |
| 100 | +@vectorcall |
| 101 | +@classmethod |
| 102 | +Template.__new__ as template_new |
| 103 | + *args: array |
| 104 | +[clinic start generated code]*/ |
| 105 | + |
92 | 106 | static PyObject * |
93 | | -template_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 107 | +template_new_impl(PyTypeObject *type, PyObject * const *args, |
| 108 | + Py_ssize_t args_length) |
| 109 | +/*[clinic end generated code: output=5831a1056a1a68d5 input=65f04e91969ffccd]*/ |
94 | 110 | { |
95 | | - if (kwds != NULL) { |
96 | | - PyErr_SetString(PyExc_TypeError, "Template.__new__ only accepts *args arguments"); |
97 | | - return NULL; |
98 | | - } |
99 | | - |
100 | | - Py_ssize_t argslen = PyTuple_GET_SIZE(args); |
101 | 111 | Py_ssize_t stringslen = 0; |
102 | 112 | Py_ssize_t interpolationslen = 0; |
103 | 113 | int last_was_str = 0; |
104 | 114 |
|
105 | | - for (Py_ssize_t i = 0; i < argslen; i++) { |
106 | | - PyObject *item = PyTuple_GET_ITEM(args, i); |
| 115 | + for (Py_ssize_t i = 0; i < args_length; i++) { |
| 116 | + PyObject *item = args[i]; |
107 | 117 | if (PyUnicode_Check(item)) { |
108 | 118 | if (!last_was_str) { |
109 | 119 | stringslen++; |
@@ -142,8 +152,8 @@ template_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
142 | 152 |
|
143 | 153 | last_was_str = 0; |
144 | 154 | Py_ssize_t stringsidx = 0, interpolationsidx = 0; |
145 | | - for (Py_ssize_t i = 0; i < argslen; i++) { |
146 | | - PyObject *item = PyTuple_GET_ITEM(args, i); |
| 155 | + for (Py_ssize_t i = 0; i < args_length; i++) { |
| 156 | + PyObject *item = args[i]; |
147 | 157 | if (PyUnicode_Check(item)) { |
148 | 158 | if (last_was_str) { |
149 | 159 | PyObject *laststring = PyTuple_GET_ITEM(strings, stringsidx - 1); |
@@ -391,6 +401,7 @@ PyTypeObject _PyTemplate_Type = { |
391 | 401 | .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, |
392 | 402 | .tp_as_sequence = &template_as_sequence, |
393 | 403 | .tp_new = template_new, |
| 404 | + .tp_vectorcall = template_vectorcall, |
394 | 405 | .tp_alloc = PyType_GenericAlloc, |
395 | 406 | .tp_dealloc = template_dealloc, |
396 | 407 | .tp_clear = template_clear, |
|
0 commit comments