diff options
author | Campbell Barton <campbell@blender.org> | 2022-11-08 04:03:38 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2022-11-08 14:42:14 +0300 |
commit | 9822a79f909086e5347f6a2255ecf529d872bcd9 (patch) | |
tree | b9b55fb811fca7c88a7dafef4198f976014fad9a | |
parent | 0e2a400f1126a54d260a746df1dcdf5e2c6f5321 (diff) |
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.
15 files changed, 50 insertions, 49 deletions
diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp index c3884e73ebd..9684f96d586 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp @@ -89,7 +89,7 @@ static Py_ssize_t FEdge_sq_length(BPy_FEdge * /*self*/) return 2; } -static PyObject *FEdge_sq_item(BPy_FEdge *self, int keynum) +static PyObject *FEdge_sq_item(BPy_FEdge *self, Py_ssize_t keynum) { if (keynum < 0) { keynum += FEdge_sq_length(self); diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp index 2156a91b1f2..8acbfefa995 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp @@ -74,7 +74,7 @@ static Py_ssize_t Stroke_sq_length(BPy_Stroke *self) return self->s->strokeVerticesSize(); } -static PyObject *Stroke_sq_item(BPy_Stroke *self, int keynum) +static PyObject *Stroke_sq_item(BPy_Stroke *self, Py_ssize_t keynum) { if (keynum < 0) { keynum += Stroke_sq_length(self); diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c index fab23d06ab3..b76f66015a9 100644 --- a/source/blender/python/bmesh/bmesh_py_types.c +++ b/source/blender/python/bmesh/bmesh_py_types.c @@ -3118,7 +3118,7 @@ static Py_ssize_t bpy_bmelemseq_length(BPy_BMElemSeq *self) } } -static PyObject *bpy_bmelemseq_subscript_int(BPy_BMElemSeq *self, int keynum) +static PyObject *bpy_bmelemseq_subscript_int(BPy_BMElemSeq *self, Py_ssize_t keynum) { BPY_BM_CHECK_OBJ(self); diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c b/source/blender/python/bmesh/bmesh_py_types_customdata.c index 2d0e31b9e3f..1288083f8e7 100644 --- a/source/blender/python/bmesh/bmesh_py_types_customdata.c +++ b/source/blender/python/bmesh/bmesh_py_types_customdata.c @@ -740,7 +740,8 @@ static PyObject *bpy_bmlayercollection_subscript_str(BPy_BMLayerCollection *self return NULL; } -static PyObject *bpy_bmlayercollection_subscript_int(BPy_BMLayerCollection *self, int keynum) +static PyObject *bpy_bmlayercollection_subscript_int(BPy_BMLayerCollection *self, + Py_ssize_t keynum) { Py_ssize_t len; BPY_BM_CHECK_OBJ(self); diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.c b/source/blender/python/bmesh/bmesh_py_types_meshdata.c index c58c9caf0a8..9bd98f2df53 100644 --- a/source/blender/python/bmesh/bmesh_py_types_meshdata.c +++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.c @@ -391,7 +391,7 @@ typedef struct BPy_BMDeformVert { /* Mapping Protocols * ================= */ -static int bpy_bmdeformvert_len(BPy_BMDeformVert *self) +static Py_ssize_t bpy_bmdeformvert_len(BPy_BMDeformVert *self) { return self->data->totweight; } diff --git a/source/blender/python/bmesh/bmesh_py_types_select.c b/source/blender/python/bmesh/bmesh_py_types_select.c index 20bf06e8016..ed25caee74d 100644 --- a/source/blender/python/bmesh/bmesh_py_types_select.c +++ b/source/blender/python/bmesh/bmesh_py_types_select.c @@ -163,7 +163,7 @@ static Py_ssize_t bpy_bmeditselseq_length(BPy_BMEditSelSeq *self) return BLI_listbase_count(&self->bm->selected); } -static PyObject *bpy_bmeditselseq_subscript_int(BPy_BMEditSelSeq *self, int keynum) +static PyObject *bpy_bmeditselseq_subscript_int(BPy_BMEditSelSeq *self, Py_ssize_t keynum) { BMEditSelection *ese; diff --git a/source/blender/python/generic/bgl.c b/source/blender/python/generic/bgl.c index 9c4212ebad4..fe64b247d43 100644 --- a/source/blender/python/generic/bgl.c +++ b/source/blender/python/generic/bgl.c @@ -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); @@ -794,12 +794,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"); @@ -837,10 +837,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; @@ -854,13 +853,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"); @@ -895,10 +894,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; @@ -918,7 +918,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. " diff --git a/source/blender/python/generic/idprop_py_api.c b/source/blender/python/generic/idprop_py_api.c index 04ca712b3e5..9a6568355af 100644 --- a/source/blender/python/generic/idprop_py_api.c +++ b/source/blender/python/generic/idprop_py_api.c @@ -1695,12 +1695,12 @@ static PyMethodDef BPy_IDArray_methods[] = { {NULL, NULL, 0, NULL}, }; -static int BPy_IDArray_Len(BPy_IDArray *self) +static Py_ssize_t BPy_IDArray_Len(BPy_IDArray *self) { return self->prop->len; } -static PyObject *BPy_IDArray_GetItem(BPy_IDArray *self, int index) +static PyObject *BPy_IDArray_GetItem(BPy_IDArray *self, Py_ssize_t index) { if (index < 0 || index >= self->prop->len) { PyErr_SetString(PyExc_IndexError, "index out of range!"); @@ -1722,7 +1722,7 @@ static PyObject *BPy_IDArray_GetItem(BPy_IDArray *self, int index) return NULL; } -static int BPy_IDArray_SetItem(BPy_IDArray *self, int index, PyObject *value) +static int BPy_IDArray_SetItem(BPy_IDArray *self, Py_ssize_t index, PyObject *value) { if (index < 0 || index >= self->prop->len) { PyErr_SetString(PyExc_RuntimeError, "index out of range!"); diff --git a/source/blender/python/gpu/gpu_py_buffer.c b/source/blender/python/gpu/gpu_py_buffer.c index 3dc141f400d..51bda9b4941 100644 --- a/source/blender/python/gpu/gpu_py_buffer.c +++ b/source/blender/python/gpu/gpu_py_buffer.c @@ -159,7 +159,7 @@ static BPyGPUBuffer *pygpu_buffer_make_from_data(PyObject *parent, return buffer; } -static PyObject *pygpu_buffer__sq_item(BPyGPUBuffer *self, int i) +static PyObject *pygpu_buffer__sq_item(BPyGPUBuffer *self, Py_ssize_t i) { if (i >= self->shape[0] || i < 0) { PyErr_SetString(PyExc_IndexError, "array index out of range"); @@ -200,10 +200,10 @@ static PyObject *pygpu_buffer__sq_item(BPyGPUBuffer *self, int i) static PyObject *pygpu_buffer_to_list(BPyGPUBuffer *self) { - int i, len = self->shape[0]; + const Py_ssize_t len = self->shape[0]; PyObject *list = PyList_New(len); - for (i = 0; i < len; i++) { + for (Py_ssize_t i = 0; i < len; i++) { PyList_SET_ITEM(list, i, pygpu_buffer__sq_item(self, i)); } @@ -313,7 +313,7 @@ static PyObject *pygpu_buffer__tp_repr(BPyGPUBuffer *self) return repr; } -static int pygpu_buffer__sq_ass_item(BPyGPUBuffer *self, int i, PyObject *v); +static int pygpu_buffer__sq_ass_item(BPyGPUBuffer *self, Py_ssize_t i, PyObject *v); static int pygpu_buffer_ass_slice(BPyGPUBuffer *self, Py_ssize_t begin, @@ -430,7 +430,7 @@ static int pygpu_buffer__tp_is_gc(BPyGPUBuffer *self) /* BPyGPUBuffer sequence methods */ -static int pygpu_buffer__sq_length(BPyGPUBuffer *self) +static Py_ssize_t pygpu_buffer__sq_length(BPyGPUBuffer *self) { return self->shape[0]; } @@ -458,7 +458,7 @@ static PyObject *pygpu_buffer_slice(BPyGPUBuffer *self, Py_ssize_t begin, Py_ssi return list; } -static int pygpu_buffer__sq_ass_item(BPyGPUBuffer *self, int i, PyObject *v) +static int pygpu_buffer__sq_ass_item(BPyGPUBuffer *self, Py_ssize_t i, PyObject *v) { if (i >= self->shape[0] || i < 0) { PyErr_SetString(PyExc_IndexError, "array assignment index out of range"); diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 4b767926f7a..ffcc210301c 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -2328,7 +2328,7 @@ static int pyrna_prop_collection_ass_subscript_int(BPy_PropertyRNA *self, return 0; } -static PyObject *pyrna_prop_array_subscript_int(BPy_PropertyArrayRNA *self, int keynum) +static PyObject *pyrna_prop_array_subscript_int(BPy_PropertyArrayRNA *self, Py_ssize_t keynum) { int len; @@ -2883,7 +2883,7 @@ static PyObject *pyrna_prop_array_subscript(BPy_PropertyArrayRNA *self, PyObject if (key_slice->start == Py_None && key_slice->stop == Py_None) { /* NOTE: no significant advantage with optimizing [:] slice as with collections, * but include here for consistency with collection slice func */ - const Py_ssize_t len = (Py_ssize_t)pyrna_prop_array_length(self); + const Py_ssize_t len = pyrna_prop_array_length(self); return pyrna_prop_array_subscript_slice(self, &self->ptr, self->prop, 0, len, len); } diff --git a/source/blender/python/mathutils/mathutils_Color.c b/source/blender/python/mathutils/mathutils_Color.c index e4f1ea87563..1a1ea1a2535 100644 --- a/source/blender/python/mathutils/mathutils_Color.c +++ b/source/blender/python/mathutils/mathutils_Color.c @@ -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; diff --git a/source/blender/python/mathutils/mathutils_Euler.c b/source/blender/python/mathutils/mathutils_Euler.c index d72ec5bbc77..551e5d6706d 100644 --- a/source/blender/python/mathutils/mathutils_Euler.c +++ b/source/blender/python/mathutils/mathutils_Euler.c @@ -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; diff --git a/source/blender/python/mathutils/mathutils_Matrix.c b/source/blender/python/mathutils/mathutils_Matrix.c index 858b01b2a84..21ad79bc94d 100644 --- a/source/blender/python/mathutils/mathutils_Matrix.c +++ b/source/blender/python/mathutils/mathutils_Matrix.c @@ -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; @@ -3633,15 +3633,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; diff --git a/source/blender/python/mathutils/mathutils_Quaternion.c b/source/blender/python/mathutils/mathutils_Quaternion.c index 4c64746b764..f2348713433 100644 --- a/source/blender/python/mathutils/mathutils_Quaternion.c +++ b/source/blender/python/mathutils/mathutils_Quaternion.c @@ -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; diff --git a/source/blender/python/mathutils/mathutils_Vector.c b/source/blender/python/mathutils/mathutils_Vector.c index 0f534e76e73..c5a002a6058 100644 --- a/source/blender/python/mathutils/mathutils_Vector.c +++ b/source/blender/python/mathutils/mathutils_Vector.c @@ -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); } |