Skip to content

Commit e1616cf

Browse files
committed
Template/Interpolation AC vectorcall
1 parent 1cc5802 commit e1616cf

4 files changed

Lines changed: 144 additions & 17 deletions

File tree

‎Objects/clinic/interpolationobject.c.h‎

Lines changed: 64 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Objects/clinic/templateobject.c.h‎

Lines changed: 55 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Objects/interpolationobject.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ typedef struct {
5050
(assert(_PyInterpolation_CheckExact(op)), _Py_CAST(interpolationobject*, (op)))
5151

5252
/*[clinic input]
53+
@vectorcall
5354
@classmethod
5455
Interpolation.__new__ as interpolation_new
5556
@@ -63,7 +64,7 @@ static PyObject *
6364
interpolation_new_impl(PyTypeObject *type, PyObject *value,
6465
PyObject *expression, PyObject *conversion,
6566
PyObject *format_spec)
66-
/*[clinic end generated code: output=6488e288765bc1a9 input=fc5c285c1dd23d36]*/
67+
/*[clinic end generated code: output=6488e288765bc1a9 input=de7e890ea8f801e5]*/
6768
{
6869
interpolationobject *self = PyObject_GC_New(interpolationobject, type);
6970
if (!self) {
@@ -150,6 +151,7 @@ PyTypeObject _PyInterpolation_Type = {
150151
.tp_itemsize = 0,
151152
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
152153
.tp_new = interpolation_new,
154+
.tp_vectorcall = interpolation_vectorcall,
153155
.tp_alloc = PyType_GenericAlloc,
154156
.tp_dealloc = interpolation_dealloc,
155157
.tp_clear = interpolation_clear,

‎Objects/templateobject.c‎

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
#include "pycore_runtime.h" // _Py_STR()
66
#include "pycore_template.h"
77

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+
815
typedef struct {
916
PyObject_HEAD
1017
PyObject *stringsiter;
@@ -89,21 +96,24 @@ typedef struct {
8996
#define templateobject_CAST(op) \
9097
(assert(_PyTemplate_CheckExact(op)), _Py_CAST(templateobject*, (op)))
9198

99+
/*[clinic input]
100+
@vectorcall
101+
@classmethod
102+
Template.__new__ as template_new
103+
*args: array
104+
[clinic start generated code]*/
105+
92106
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]*/
94110
{
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);
101111
Py_ssize_t stringslen = 0;
102112
Py_ssize_t interpolationslen = 0;
103113
int last_was_str = 0;
104114

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];
107117
if (PyUnicode_Check(item)) {
108118
if (!last_was_str) {
109119
stringslen++;
@@ -142,8 +152,8 @@ template_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
142152

143153
last_was_str = 0;
144154
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];
147157
if (PyUnicode_Check(item)) {
148158
if (last_was_str) {
149159
PyObject *laststring = PyTuple_GET_ITEM(strings, stringsidx - 1);
@@ -391,6 +401,7 @@ PyTypeObject _PyTemplate_Type = {
391401
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
392402
.tp_as_sequence = &template_as_sequence,
393403
.tp_new = template_new,
404+
.tp_vectorcall = template_vectorcall,
394405
.tp_alloc = PyType_GenericAlloc,
395406
.tp_dealloc = template_dealloc,
396407
.tp_clear = template_clear,

0 commit comments

Comments
 (0)