[Bf-blender-cvs] [8f439bdc2de] blender-v3.4-release: Fix invalid function signatures for PySequenceMethods callbacks

Campbell Barton noreply at git.blender.org
Tue Nov 8 02:17:39 CET 2022


Commit: 8f439bdc2de1f964c8037448796a3f03a9cce4fe
Author: Campbell Barton
Date:   Tue Nov 8 12:03:38 2022 +1100
Branches: blender-v3.4-release
https://developer.blender.org/rB8f439bdc2de1f964c8037448796a3f03a9cce4fe

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.

===================================================================

M	source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp
M	source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp
M	source/blender/python/bmesh/bmesh_py_types.c
M	source/blender/python/bmesh/bmesh_py_types_customdata.c
M	source/blender/python/bmesh/bmesh_py_types_meshdata.c
M	source/blender/python/bmesh/bmesh_py_types_select.c
M	source/blender/python/generic/bgl.c
M	source/blender/python/generic/idprop_py_api.c
M	source/blender/python/gpu/gpu_py_buffer.c
M	source/blender/python/intern/bpy_rna.c
M	source/blender/python/mathutils/mathutils_Color.c
M	source/blender/python/mathutils/mathutils_Euler.c
M	source/blender/python/mathutils/mathutils_Matrix.c
M	source/blender/python/mathutils/mathutils_Quaternion.c
M	source/blender/python/mathutils/mathutils_Vector.c

===================================================================

diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp
index f73c4a8fed5..bf527673f36 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 6f90406d74d..3e7d4fd9e1c 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 364adb5458b..5c9c83f2e6e 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 58bfb922327..00b8f579021 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 9f200734786..fc2e70221a0 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 93bce055b12..01d555c00ca 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 fd5f2e77672..07ee3ed8752 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);
 
@@ -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. "
diff --git a/source/blender/python/generic/idprop_py_api.c b/source/blender/python/generic/idprop_py_api.c
index 3978f7f37cc..9ffea65bf55 100644
--- a/source/blender/python/generic/idprop_py_api.c
+++ b/source/blender/python/generic/idprop_py_api.c
@@ -1703,12 +1703,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!");
@@ -1730,7 +1730,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 30a434f8667..cee8a1d349b 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 02f7e16e805..e6525db62a4 100644
--- a/source/blender/python/intern/b

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list