Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 64 additions & 5 deletions Objects/clinic/interpolationobject.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions Objects/clinic/templateobject.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Objects/interpolationobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ typedef struct {
(assert(_PyInterpolation_CheckExact(op)), _Py_CAST(interpolationobject*, (op)))

/*[clinic input]
@vectorcall
@classmethod
Interpolation.__new__ as interpolation_new
Expand All @@ -63,7 +64,7 @@ static PyObject *
interpolation_new_impl(PyTypeObject *type, PyObject *value,
PyObject *expression, PyObject *conversion,
PyObject *format_spec)
/*[clinic end generated code: output=6488e288765bc1a9 input=fc5c285c1dd23d36]*/
/*[clinic end generated code: output=6488e288765bc1a9 input=de7e890ea8f801e5]*/
{
interpolationobject *self = PyObject_GC_New(interpolationobject, type);
if (!self) {
Expand Down Expand Up @@ -150,6 +151,7 @@ PyTypeObject _PyInterpolation_Type = {
.tp_itemsize = 0,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
.tp_new = interpolation_new,
.tp_vectorcall = interpolation_vectorcall,
.tp_alloc = PyType_GenericAlloc,
.tp_dealloc = interpolation_dealloc,
.tp_clear = interpolation_clear,
Expand Down
33 changes: 22 additions & 11 deletions Objects/templateobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
#include "pycore_runtime.h" // _Py_STR()
#include "pycore_template.h"

#include "clinic/templateobject.c.h"

/*[clinic input]
class Template "templateobject *" "&_PyTemplate_Type"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=ee41f8d8c49f0271]*/

typedef struct {
PyObject_HEAD
PyObject *stringsiter;
Expand Down Expand Up @@ -89,21 +96,24 @@ typedef struct {
#define templateobject_CAST(op) \
(assert(_PyTemplate_CheckExact(op)), _Py_CAST(templateobject*, (op)))

/*[clinic input]
@vectorcall
@classmethod
Template.__new__ as template_new
*args: array
[clinic start generated code]*/

static PyObject *
template_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
template_new_impl(PyTypeObject *type, PyObject * const *args,
Py_ssize_t args_length)
/*[clinic end generated code: output=5831a1056a1a68d5 input=65f04e91969ffccd]*/
{
if (kwds != NULL) {
PyErr_SetString(PyExc_TypeError, "Template.__new__ only accepts *args arguments");
return NULL;
}

Py_ssize_t argslen = PyTuple_GET_SIZE(args);
Py_ssize_t stringslen = 0;
Py_ssize_t interpolationslen = 0;
int last_was_str = 0;

for (Py_ssize_t i = 0; i < argslen; i++) {
PyObject *item = PyTuple_GET_ITEM(args, i);
for (Py_ssize_t i = 0; i < args_length; i++) {
PyObject *item = args[i];
if (PyUnicode_Check(item)) {
if (!last_was_str) {
stringslen++;
Expand Down Expand Up @@ -142,8 +152,8 @@ template_new(PyTypeObject *type, PyObject *args, PyObject *kwds)

last_was_str = 0;
Py_ssize_t stringsidx = 0, interpolationsidx = 0;
for (Py_ssize_t i = 0; i < argslen; i++) {
PyObject *item = PyTuple_GET_ITEM(args, i);
for (Py_ssize_t i = 0; i < args_length; i++) {
PyObject *item = args[i];
if (PyUnicode_Check(item)) {
if (last_was_str) {
PyObject *laststring = PyTuple_GET_ITEM(strings, stringsidx - 1);
Expand Down Expand Up @@ -391,6 +401,7 @@ PyTypeObject _PyTemplate_Type = {
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
.tp_as_sequence = &template_as_sequence,
.tp_new = template_new,
.tp_vectorcall = template_vectorcall,
.tp_alloc = PyType_GenericAlloc,
.tp_dealloc = template_dealloc,
.tp_clear = template_clear,
Expand Down
Loading