Fix invalid function signatures for PySequenceMethods callbacks
Function casts hid casting between potentially incompatible type signatures (using int instead of Py_ssize_t). As it happens this seems not to have caused any bugs on supported platforms so this change is mainly for correctness and to avoid problems in the future.
This commit is contained in:
@@ -417,11 +417,11 @@ static PyObject *Method_ShaderSource(PyObject *self, PyObject *args);
|
||||
|
||||
/* Buffer sequence methods */
|
||||
|
||||
static int Buffer_len(Buffer *self);
|
||||
static PyObject *Buffer_item(Buffer *self, int i);
|
||||
static PyObject *Buffer_slice(Buffer *self, int begin, int end);
|
||||
static int Buffer_ass_item(Buffer *self, int i, PyObject *v);
|
||||
static int Buffer_ass_slice(Buffer *self, int begin, int end, PyObject *seq);
|
||||
static Py_ssize_t Buffer_len(Buffer *self);
|
||||
static PyObject *Buffer_item(Buffer *self, Py_ssize_t i);
|
||||
static PyObject *Buffer_slice(Buffer *self, Py_ssize_t begin, Py_ssize_t end);
|
||||
static int Buffer_ass_item(Buffer *self, Py_ssize_t i, PyObject *v);
|
||||
static int Buffer_ass_slice(Buffer *self, Py_ssize_t begin, Py_ssize_t end, PyObject *seq);
|
||||
static PyObject *Buffer_subscript(Buffer *self, PyObject *item);
|
||||
static int Buffer_ass_subscript(Buffer *self, PyObject *item, PyObject *value);
|
||||
|
||||
@@ -811,12 +811,12 @@ static PyObject *Buffer_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject
|
||||
|
||||
/* Buffer sequence methods */
|
||||
|
||||
static int Buffer_len(Buffer *self)
|
||||
static Py_ssize_t Buffer_len(Buffer *self)
|
||||
{
|
||||
return self->dimensions[0];
|
||||
}
|
||||
|
||||
static PyObject *Buffer_item(Buffer *self, int i)
|
||||
static PyObject *Buffer_item(Buffer *self, Py_ssize_t i)
|
||||
{
|
||||
if (i >= self->dimensions[0] || i < 0) {
|
||||
PyErr_SetString(PyExc_IndexError, "array index out of range");
|
||||
@@ -854,10 +854,9 @@ static PyObject *Buffer_item(Buffer *self, int i)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static PyObject *Buffer_slice(Buffer *self, int begin, int end)
|
||||
static PyObject *Buffer_slice(Buffer *self, Py_ssize_t begin, Py_ssize_t end)
|
||||
{
|
||||
PyObject *list;
|
||||
int count;
|
||||
|
||||
if (begin < 0) {
|
||||
begin = 0;
|
||||
@@ -871,13 +870,13 @@ static PyObject *Buffer_slice(Buffer *self, int begin, int end)
|
||||
|
||||
list = PyList_New(end - begin);
|
||||
|
||||
for (count = begin; count < end; count++) {
|
||||
for (Py_ssize_t count = begin; count < end; count++) {
|
||||
PyList_SET_ITEM(list, count - begin, Buffer_item(self, count));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
static int Buffer_ass_item(Buffer *self, int i, PyObject *v)
|
||||
static int Buffer_ass_item(Buffer *self, Py_ssize_t i, PyObject *v)
|
||||
{
|
||||
if (i >= self->dimensions[0] || i < 0) {
|
||||
PyErr_SetString(PyExc_IndexError, "array assignment index out of range");
|
||||
@@ -912,10 +911,11 @@ static int Buffer_ass_item(Buffer *self, int i, PyObject *v)
|
||||
}
|
||||
}
|
||||
|
||||
static int Buffer_ass_slice(Buffer *self, int begin, int end, PyObject *seq)
|
||||
static int Buffer_ass_slice(Buffer *self, Py_ssize_t begin, Py_ssize_t end, PyObject *seq)
|
||||
{
|
||||
PyObject *item;
|
||||
int count, err = 0;
|
||||
int err = 0;
|
||||
Py_ssize_t count;
|
||||
|
||||
if (begin < 0) {
|
||||
begin = 0;
|
||||
@@ -935,7 +935,7 @@ static int Buffer_ass_slice(Buffer *self, int begin, int end, PyObject *seq)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* re-use count var */
|
||||
/* Re-use count variable. */
|
||||
if ((count = PySequence_Size(seq)) != (end - begin)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"buffer[:] = value, size mismatch in assignment. "
|
||||
|
||||
Reference in New Issue
Block a user