Skip to content

Commit 7794862

Browse files
author
Rémi Lapeyre
committed
Fix coding style issues and use Python memory allocator
1 parent 9986e86 commit 7794862

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

Objects/exceptions.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,11 @@ BaseException_repr(PyBaseExceptionObject *self)
176176
}
177177
key = PyTuple_GET_ITEM(item, 0);
178178
value = PyTuple_GET_ITEM(item, 1);
179-
PyTuple_SET_ITEM(seq, i, PyUnicode_FromFormat("%S=%R", key, value));
179+
repr = PyUnicode_FromFormat("%S=%R", key, value);
180+
if (repr == NULL) {
181+
goto fail;
182+
}
183+
PyTuple_SET_ITEM(seq, i, repr);
180184
i++;
181185
Py_DECREF(item);
182186
}
@@ -221,36 +225,41 @@ BaseException_reduce(PyBaseExceptionObject *self, PyObject *Py_UNUSED(ignored))
221225
PyObject *functools;
222226
PyObject *partial;
223227
PyObject *constructor;
224-
PyObject *args;
225228
PyObject *result;
226229
PyObject **newargs;
227230

228231
_Py_IDENTIFIER(partial);
229232
functools = PyImport_ImportModule("functools");
230-
if (!functools)
233+
if (functools == NULL) {
231234
return NULL;
235+
}
232236
partial = _PyObject_GetAttrId(functools, &PyId_partial);
233237
Py_DECREF(functools);
234-
if (!partial)
238+
if (partial == NULL) {
235239
return NULL;
240+
}
236241

237242
Py_ssize_t len = 1;
238243
if (PyTuple_Check(self->args)) {
239244
len += PyTuple_GET_SIZE(self->args);
240245
}
241-
newargs = PyMem_RawMalloc(len*sizeof(PyObject*));
246+
newargs = PyMem_New(PyObject *, len);
247+
if (newargs == NULL) {
248+
PyErr_NoMemory();
249+
return NULL;
250+
}
242251
newargs[0] = (PyObject *)Py_TYPE(self);
243252

244253
for (Py_ssize_t i=1; i < len; i++) {
245254
newargs[i] = PyTuple_GetItem(self->args, i-1);
246255
}
247256
constructor = _PyObject_FastCallDict(partial, newargs, len, self->kwargs);
248-
PyMem_RawFree(newargs);
257+
PyMem_Free(newargs);
249258

250259
Py_DECREF(partial);
251260

252-
args = PyTuple_New(0);
253-
if (!args) {
261+
PyObject *args = PyTuple_New(0);
262+
if (args == NULL) {
254263
return NULL;
255264
}
256265
if (self->args && self->dict){

0 commit comments

Comments
 (0)