Merge 3.6

This commit is contained in:
INADA Naoki 2017-01-06 17:44:43 +09:00
commit 7ed28a8914
4 changed files with 41 additions and 18 deletions

View file

@ -798,18 +798,22 @@ bytearray_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds)
if (PyIndex_Check(arg)) {
count = PyNumber_AsSsize_t(arg, PyExc_OverflowError);
if (count == -1 && PyErr_Occurred()) {
return -1;
}
if (count < 0) {
PyErr_SetString(PyExc_ValueError, "negative count");
return -1;
}
if (count > 0) {
if (PyByteArray_Resize((PyObject *)self, count))
if (PyErr_ExceptionMatches(PyExc_OverflowError))
return -1;
memset(PyByteArray_AS_STRING(self), 0, count);
PyErr_Clear(); /* fall through */
}
else {
if (count < 0) {
PyErr_SetString(PyExc_ValueError, "negative count");
return -1;
}
if (count > 0) {
if (PyByteArray_Resize((PyObject *)self, count))
return -1;
memset(PyByteArray_AS_STRING(self), 0, count);
}
return 0;
}
return 0;
}
/* Use the buffer API */