Skip to content
Merged
Changes from 6 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
13 changes: 10 additions & 3 deletions Modules/arraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3053,21 +3053,24 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
len = 0;

a = newarrayobject(type, len, descr);
if (a == NULL)
if (a == NULL) {
Py_XDECREF(it);
return NULL;
}

if (len > 0 && !array_Check(initial, state)) {
Py_ssize_t i;
for (i = 0; i < len; i++) {
PyObject *v =
PySequence_GetItem(initial, i);
PyObject *v = PySequence_GetItem(initial, i);
Comment thread
skirpichev marked this conversation as resolved.
Outdated
if (v == NULL) {
Py_DECREF(a);
Py_XDECREF(it);
return NULL;
Comment on lines 3067 to 3069
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a common part for most cleanups. You can add a label and use goto statements in other places.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to refactor now.

}
if (setarrayitem(a, i, v) != 0) {
Py_DECREF(v);
Py_DECREF(a);
Py_XDECREF(it);
return NULL;
}
Py_DECREF(v);
Expand All @@ -3079,6 +3082,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
v = array_array_frombytes((PyObject *)a, initial);
if (v == NULL) {
Py_DECREF(a);
Py_XDECREF(it);
return NULL;
}
Py_DECREF(v);
Expand All @@ -3089,6 +3093,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
wchar_t *ustr = PyUnicode_AsWideCharString(initial, &n);
if (ustr == NULL) {
Py_DECREF(a);
Py_XDECREF(it);
return NULL;
}

Expand All @@ -3109,6 +3114,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Py_UCS4 *ustr = PyUnicode_AsUCS4Copy(initial);
if (ustr == NULL) {
Py_DECREF(a);
Py_XDECREF(it);
return NULL;
}

Expand Down Expand Up @@ -3136,6 +3142,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return a;
}
}
Py_XDECREF(it);
PyErr_SetString(PyExc_ValueError,
"bad typecode (must be b, B, u, w, h, H, i, I, l, L, q, Q, f or d)");
return NULL;
Expand Down
Loading