[Bf-blender-cvs] [efa7aaa97f5] master: Cleanup: use const variables where possible in the Python API
Campbell Barton
noreply at git.blender.org
Thu Aug 20 08:16:35 CEST 2020
Commit: efa7aaa97f5c2a6073017a15f1b1d98fdc451ba5
Author: Campbell Barton
Date: Thu Aug 20 16:10:13 2020 +1000
Branches: master
https://developer.blender.org/rBefa7aaa97f5c2a6073017a15f1b1d98fdc451ba5
Cleanup: use const variables where possible in the Python API
===================================================================
M source/blender/python/bmesh/bmesh_py_ops_call.c
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_select.c
M source/blender/python/generic/bgl.c
M source/blender/python/generic/idprop_py_api.c
M source/blender/python/generic/imbuf_py_api.c
M source/blender/python/generic/py_capi_utils.c
M source/blender/python/gpu/gpu_py_shader.c
M source/blender/python/gpu/gpu_py_vertex_buffer.c
M source/blender/python/gpu/gpu_py_vertex_format.c
M source/blender/python/intern/bpy_app.c
M source/blender/python/intern/bpy_app_handlers.c
M source/blender/python/intern/bpy_app_icons.c
M source/blender/python/intern/bpy_app_opensubdiv.c
M source/blender/python/intern/bpy_app_timers.c
M source/blender/python/intern/bpy_app_translations.c
M source/blender/python/intern/bpy_driver.c
M source/blender/python/intern/bpy_interface.c
M source/blender/python/intern/bpy_library_load.c
M source/blender/python/intern/bpy_msgbus.c
M source/blender/python/intern/bpy_props.c
M source/blender/python/intern/bpy_rna.c
M source/blender/python/intern/bpy_rna_anim.c
M source/blender/python/intern/bpy_rna_array.c
M source/blender/python/intern/bpy_rna_callback.c
M source/blender/python/intern/bpy_rna_driver.c
M source/blender/python/intern/bpy_rna_gizmo.c
M source/blender/python/mathutils/mathutils.c
M source/blender/python/mathutils/mathutils_Color.c
M source/blender/python/mathutils/mathutils_Matrix.c
M source/blender/python/mathutils/mathutils_Vector.c
M source/blender/python/mathutils/mathutils_bvhtree.c
M source/blender/python/mathutils/mathutils_geometry.c
M source/blender/python/mathutils/mathutils_kdtree.c
===================================================================
diff --git a/source/blender/python/bmesh/bmesh_py_ops_call.c b/source/blender/python/bmesh/bmesh_py_ops_call.c
index a387ba31c84..d0676ec1947 100644
--- a/source/blender/python/bmesh/bmesh_py_ops_call.c
+++ b/source/blender/python/bmesh/bmesh_py_ops_call.c
@@ -228,7 +228,7 @@ static int bpy_slot_from_py(BMesh *bm,
break;
}
case BMO_OP_SLOT_FLT: {
- float param = PyFloat_AsDouble(value);
+ const float param = PyFloat_AsDouble(value);
if (param == -1 && PyErr_Occurred()) {
PyErr_Format(PyExc_TypeError,
"%.200s: keyword \"%.200s\" expected a float, not %.200s",
@@ -840,7 +840,7 @@ PyObject *BPy_BMO_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject *kw)
{
char slot_name_strip[MAX_SLOTNAME];
const char *ch = strchr(slot->slot_name, '.'); /* can't fail! */
- int tot = ch - slot->slot_name;
+ const int tot = ch - slot->slot_name;
BLI_assert(ch != NULL);
memcpy(slot_name_strip, slot->slot_name, tot);
slot_name_strip[tot] = '\0';
diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c
index 04bceb17c20..2b174de7136 100644
--- a/source/blender/python/bmesh/bmesh_py_types.c
+++ b/source/blender/python/bmesh/bmesh_py_types.c
@@ -1093,7 +1093,7 @@ static PyObject *bpy_bmesh_from_object(BPy_BMesh *self, PyObject *args, PyObject
bool use_deform = true;
bool use_cage = false;
bool use_fnorm = true;
- CustomData_MeshMasks data_masks = CD_MASK_BMESH;
+ const CustomData_MeshMasks data_masks = CD_MASK_BMESH;
BPY_BM_CHECK_OBJ(self);
@@ -1346,7 +1346,7 @@ static PyObject *bpy_bmesh_transform(BPy_BMElem *self, PyObject *args, PyObject
}
}
else {
- char filter_flags_ch = (char)filter_flags;
+ const char filter_flags_ch = (char)filter_flags;
BM_ITER_MESH (eve, &iter, self->bm, BM_VERTS_OF_MESH) {
if (BM_elem_flag_test(eve, filter_flags_ch)) {
mul_m4_v3((float(*)[4])mat_ptr, eve->co);
@@ -3222,7 +3222,7 @@ static PyObject *bpy_bmelemseq_subscript(BPy_BMElemSeq *self, PyObject *key)
{
/* don't need error check here */
if (PyIndex_Check(key)) {
- Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
+ const Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
if (i == -1 && PyErr_Occurred()) {
return NULL;
}
@@ -3255,7 +3255,7 @@ static PyObject *bpy_bmelemseq_subscript(BPy_BMElemSeq *self, PyObject *key)
if (start < 0 || stop < 0) {
/* only get the length for negative values */
- Py_ssize_t len = bpy_bmelemseq_length(self);
+ const Py_ssize_t len = bpy_bmelemseq_length(self);
if (start < 0) {
start += len;
}
diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c b/source/blender/python/bmesh/bmesh_py_types_customdata.c
index 51616030d30..a9a9a3ad5d9 100644
--- a/source/blender/python/bmesh/bmesh_py_types_customdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_customdata.c
@@ -714,7 +714,7 @@ static PyObject *bpy_bmlayercollection_subscript_slice(BPy_BMLayerCollection *se
Py_ssize_t start,
Py_ssize_t stop)
{
- Py_ssize_t len = bpy_bmlayercollection_length(self);
+ const Py_ssize_t len = bpy_bmlayercollection_length(self);
int count = 0;
PyObject *tuple;
@@ -746,7 +746,7 @@ static PyObject *bpy_bmlayercollection_subscript(BPy_BMLayerCollection *self, Py
return bpy_bmlayercollection_subscript_str(self, _PyUnicode_AsString(key));
}
if (PyIndex_Check(key)) {
- Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
+ const Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
if (i == -1 && PyErr_Occurred()) {
return NULL;
}
@@ -779,7 +779,7 @@ static PyObject *bpy_bmlayercollection_subscript(BPy_BMLayerCollection *self, Py
if (start < 0 || stop < 0) {
/* only get the length for negative values */
- Py_ssize_t len = bpy_bmlayercollection_length(self);
+ const Py_ssize_t len = bpy_bmlayercollection_length(self);
if (start < 0) {
start += len;
}
@@ -1127,7 +1127,7 @@ int BPy_BMLayerItem_SetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer, PyObj
}
case CD_PROP_FLOAT:
case CD_PAINT_MASK: {
- float tmp_val = PyFloat_AsDouble(py_value);
+ const float tmp_val = PyFloat_AsDouble(py_value);
if (UNLIKELY(tmp_val == -1 && PyErr_Occurred())) {
PyErr_Format(
PyExc_TypeError, "expected a float, not a %.200s", Py_TYPE(py_value)->tp_name);
@@ -1140,7 +1140,7 @@ int BPy_BMLayerItem_SetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer, PyObj
}
case CD_PROP_INT32:
case CD_FACEMAP: {
- int tmp_val = PyC_Long_AsI32(py_value);
+ const int tmp_val = PyC_Long_AsI32(py_value);
if (UNLIKELY(tmp_val == -1 && PyErr_Occurred())) {
/* error is set */
ret = -1;
@@ -1187,7 +1187,7 @@ int BPy_BMLayerItem_SetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer, PyObj
break;
}
case CD_BWEIGHT: {
- float tmp_val = PyFloat_AsDouble(py_value);
+ const float tmp_val = PyFloat_AsDouble(py_value);
if (UNLIKELY(tmp_val == -1 && PyErr_Occurred())) {
PyErr_Format(
PyExc_TypeError, "expected a float, not a %.200s", Py_TYPE(py_value)->tp_name);
@@ -1199,7 +1199,7 @@ int BPy_BMLayerItem_SetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer, PyObj
break;
}
case CD_CREASE: {
- float tmp_val = PyFloat_AsDouble(py_value);
+ const float tmp_val = PyFloat_AsDouble(py_value);
if (UNLIKELY(tmp_val == -1 && PyErr_Occurred())) {
PyErr_Format(
PyExc_TypeError, "expected a float, not a %.200s", Py_TYPE(py_value)->tp_name);
diff --git a/source/blender/python/bmesh/bmesh_py_types_select.c b/source/blender/python/bmesh/bmesh_py_types_select.c
index d69668341ff..9bb9815f731 100644
--- a/source/blender/python/bmesh/bmesh_py_types_select.c
+++ b/source/blender/python/bmesh/bmesh_py_types_select.c
@@ -246,7 +246,7 @@ static PyObject *bpy_bmeditselseq_subscript(BPy_BMEditSelSeq *self, PyObject *ke
{
/* don't need error check here */
if (PyIndex_Check(key)) {
- Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
+ const Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
if (i == -1 && PyErr_Occurred()) {
return NULL;
}
@@ -279,7 +279,7 @@ static PyObject *bpy_bmeditselseq_subscript(BPy_BMEditSelSeq *self, PyObject *ke
if (start < 0 || stop < 0) {
/* only get the length for negative values */
- Py_ssize_t len = bpy_bmeditselseq_length(self);
+ const Py_ssize_t len = bpy_bmeditselseq_length(self);
if (start < 0) {
start += len;
}
diff --git a/source/blender/python/generic/bgl.c b/source/blender/python/generic/bgl.c
index 405541554c9..89fe9f8c6aa 100644
--- a/source/blender/python/generic/bgl.c
+++ b/source/blender/python/generic/bgl.c
@@ -461,7 +461,7 @@ int BGL_typeSize(int type)
static int gl_buffer_type_from_py_buffer(Py_buffer *pybuffer)
{
const char format = PyC_StructFmt_type_from_str(pybuffer->format);
- Py_ssize_t itemsize = pybuffer->itemsize;
+ const Py_ssize_t itemsize = pybuffer->itemsize;
if (PyC_StructFmt_type_is_float_any(format)) {
if (itemsize == 4) {
@@ -705,7 +705,7 @@ static int BGL_BufferOrOffsetConverter(PyObject *object, BufferOrOffset *buffer)
return 1;
}
if (PyNumber_Check(object)) {
- Py_ssize_t offset = PyNumber_AsSsize_t(object, PyExc_IndexError);
+ const Py_ssize_t offset = PyNumber_AsSsize_t(object, PyExc_IndexError);
if (offset == -1 && PyErr_Occurred()) {
return 0;
}
@@ -907,7 +907,7 @@ static int Buffer_ass_item(Buffer *self, int i, PyObject *v)
Buffer *row = (Buffer *)Buffer_item(self, i);
if (row) {
- int ret = Buffer_ass_slice(row, 0, self->dimensions[1], v);
+ const int ret = Buffer_ass_slice(row, 0, self->dimensions[1], v);
Py_DECREF(row);
return ret;
}
diff --git a/source/blender/python/generic/idprop_py_api.c b/source/blender/python/generic/idprop_py_api.c
index 615ce514a3e..314a34e3dec 100644
--- a/source/blender/python/generic/idprop_py_api.c
+++ b/source/blender/python/generic/idprop_py_api.c
@@ -435,7 +435,7 @@ static IDProperty *idp_from_PyBytes(const char *name, PyObject *ob)
static int idp_array_type_from_formatstr_and_size(const char *typestr, Py_ssize_t itemsize)
{
- char format = PyC_StructFmt_type_from_str(typestr);
+ const char format = PyC_StructFmt_type_from_str(typestr);
if (PyC_StructFmt_type_is_float_any(format)) {
if (itemsize == 4) {
@@ -473,7 +473,7 @@ static IDProperty *idp_from_PySequence_Buffer(const char *name, Py_buffer *buffe
IDProperty *prop;
IDPropertyTemplate val = {0};
- int id_type = idp_array_type_from_formatstr_and_size(buffer->format, buffer->itemsize);
+ const int id_type = idp_array_type_from_formatstr_and_size(buffer->format, buffer->itemsize);
if (id_type == -1) {
/* should never happen as the type has been checked before */
return NULL;
@@ -560,7 +560,7 @@ static IDProperty *idp_from_PySequence(const char *name, PyObject *ob)
if (PyObject_CheckBuffer(ob)) {
PyObject_GetBuffer(ob, &buffer, PyBUF_SIMPLE | PyBUF_FORMAT);
- char format = PyC_StructFmt_type_from_str(buffer.format);
+ const char format = PyC_StructFmt_type_from_str(buffer.format);
if (PyC_StructFmt_type_is_float_any(format) ||
(PyC_StructFmt_type_is_int_any(format) && buffer.itemsize == 4)) {
use_buffer = true;
@@ -589,7 +589,7 @@ static IDProperty *idp_from_PySequence(const char *name, PyObject *ob)
static IDProperty *idp_from_PyMapping(const char *name, PyObject *ob)
{
IDProperty *prop;
- IDPropertyTemplate val = {0};
+ const IDPropertyTemplate val = {0};
PyObject *keys, *vals, *key, *pval;
int i, len;
@@ -1559,8 +1559,8 @@ static int itemsize_by_idarray_type(int array_type)
static int BPy_IDArray_getbuffer(BPy_IDArray *self, Py_buffer *view, int flags)
{
IDProperty *prop =
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list