Skip to content

Commit 8b24ff3

Browse files
committed
Use Py_BuildValue and add error checking for _PyType_GetDict
1 parent e84778a commit 8b24ff3

File tree

1 file changed

+8
-39
lines changed

1 file changed

+8
-39
lines changed

Objects/interpolationobject.c

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -132,53 +132,22 @@ PyTypeObject _PyInterpolation_Type = {
132132
.tp_traverse = interpolation_traverse,
133133
};
134134

135-
static PyObject *
136-
_get_match_args(void)
137-
{
138-
PyObject *value = NULL, *expression = NULL, *conversion = NULL, *format_spec = NULL;
139-
PyObject *tuple = NULL;
140-
141-
value = PyUnicode_FromString("value");
142-
if (!value) {
143-
goto error;
144-
}
145-
expression = PyUnicode_FromString("expression");
146-
if (!expression) {
147-
goto error;
148-
}
149-
conversion = PyUnicode_FromString("conversion");
150-
if (!conversion) {
151-
goto error;
152-
}
153-
format_spec = PyUnicode_FromString("format_spec");
154-
if (!format_spec) {
155-
goto error;
156-
}
157-
158-
tuple = PyTuple_Pack(4, value, expression, conversion, format_spec);
159-
160-
error:
161-
Py_XDECREF(value);
162-
Py_XDECREF(expression);
163-
Py_XDECREF(conversion);
164-
Py_XDECREF(format_spec);
165-
return tuple;
166-
167-
}
168-
169135
PyStatus
170136
_PyInterpolation_InitTypes(PyInterpreterState *interp)
171137
{
172-
PyObject *tuple = _get_match_args();
138+
PyObject *tuple = Py_BuildValue("(ssss)", "value", "expression", "conversion", "format_spec");
173139
if (!tuple) {
174140
goto error;
175141
}
176142

177-
int status = PyDict_SetItemString(_PyType_GetDict(&_PyInterpolation_Type),
178-
"__match_args__",
179-
tuple);
180-
Py_DECREF(tuple);
143+
PyObject *dict = _PyType_GetDict(&_PyInterpolation_Type);
144+
if (!dict) {
145+
Py_DECREF(tuple);
146+
goto error;
147+
}
181148

149+
int status = PyDict_SetItemString(dict, "__match_args__", tuple);
150+
Py_DECREF(tuple);
182151
if (status < 0) {
183152
goto error;
184153
}

0 commit comments

Comments
 (0)