8000 Minor fixes (mostly cosmetic) · python/cpython@8f8a414 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 8f8a414

Browse files
committed
Minor fixes (mostly cosmetic)
1 parent c833f6d commit 8f8a414

File tree

2 files changed

+28
-45
lines changed

2 files changed

+28
-45
lines changed

Objects/interpolationobject.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ interpolation_new_impl(PyTypeObject *type, PyObject *value,
6767
return NULL;
6868
}
6969

70-
Py_XSETREF(self->value, Py_NewRef(value));
71-
Py_XSETREF(self->expression, Py_NewRef(expression));
72-
Py_XSETREF(self->conversion, Py_NewRef(conversion));
73-
Py_XSETREF(self->format_spec, Py_NewRef(format_spec));
70+
self->value = Py_NewRef(value);
71+
self->expression = Py_NewRef(expression);
72+
self->conversion = Py_NewRef(conversion);
73+
self->format_spec = Py_NewRef(format_spec);
7474
return (PyObject *) self;
7575
}
7676

Objects/templateobject.c

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,23 @@ typedef struct {
6868
} templateobject;
6969

7070
static templateobject *
71-
template_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
71+
template_from_strings_interpolations(PyTypeObject *type, PyObject *strings, PyObject *interpolations)
7272
{
73-
if (kwds != NULL) {
74-
PyErr_SetString(PyExc_TypeError, "Template.__new__ only accepts *args arguments");
73+
templateobject *template = (templateobject *) type->tp_alloc(type, 0);
74+
if (template == NULL) {
7575
return NULL;
7676
}
7777

78-
templateobject *self = (templateobject *) type->tp_alloc(type, 0);
79-
if (!self) {
78+
template->strings = Py_NewRef(strings);
79+
template->interpolations = Py_NewRef(interpolations);
80+
return template;
81+
}
82+
83+
static templateobject *
84+
template_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
85+
{
86+
if (kwds != NULL) {
87+
PyErr_SetString(PyExc_TypeError, "Template.__new__ only accepts *args arguments");
8088
return NULL;
8189
}
8290

@@ -101,7 +109,6 @@ template_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
101109
last_was_str = 0;
102110
}
103111
else {
104-
Py_DECREF(self);
105112
PyErr_SetString(PyExc_TypeError, "Template.__new__ *args need to be of type 'str' or 'Interpolation'");
106113
return NULL;
107114
}
@@ -112,13 +119,11 @@ template_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
112119

113120
PyObject *strings = PyTuple_New(stringslen);
114121
if (!strings) {
115-
Py_DECREF(self);
116122
return NULL;
117123
}
118124

119125
PyObject *interpolations = PyTuple_New(interpolationslen);
120126
if (!interpolations) {
121-
Py_DECREF(self);
122127
Py_DECREF(strings);
123128
return NULL;
124129
}
@@ -133,7 +138,9 @@ template_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
133138
PyObject *concat = PyUnicode_Concat(laststring, item);
134139
Py_DECREF(laststring);
135140
if (!concat) {
136-
goto error;
141+
Py_DECREF(strings);
142+
Py_DECREF(interpolations);
143+
return NULL;
137144
}
138145
PyTuple_SET_ITEM(strings, stringsidx - 1, concat);
139146
}
@@ -154,15 +161,10 @@ template_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
154161
PyTuple_SET_ITEM(strings, stringsidx++, &_Py_STR(empty));
155162
}
156163

157-
self->strings = strings;
158-
self->interpolations = interpolations;
159-
return self;
160-
161-
error:
162-
Py_DECREF(self);
164+
templateobject *template = template_from_strings_interpolations(type, strings, interpolations);
163165
Py_DECREF(strings);
164166
Py_DECREF(interpolations);
165-
return NULL;
167+
return template;
166168
}
167169

168170
static void
@@ -219,19 +221,6 @@ template_iter(templateobject *self)
219221
return iter;
220222
}
221223

222-
static PyObject *
223-
template_from_strings_interpolations(PyTypeObject *type, PyObject *strings, PyObject *interpolations)
224-
{
225-
PyObject *template = type->tp_alloc(type, 0);
226-
if (template == NULL) {
227-
return NULL;
228-
}
229-
230-
((templateobject *) template)->strings = Py_NewRef(strings);
231-
((templateobject *) template)->interpolations = Py_NewRef(interpolations);
232-
return template;
233-
}
234-
235224
static PyObject *
236225
template_interpolations_copy(PyObject *interpolations) {
237226
Py_ssize_t interpolationslen = PyTuple_GET_SIZE(interpolations);
@@ -360,12 +349,10 @@ template_concat_templates(templateobject *self, templateobject *other)
360349
return NULL;
361350
}
362351

363-
PyObject *newtemplate = template_from_strings_interpolations(Py_TYPE(self), newstrings, newinterpolations);
364-
352+
templateobject *newtemplate = template_from_strings_interpolations(Py_TYPE(self), newstrings, newinterpolations);
365353
Py_DECREF(newstrings);
366354
Py_DECREF(newinterpolations);
367-
368-
return newtemplate;
355+
return (PyObject *) newtemplate;
369356
}
370357

371358
static PyObject *
@@ -382,12 +369,10 @@ template_concat_template_str(templateobject *self, PyObject *other)
382369
return NULL;
383370
}
384371

385-
PyObject *newtemplate = template_from_strings_interpolations(Py_TYPE(self), newstrings, newinterpolations);
386-
372+
templateobject *newtemplate = template_from_strings_interpolations(Py_TYPE(self), newstrings, newinterpolations);
387373
Py_DECREF(newstrings);
388374
Py_DECREF(newinterpolations);
389-
390-
return newtemplate;
375+
return (PyObject *) newtemplate;
391376
}
392377

393378
static PyObject *
@@ -404,12 +389,10 @@ template_concat_str_template(templateobject *self, PyObject *other)
404389
return NULL;
405390
}
406391

407-
PyObject *newtemplate = template_from_strings_interpolations(Py_TYPE(self), newstrings, newinterpolations);
408-
392+
templateobject *newtemplate = template_from_strings_interpolations(Py_TYPE(self), newstrings, newinterpolations);
409393
Py_DECREF(newstrings);
410394
Py_DECREF(newinterpolations);
411-
412-
return newtemplate;
395+
return (PyObject *) newtemplate;
413396
}
414397

415398
PyObject *

0 commit comments

Comments
 (0)
0