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:
2022-11-08 12:03:38 +11:00
parent 1140e001a0
commit 8f439bdc2d
15 changed files with 50 additions and 49 deletions

View File

@@ -351,13 +351,13 @@ static Py_hash_t Color_hash(ColorObject *self)
* \{ */
/** Sequence length: `len(object)`. */
static int Color_len(ColorObject *UNUSED(self))
static Py_ssize_t Color_len(ColorObject *UNUSED(self))
{
return COLOR_SIZE;
}
/** Sequence accessor (get): `x = object[i]`. */
static PyObject *Color_item(ColorObject *self, int i)
static PyObject *Color_item(ColorObject *self, Py_ssize_t i)
{
if (i < 0) {
i = COLOR_SIZE - i;
@@ -378,7 +378,7 @@ static PyObject *Color_item(ColorObject *self, int i)
}
/** Sequence accessor (set): `object[i] = x`. */
static int Color_ass_item(ColorObject *self, int i, PyObject *value)
static int Color_ass_item(ColorObject *self, Py_ssize_t i, PyObject *value)
{
float f;

View File

@@ -434,13 +434,13 @@ static Py_hash_t Euler_hash(EulerObject *self)
* \{ */
/** Sequence length: `len(object)`. */
static int Euler_len(EulerObject *UNUSED(self))
static Py_ssize_t Euler_len(EulerObject *UNUSED(self))
{
return EULER_SIZE;
}
/** Sequence accessor (get): `x = object[i]`. */
static PyObject *Euler_item(EulerObject *self, int i)
static PyObject *Euler_item(EulerObject *self, Py_ssize_t i)
{
if (i < 0) {
i = EULER_SIZE - i;
@@ -461,7 +461,7 @@ static PyObject *Euler_item(EulerObject *self, int i)
}
/** Sequence accessor (set): `object[i] = x`. */
static int Euler_ass_item(EulerObject *self, int i, PyObject *value)
static int Euler_ass_item(EulerObject *self, Py_ssize_t i, PyObject *value)
{
float f;

View File

@@ -2379,7 +2379,7 @@ static Py_hash_t Matrix_hash(MatrixObject *self)
* \{ */
/** Sequence length: `len(object)`. */
static int Matrix_len(MatrixObject *self)
static Py_ssize_t Matrix_len(MatrixObject *self)
{
return self->row_num;
}
@@ -2388,7 +2388,7 @@ static int Matrix_len(MatrixObject *self)
* Sequence accessor (get): `x = object[i]`.
* \note the wrapped vector gives direct access to the matrix data.
*/
static PyObject *Matrix_item_row(MatrixObject *self, int row)
static PyObject *Matrix_item_row(MatrixObject *self, Py_ssize_t row)
{
if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return NULL;
@@ -2407,7 +2407,7 @@ static PyObject *Matrix_item_row(MatrixObject *self, int row)
* Sequence accessor (get): `x = object.col[i]`.
* \note the wrapped vector gives direct access to the matrix data.
*/
static PyObject *Matrix_item_col(MatrixObject *self, int col)
static PyObject *Matrix_item_col(MatrixObject *self, Py_ssize_t col)
{
if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return NULL;
@@ -3625,15 +3625,15 @@ static int MatrixAccess_len(MatrixAccessObject *self)
return (self->type == MAT_ACCESS_ROW) ? self->matrix_user->row_num : self->matrix_user->col_num;
}
static PyObject *MatrixAccess_slice(MatrixAccessObject *self, int begin, int end)
static PyObject *MatrixAccess_slice(MatrixAccessObject *self, Py_ssize_t begin, Py_ssize_t end)
{
PyObject *tuple;
int count;
Py_ssize_t count;
/* row/col access */
MatrixObject *matrix_user = self->matrix_user;
int matrix_access_len;
PyObject *(*Matrix_item_new)(MatrixObject *, int);
PyObject *(*Matrix_item_new)(MatrixObject *, Py_ssize_t);
if (self->type == MAT_ACCESS_ROW) {
matrix_access_len = matrix_user->row_num;

View File

@@ -881,13 +881,13 @@ static Py_hash_t Quaternion_hash(QuaternionObject *self)
* \{ */
/** Sequence length: `len(object)`. */
static int Quaternion_len(QuaternionObject *UNUSED(self))
static Py_ssize_t Quaternion_len(QuaternionObject *UNUSED(self))
{
return QUAT_SIZE;
}
/** Sequence accessor (get): `x = object[i]`. */
static PyObject *Quaternion_item(QuaternionObject *self, int i)
static PyObject *Quaternion_item(QuaternionObject *self, Py_ssize_t i)
{
if (i < 0) {
i = QUAT_SIZE - i;
@@ -908,7 +908,7 @@ static PyObject *Quaternion_item(QuaternionObject *self, int i)
}
/** Sequence accessor (set): `object[i] = x`. */
static int Quaternion_ass_item(QuaternionObject *self, int i, PyObject *ob)
static int Quaternion_ass_item(QuaternionObject *self, Py_ssize_t i, PyObject *ob)
{
float f;

View File

@@ -1667,7 +1667,7 @@ static Py_hash_t Vector_hash(VectorObject *self)
* \{ */
/** Sequence length: `len(object)`. */
static int Vector_len(VectorObject *self)
static Py_ssize_t Vector_len(VectorObject *self)
{
return self->vec_num;
}
@@ -1699,7 +1699,7 @@ static PyObject *vector_item_internal(VectorObject *self, int i, const bool is_a
}
/** Sequence accessor (get): `x = object[i]`. */
static PyObject *Vector_item(VectorObject *self, int i)
static PyObject *Vector_item(VectorObject *self, Py_ssize_t i)
{
return vector_item_internal(self, i, false);
}
@@ -1747,7 +1747,7 @@ static int vector_ass_item_internal(VectorObject *self, int i, PyObject *value,
}
/** Sequence accessor (set): `object[i] = x`. */
static int Vector_ass_item(VectorObject *self, int i, PyObject *value)
static int Vector_ass_item(VectorObject *self, Py_ssize_t i, PyObject *value)
{
return vector_ass_item_internal(self, i, value, false);
}