Skip to content

[3.7] bpo-35441: Remove dead and buggy code related to PyList_SetItem(). (GH-11033) #11037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2018
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
15 changes: 4 additions & 11 deletions Modules/_localemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,13 @@ copy_grouping(const char* s)
do {
i++;
val = PyLong_FromLong(s[i]);
if (!val)
break;
if (PyList_SetItem(result, i, val)) {
Py_DECREF(val);
val = NULL;
break;
if (val == NULL) {
Py_DECREF(result);
return NULL;
}
PyList_SET_ITEM(result, i, val);
} while (s[i] != '\0' && s[i] != CHAR_MAX);

if (!val) {
Py_DECREF(result);
return NULL;
}

return result;
}

Expand Down
11 changes: 8 additions & 3 deletions Modules/arraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1544,12 +1544,18 @@ array_array_fromlist(arrayobject *self, PyObject *list)
if (array_resize(self, old_size + n) == -1)
return NULL;
for (i = 0; i < n; i++) {
PyObject *v = PyList_GetItem(list, i);
PyObject *v = PyList_GET_ITEM(list, i);
if ((*self->ob_descr->setitem)(self,
Py_SIZE(self) - n + i, v) != 0) {
array_resize(self, old_size);
return NULL;
}
if (n != PyList_GET_SIZE(list)) {
PyErr_SetString(PyExc_RuntimeError,
"list changed size during iteration");
array_resize(self, old_size);
return NULL;
}
}
}
Py_RETURN_NONE;
Expand All @@ -1574,8 +1580,7 @@ array_array_tolist_impl(arrayobject *self)
PyObject *v = getarrayitem((PyObject *)self, i);
if (v == NULL)
goto error;
if (PyList_SetItem(list, i, v) < 0)
goto error;
PyList_SET_ITEM(list, i, v);
}
return list;

Expand Down
3 changes: 1 addition & 2 deletions Modules/readline.c
Original file line number Diff line number Diff line change
Expand Up @@ -936,8 +936,7 @@ on_completion_display_matches_hook(char **matches,
s = decode(matches[i+1]);
if (s == NULL)
goto error;
if (PyList_SetItem(m, i, s) == -1)
goto error;
PyList_SET_ITEM(m, i, s);
}
sub = decode(matches[0]);
r = PyObject_CallFunction(readlinestate_global->completion_display_matches_hook,
Expand Down
10 changes: 2 additions & 8 deletions Modules/selectmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,10 +652,7 @@ poll_poll(pollObject *self, PyObject *args)
goto error;
}
PyTuple_SET_ITEM(value, 1, num);
if ((PyList_SetItem(result_list, j, value)) == -1) {
Py_DECREF(value);
goto error;
}
PyList_SET_ITEM(result_list, j, value);
i++;
}
return result_list;
Expand Down Expand Up @@ -981,10 +978,7 @@ devpoll_poll(devpollObject *self, PyObject *args)
Py_DECREF(num2);
if (value == NULL)
goto error;
if ((PyList_SetItem(result_list, i, value)) == -1) {
Py_DECREF(value);
goto error;
}
PyList_SET_ITEM(result_list, i, value);
}

return result_list;
Expand Down
10 changes: 7 additions & 3 deletions PC/winreg.c
Original file line number Diff line number Diff line change
Expand Up @@ -757,9 +757,13 @@ Reg2Py(BYTE *retDataBuf, DWORD retDataSize, DWORD typ)
PyMem_Free(str);
return NULL;
}
PyList_SetItem(obData,
index,
PyUnicode_FromWideChar(str[index], len));
PyObject *uni = PyUnicode_FromWideChar(str[index], len);
if (uni == NULL) {
Py_DECREF(obData);
PyMem_Free(str);
return NULL;
}
PyList_SET_ITEM(obData, index, uni);
}
PyMem_Free(str);

Expand Down
4 changes: 2 additions & 2 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -5056,7 +5056,7 @@ getarray(long a[256])
Py_DECREF(l);
return NULL;
}
PyList_SetItem(l, i, x);
PyList_SET_ITEM(l, i, x);
}
for (i = 0; i < 256; i++)
a[i] = 0;
Expand All @@ -5078,7 +5078,7 @@ _Py_GetDXProfile(PyObject *self, PyObject *args)
Py_DECREF(l);
return NULL;
}
PyList_SetItem(l, i, x);
PyList_SET_ITEM(l, i, x);
}
return l;
#endif
Expand Down
2 changes: 1 addition & 1 deletion Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2544,7 +2544,7 @@ makepathobject(const wchar_t *path, wchar_t delim)
Py_DECREF(v);
return NULL;
}
PyList_SetItem(v, i, w);
PyList_SET_ITEM(v, i, w);
if (*p == '\0')
break;
path = p+1;
Expand Down