mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
bpo-30061: Check if PyObject_Size()/PySequence_Size()/PyMapping_Size() (#1096)
raised an error. Replace them with using concrete types API that never fails if appropriate.
This commit is contained in:
parent
c209b70d61
commit
bf623ae884
14 changed files with 108 additions and 48 deletions
|
@ -722,17 +722,22 @@ getenvironment(PyObject* environment)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
envsize = PyMapping_Length(environment);
|
||||
|
||||
keys = PyMapping_Keys(environment);
|
||||
values = PyMapping_Values(environment);
|
||||
if (!keys || !values)
|
||||
goto error;
|
||||
|
||||
envsize = PySequence_Fast_GET_SIZE(keys);
|
||||
if (PySequence_Fast_GET_SIZE(values) != envsize) {
|
||||
PyErr_SetString(PyExc_RuntimeError,
|
||||
"environment changed size during iteration");
|
||||
goto error;
|
||||
}
|
||||
|
||||
totalsize = 1; /* trailing null character */
|
||||
for (i = 0; i < envsize; i++) {
|
||||
PyObject* key = PyList_GET_ITEM(keys, i);
|
||||
PyObject* value = PyList_GET_ITEM(values, i);
|
||||
PyObject* key = PySequence_Fast_GET_ITEM(keys, i);
|
||||
PyObject* value = PySequence_Fast_GET_ITEM(values, i);
|
||||
|
||||
if (! PyUnicode_Check(key) || ! PyUnicode_Check(value)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
|
@ -760,8 +765,8 @@ getenvironment(PyObject* environment)
|
|||
end = buffer + totalsize;
|
||||
|
||||
for (i = 0; i < envsize; i++) {
|
||||
PyObject* key = PyList_GET_ITEM(keys, i);
|
||||
PyObject* value = PyList_GET_ITEM(values, i);
|
||||
PyObject* key = PySequence_Fast_GET_ITEM(keys, i);
|
||||
PyObject* value = PySequence_Fast_GET_ITEM(values, i);
|
||||
if (!PyUnicode_AsUCS4(key, p, end - p, 0))
|
||||
goto error;
|
||||
p += PyUnicode_GET_LENGTH(key);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue