Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-03-29 22:12:48 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-03-29 23:14:28 +0300
commit25ec4b437fe927205a810470cdc23efd7282c85b (patch)
tree6d7ba2fe73703915b4b94d3f2dab03fb731e9544
parent18d06e8d21ed8c9a19df4205abcd7ed17eb9af00 (diff)
Cleanup: style, use braces for the Python API
-rw-r--r--source/blender/python/bmesh/bmesh_py_ops.c6
-rw-r--r--source/blender/python/bmesh/bmesh_py_types.c99
-rw-r--r--source/blender/python/bmesh/bmesh_py_types_customdata.c34
-rw-r--r--source/blender/python/bmesh/bmesh_py_types_meshdata.c6
-rw-r--r--source/blender/python/bmesh/bmesh_py_types_select.c19
-rw-r--r--source/blender/python/generic/bgl.c77
-rw-r--r--source/blender/python/generic/blf_py_api.c42
-rw-r--r--source/blender/python/generic/bpy_internal_import.c24
-rw-r--r--source/blender/python/generic/idprop_py_api.c68
-rw-r--r--source/blender/python/generic/py_capi_utils.c24
-rw-r--r--source/blender/python/gpu/gpu_py_offscreen.c3
-rw-r--r--source/blender/python/gpu/gpu_py_types.c18
-rw-r--r--source/blender/python/intern/bpy.c26
-rw-r--r--source/blender/python/intern/bpy_app.c16
-rw-r--r--source/blender/python/intern/bpy_app_handlers.c3
-rw-r--r--source/blender/python/intern/bpy_app_translations.c15
-rw-r--r--source/blender/python/intern/bpy_capi_utils.c6
-rw-r--r--source/blender/python/intern/bpy_driver.c34
-rw-r--r--source/blender/python/intern/bpy_interface.c36
-rw-r--r--source/blender/python/intern/bpy_library_load.c3
-rw-r--r--source/blender/python/intern/bpy_operator.c6
-rw-r--r--source/blender/python/intern/bpy_operator_wrap.c3
-rw-r--r--source/blender/python/intern/bpy_props.c181
-rw-r--r--source/blender/python/intern/bpy_rna.c442
-rw-r--r--source/blender/python/intern/bpy_rna_anim.c21
-rw-r--r--source/blender/python/intern/bpy_rna_array.c32
-rw-r--r--source/blender/python/intern/bpy_rna_callback.c36
-rw-r--r--source/blender/python/intern/bpy_traceback.c24
-rw-r--r--source/blender/python/mathutils/mathutils.c31
-rw-r--r--source/blender/python/mathutils/mathutils_Color.c136
-rw-r--r--source/blender/python/mathutils/mathutils_Euler.c116
-rw-r--r--source/blender/python/mathutils/mathutils_Matrix.c317
-rw-r--r--source/blender/python/mathutils/mathutils_Quaternion.c209
-rw-r--r--source/blender/python/mathutils/mathutils_Vector.c250
-rw-r--r--source/blender/python/mathutils/mathutils_bvhtree.c6
-rw-r--r--source/blender/python/mathutils/mathutils_geometry.c24
-rw-r--r--source/blender/python/mathutils/mathutils_interpolate.c12
-rw-r--r--source/blender/python/mathutils/mathutils_kdtree.c12
-rw-r--r--source/blender/python/mathutils/mathutils_noise.c72
39 files changed, 1689 insertions, 800 deletions
diff --git a/source/blender/python/bmesh/bmesh_py_ops.c b/source/blender/python/bmesh/bmesh_py_ops.c
index fbd79f28ec7..f35bfb730ad 100644
--- a/source/blender/python/bmesh/bmesh_py_ops.c
+++ b/source/blender/python/bmesh/bmesh_py_ops.c
@@ -351,11 +351,13 @@ PyObject *BPyInit_bmesh_ops(void)
{
PyObject *submodule;
- if (PyType_Ready(&bmesh_ops_fakemod_Type) < 0)
+ if (PyType_Ready(&bmesh_ops_fakemod_Type) < 0) {
return NULL;
+ }
- if (PyType_Ready(&bmesh_op_Type) < 0)
+ if (PyType_Ready(&bmesh_op_Type) < 0) {
return NULL;
+ }
submodule = PyObject_New(PyObject, &bmesh_ops_fakemod_Type);
diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c
index 1addd9b84f7..366f0b4b3f7 100644
--- a/source/blender/python/bmesh/bmesh_py_types.c
+++ b/source/blender/python/bmesh/bmesh_py_types.c
@@ -1445,8 +1445,9 @@ static PyObject *bpy_bmvert_calc_edge_angle(BPy_BMVert *self, PyObject *args)
BPY_BM_CHECK_OBJ(self);
- if (!PyArg_ParseTuple(args, "|O:calc_edge_angle", &fallback))
+ if (!PyArg_ParseTuple(args, "|O:calc_edge_angle", &fallback)) {
return NULL;
+ }
angle = BM_vert_calc_edge_angle_ex(self->v, angle_invalid);
@@ -1530,8 +1531,9 @@ static PyObject *bpy_bmedge_calc_face_angle(BPy_BMEdge *self, PyObject *args)
BPY_BM_CHECK_OBJ(self);
- if (!PyArg_ParseTuple(args, "|O:calc_face_angle", &fallback))
+ if (!PyArg_ParseTuple(args, "|O:calc_face_angle", &fallback)) {
return NULL;
+ }
angle = BM_edge_calc_face_angle_ex(self->e, angle_invalid);
@@ -1569,8 +1571,9 @@ static PyObject *bpy_bmedge_calc_face_angle_signed(BPy_BMEdge *self, PyObject *a
BPY_BM_CHECK_OBJ(self);
- if (!PyArg_ParseTuple(args, "|O:calc_face_angle_signed", &fallback))
+ if (!PyArg_ParseTuple(args, "|O:calc_face_angle_signed", &fallback)) {
return NULL;
+ }
angle = BM_edge_calc_face_angle_signed_ex(self->e, angle_invalid);
@@ -2161,7 +2164,9 @@ static PyObject *bpy_bmedgeseq_new(BPy_BMElemSeq *self, PyObject *args)
ret = BPy_BMEdge_CreatePyObject(bm, e);
cleanup:
- if (vert_array) PyMem_FREE(vert_array);
+ if (vert_array) {
+ PyMem_FREE(vert_array);
+ }
return ret;
}
}
@@ -2239,7 +2244,9 @@ static PyObject *bpy_bmfaceseq_new(BPy_BMElemSeq *self, PyObject *args)
/* pass through */
cleanup:
- if (vert_array) PyMem_FREE(vert_array);
+ if (vert_array) {
+ PyMem_FREE(vert_array);
+ }
return ret;
}
}
@@ -2535,9 +2542,15 @@ static int bpy_bmelemseq_sort_cmp_by_keys_ascending(const void *index1_v, const
const int *index1 = (int *)index1_v;
const int *index2 = (int *)index2_v;
- if (keys[*index1] < keys[*index2]) return -1;
- else if (keys[*index1] > keys[*index2]) return 1;
- else return 0;
+ if (keys[*index1] < keys[*index2]) {
+ return -1;
+ }
+ else if (keys[*index1] > keys[*index2]) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
}
static int bpy_bmelemseq_sort_cmp_by_keys_descending(const void *index1_v, const void *index2_v, void *keys_v)
@@ -2646,10 +2659,12 @@ static PyObject *bpy_bmelemseq_sort(BPy_BMElemSeq *self, PyObject *args, PyObjec
range_vn_i(elem_idx, n_elem, 0);
/* Sort the index array according to the order of the 'keys' array */
- if (do_reverse)
+ if (do_reverse) {
elem_idx_compare_by_keys = bpy_bmelemseq_sort_cmp_by_keys_descending;
- else
+ }
+ else {
elem_idx_compare_by_keys = bpy_bmelemseq_sort_cmp_by_keys_ascending;
+ }
BLI_qsort_r(elem_idx, n_elem, sizeof(*elem_idx), elem_idx_compare_by_keys, keys);
@@ -2920,7 +2935,10 @@ static PyObject *bpy_bmelemseq_subscript_int(BPy_BMElemSeq *self, int keynum)
{
BPY_BM_CHECK_OBJ(self);
- if (keynum < 0) keynum += bpy_bmelemseq_length(self); /* only get length on negative value, may loop entire seq */
+ if (keynum < 0) {
+ /* only get length on negative value, may loop entire seq */
+ keynum += bpy_bmelemseq_length(self);
+ }
if (keynum >= 0) {
if (self->itype <= BM_FACES_OF_MESH) {
if ((self->bm->elem_table_dirty & bm_iter_itype_htype_map[self->itype]) == 0) {
@@ -3014,8 +3032,9 @@ 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);
- if (i == -1 && PyErr_Occurred())
+ if (i == -1 && PyErr_Occurred()) {
return NULL;
+ }
return bpy_bmelemseq_subscript_int(self, i);
}
else if (PySlice_Check(key)) {
@@ -3037,14 +3056,22 @@ static PyObject *bpy_bmelemseq_subscript(BPy_BMElemSeq *self, PyObject *key)
Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX;
/* avoid PySlice_GetIndicesEx because it needs to know the length ahead of time. */
- if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) return NULL;
- if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) return NULL;
+ if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) {
+ return NULL;
+ }
+ if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) {
+ return NULL;
+ }
if (start < 0 || stop < 0) {
/* only get the length for negative values */
Py_ssize_t len = bpy_bmelemseq_length(self);
- if (start < 0) start += len;
- if (stop < 0) stop += len;
+ if (start < 0) {
+ start += len;
+ }
+ if (stop < 0) {
+ stop += len;
+ }
}
if (stop - start <= 0) {
@@ -3162,10 +3189,18 @@ static void bpy_bmesh_dealloc(BPy_BMesh *self)
if (bm) {
bm_dealloc_editmode_warn(self);
- if (CustomData_has_layer(&bm->vdata, CD_BM_ELEM_PYPTR)) BM_data_layer_free(bm, &bm->vdata, CD_BM_ELEM_PYPTR);
- if (CustomData_has_layer(&bm->edata, CD_BM_ELEM_PYPTR)) BM_data_layer_free(bm, &bm->edata, CD_BM_ELEM_PYPTR);
- if (CustomData_has_layer(&bm->pdata, CD_BM_ELEM_PYPTR)) BM_data_layer_free(bm, &bm->pdata, CD_BM_ELEM_PYPTR);
- if (CustomData_has_layer(&bm->ldata, CD_BM_ELEM_PYPTR)) BM_data_layer_free(bm, &bm->ldata, CD_BM_ELEM_PYPTR);
+ if (CustomData_has_layer(&bm->vdata, CD_BM_ELEM_PYPTR)) {
+ BM_data_layer_free(bm, &bm->vdata, CD_BM_ELEM_PYPTR);
+ }
+ if (CustomData_has_layer(&bm->edata, CD_BM_ELEM_PYPTR)) {
+ BM_data_layer_free(bm, &bm->edata, CD_BM_ELEM_PYPTR);
+ }
+ if (CustomData_has_layer(&bm->pdata, CD_BM_ELEM_PYPTR)) {
+ BM_data_layer_free(bm, &bm->pdata, CD_BM_ELEM_PYPTR);
+ }
+ if (CustomData_has_layer(&bm->ldata, CD_BM_ELEM_PYPTR)) {
+ BM_data_layer_free(bm, &bm->ldata, CD_BM_ELEM_PYPTR);
+ }
bm->py_handle = NULL;
@@ -3182,8 +3217,9 @@ static void bpy_bmvert_dealloc(BPy_BMElem *self)
BMesh *bm = self->bm;
if (bm) {
void **ptr = CustomData_bmesh_get(&bm->vdata, self->ele->head.data, CD_BM_ELEM_PYPTR);
- if (ptr)
+ if (ptr) {
*ptr = NULL;
+ }
}
PyObject_DEL(self);
}
@@ -3193,8 +3229,9 @@ static void bpy_bmedge_dealloc(BPy_BMElem *self)
BMesh *bm = self->bm;
if (bm) {
void **ptr = CustomData_bmesh_get(&bm->edata, self->ele->head.data, CD_BM_ELEM_PYPTR);
- if (ptr)
+ if (ptr) {
*ptr = NULL;
+ }
}
PyObject_DEL(self);
}
@@ -3204,8 +3241,9 @@ static void bpy_bmface_dealloc(BPy_BMElem *self)
BMesh *bm = self->bm;
if (bm) {
void **ptr = CustomData_bmesh_get(&bm->pdata, self->ele->head.data, CD_BM_ELEM_PYPTR);
- if (ptr)
+ if (ptr) {
*ptr = NULL;
+ }
}
PyObject_DEL(self);
}
@@ -3215,8 +3253,9 @@ static void bpy_bmloop_dealloc(BPy_BMElem *self)
BMesh *bm = self->bm;
if (bm) {
void **ptr = CustomData_bmesh_get(&bm->ldata, self->ele->head.data, CD_BM_ELEM_PYPTR);
- if (ptr)
+ if (ptr) {
*ptr = NULL;
+ }
}
PyObject_DEL(self);
}
@@ -3938,7 +3977,9 @@ void *BPy_BMElem_PySeq_As_Array_FAST(
}
*r_size = seq_len;
- if (r_bm) *r_bm = bm;
+ if (r_bm) {
+ *r_bm = bm;
+ }
return alloc;
err_cleanup:
@@ -4042,10 +4083,10 @@ char *BPy_BMElem_StringFromHType_ex(const char htype, char ret[32])
{
/* zero to ensure string is always NULL terminated */
char *ret_ptr = ret;
- if (htype & BM_VERT) ret_ptr += sprintf(ret_ptr, "/%s", BPy_BMVert_Type.tp_name);
- if (htype & BM_EDGE) ret_ptr += sprintf(ret_ptr, "/%s", BPy_BMEdge_Type.tp_name);
- if (htype & BM_FACE) ret_ptr += sprintf(ret_ptr, "/%s", BPy_BMFace_Type.tp_name);
- if (htype & BM_LOOP) ret_ptr += sprintf(ret_ptr, "/%s", BPy_BMLoop_Type.tp_name);
+ if (htype & BM_VERT) { ret_ptr += sprintf(ret_ptr, "/%s", BPy_BMVert_Type.tp_name); }
+ if (htype & BM_EDGE) { ret_ptr += sprintf(ret_ptr, "/%s", BPy_BMEdge_Type.tp_name); }
+ if (htype & BM_FACE) { ret_ptr += sprintf(ret_ptr, "/%s", BPy_BMFace_Type.tp_name); }
+ if (htype & BM_LOOP) { ret_ptr += sprintf(ret_ptr, "/%s", BPy_BMLoop_Type.tp_name); }
ret[0] = '(';
*ret_ptr++ = ')';
*ret_ptr = '\0';
diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c b/source/blender/python/bmesh/bmesh_py_types_customdata.c
index c161b974eff..abe146f2581 100644
--- a/source/blender/python/bmesh/bmesh_py_types_customdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_customdata.c
@@ -615,7 +615,9 @@ static PyObject *bpy_bmlayercollection_subscript_int(BPy_BMLayerCollection *self
len = bpy_bmlayercollection_length(self);
- if (keynum < 0) keynum += len;
+ if (keynum < 0) {
+ keynum += len;
+ }
if (keynum >= 0) {
if (keynum < len) {
return BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, keynum);
@@ -636,8 +638,12 @@ static PyObject *bpy_bmlayercollection_subscript_slice(BPy_BMLayerCollection *se
BPY_BM_CHECK_OBJ(self);
- if (start >= len) start = len - 1;
- if (stop >= len) stop = len - 1;
+ if (start >= len) {
+ start = len - 1;
+ }
+ if (stop >= len) {
+ stop = len - 1;
+ }
tuple = PyTuple_New(stop - start);
@@ -656,8 +662,9 @@ static PyObject *bpy_bmlayercollection_subscript(BPy_BMLayerCollection *self, Py
}
else if (PyIndex_Check(key)) {
Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
- if (i == -1 && PyErr_Occurred())
+ if (i == -1 && PyErr_Occurred()) {
return NULL;
+ }
return bpy_bmlayercollection_subscript_int(self, i);
}
else if (PySlice_Check(key)) {
@@ -679,14 +686,22 @@ static PyObject *bpy_bmlayercollection_subscript(BPy_BMLayerCollection *self, Py
Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX;
/* avoid PySlice_GetIndicesEx because it needs to know the length ahead of time. */
- if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) return NULL;
- if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) return NULL;
+ if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) {
+ return NULL;
+ }
+ if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) {
+ return NULL;
+ }
if (start < 0 || stop < 0) {
/* only get the length for negative values */
Py_ssize_t len = bpy_bmlayercollection_length(self);
- if (start < 0) start += len;
- if (stop < 0) stop += len;
+ if (start < 0) {
+ start += len;
+ }
+ if (stop < 0) {
+ stop += len;
+ }
}
if (stop - start <= 0) {
@@ -1085,8 +1100,9 @@ int BPy_BMLayerItem_SetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer, PyObj
ret = -1;
}
else {
- if (tmp_val_len > sizeof(mstring->s))
+ if (tmp_val_len > sizeof(mstring->s)) {
tmp_val_len = sizeof(mstring->s);
+ }
memcpy(mstring->s, tmp_val, tmp_val_len);
mstring->s_len = tmp_val_len;
}
diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.c b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
index aba54c6c43a..604b55de6e6 100644
--- a/source/blender/python/bmesh/bmesh_py_types_meshdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
@@ -306,8 +306,9 @@ static int mathutils_bmloopcol_set(BaseMathObject *bmo, int UNUSED(subtype))
static int mathutils_bmloopcol_get_index(BaseMathObject *bmo, int subtype, int UNUSED(index))
{
/* lazy, avoid repeteing the case statement */
- if (mathutils_bmloopcol_get(bmo, subtype) == -1)
+ if (mathutils_bmloopcol_get(bmo, subtype) == -1) {
return -1;
+ }
return 0;
}
@@ -316,8 +317,9 @@ static int mathutils_bmloopcol_set_index(BaseMathObject *bmo, int subtype, int i
const float f = bmo->data[index];
/* lazy, avoid repeteing the case statement */
- if (mathutils_bmloopcol_get(bmo, subtype) == -1)
+ if (mathutils_bmloopcol_get(bmo, subtype) == -1) {
return -1;
+ }
bmo->data[index] = f;
return mathutils_bmloopcol_set(bmo, subtype);
diff --git a/source/blender/python/bmesh/bmesh_py_types_select.c b/source/blender/python/bmesh/bmesh_py_types_select.c
index ed631f7105b..e257c1bff4b 100644
--- a/source/blender/python/bmesh/bmesh_py_types_select.c
+++ b/source/blender/python/bmesh/bmesh_py_types_select.c
@@ -255,8 +255,9 @@ 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);
- if (i == -1 && PyErr_Occurred())
+ if (i == -1 && PyErr_Occurred()) {
return NULL;
+ }
return bpy_bmeditselseq_subscript_int(self, i);
}
else if (PySlice_Check(key)) {
@@ -278,14 +279,22 @@ static PyObject *bpy_bmeditselseq_subscript(BPy_BMEditSelSeq *self, PyObject *ke
Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX;
/* avoid PySlice_GetIndicesEx because it needs to know the length ahead of time. */
- if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) return NULL;
- if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) return NULL;
+ if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) {
+ return NULL;
+ }
+ if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) {
+ return NULL;
+ }
if (start < 0 || stop < 0) {
/* only get the length for negative values */
Py_ssize_t len = bpy_bmeditselseq_length(self);
- if (start < 0) start += len;
- if (stop < 0) stop += len;
+ if (start < 0) {
+ start += len;
+ }
+ if (stop < 0) {
+ stop += len;
+ }
}
if (stop - start <= 0) {
diff --git a/source/blender/python/generic/bgl.c b/source/blender/python/generic/bgl.c
index 13342b7dac8..b52326ed7a4 100644
--- a/source/blender/python/generic/bgl.c
+++ b/source/blender/python/generic/bgl.c
@@ -476,15 +476,25 @@ static int gl_buffer_type_from_py_buffer(Py_buffer *pybuffer)
Py_ssize_t itemsize = pybuffer->itemsize;
if (PyC_StructFmt_type_is_float_any(format)) {
- if (itemsize == 4) return GL_FLOAT;
- if (itemsize == 8) return GL_DOUBLE;
+ if (itemsize == 4) {
+ return GL_FLOAT;
+ }
+ if (itemsize == 8) {
+ return GL_DOUBLE;
+ }
}
if (PyC_StructFmt_type_is_byte(format) ||
PyC_StructFmt_type_is_int_any(format))
{
- if (itemsize == 1) return GL_BYTE;
- if (itemsize == 2) return GL_SHORT;
- if (itemsize == 4) return GL_INT;
+ if (itemsize == 1) {
+ return GL_BYTE;
+ }
+ if (itemsize == 2) {
+ return GL_SHORT;
+ }
+ if (itemsize == 4) {
+ return GL_INT;
+ }
}
return -1; /* UNKNOWN */
@@ -769,10 +779,12 @@ static PyObject *Buffer_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject
for (i = 0; i < ndimensions; i++) {
PyObject *ob = PySequence_GetItem(length_ob, i);
- if (!PyLong_Check(ob))
+ if (!PyLong_Check(ob)) {
dimensions[i] = 1;
- else
+ }
+ else {
dimensions[i] = PyLong_AsLong(ob);
+ }
Py_DECREF(ob);
if (dimensions[i] < 1) {
@@ -868,9 +880,15 @@ static PyObject *Buffer_slice(Buffer *self, int begin, int end)
PyObject *list;
int count;
- if (begin < 0) begin = 0;
- if (end > self->dimensions[0]) end = self->dimensions[0];
- if (begin > end) begin = end;
+ if (begin < 0) {
+ begin = 0;
+ }
+ if (end > self->dimensions[0]) {
+ end = self->dimensions[0];
+ }
+ if (begin > end) {
+ begin = end;
+ }
list = PyList_New(end - begin);
@@ -916,9 +934,15 @@ static int Buffer_ass_slice(Buffer *self, int begin, int end, PyObject *seq)
PyObject *item;
int count, err = 0;
- if (begin < 0) begin = 0;
- if (end > self->dimensions[0]) end = self->dimensions[0];
- if (begin > end) begin = end;
+ if (begin < 0) {
+ begin = 0;
+ }
+ if (end > self->dimensions[0]) {
+ end = self->dimensions[0];
+ }
+ if (begin > end) {
+ begin = end;
+ }
if (!PySequence_Check(seq)) {
PyErr_Format(PyExc_TypeError,
@@ -957,17 +981,20 @@ static PyObject *Buffer_subscript(Buffer *self, PyObject *item)
if (PyIndex_Check(item)) {
Py_ssize_t i;
i = PyNumber_AsSsize_t(item, PyExc_IndexError);
- if (i == -1 && PyErr_Occurred())
+ if (i == -1 && PyErr_Occurred()) {
return NULL;
- if (i < 0)
+ }
+ if (i < 0) {
i += self->dimensions[0];
+ }
return Buffer_item(self, i);
}
else if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelength;
- if (PySlice_GetIndicesEx(item, self->dimensions[0], &start, &stop, &step, &slicelength) < 0)
+ if (PySlice_GetIndicesEx(item, self->dimensions[0], &start, &stop, &step, &slicelength) < 0) {
return NULL;
+ }
if (slicelength <= 0) {
return PyTuple_New(0);
@@ -993,20 +1020,24 @@ static int Buffer_ass_subscript(Buffer *self, PyObject *item, PyObject *value)
{
if (PyIndex_Check(item)) {
Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
- if (i == -1 && PyErr_Occurred())
+ if (i == -1 && PyErr_Occurred()) {
return -1;
- if (i < 0)
+ }
+ if (i < 0) {
i += self->dimensions[0];
+ }
return Buffer_ass_item(self, i, value);
}
else if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelength;
- if (PySlice_GetIndicesEx(item, self->dimensions[0], &start, &stop, &step, &slicelength) < 0)
+ if (PySlice_GetIndicesEx(item, self->dimensions[0], &start, &stop, &step, &slicelength) < 0) {
return -1;
+ }
- if (step == 1)
+ if (step == 1) {
return Buffer_ass_slice(self, start, stop, value);
+ }
else {
PyErr_SetString(PyExc_IndexError,
"slice steps not supported with vectors");
@@ -1390,8 +1421,9 @@ PyObject *BPyInit_bgl(void)
submodule = PyModule_Create(&BGL_module_def);
dict = PyModule_GetDict(submodule);
- if (PyType_Ready(&BGL_bufferType) < 0)
+ if (PyType_Ready(&BGL_bufferType) < 0) {
return NULL; /* should never happen */
+ }
PyModule_AddObject(submodule, "Buffer", (PyObject *)&BGL_bufferType);
Py_INCREF((PyObject *)&BGL_bufferType);
@@ -2554,8 +2586,9 @@ static PyObject *Method_ShaderSource(PyObject *UNUSED(self), PyObject *args)
unsigned int shader;
const char *source;
- if (!PyArg_ParseTuple(args, "Is", &shader, &source))
+ if (!PyArg_ParseTuple(args, "Is", &shader, &source)) {
return NULL;
+ }
glShaderSource(shader, 1, (const char **)&source, NULL);
diff --git a/source/blender/python/generic/blf_py_api.c b/source/blender/python/generic/blf_py_api.c
index 79ffb9aa892..9161e5d979b 100644
--- a/source/blender/python/generic/blf_py_api.c
+++ b/source/blender/python/generic/blf_py_api.c
@@ -50,8 +50,9 @@ static PyObject *py_blf_position(PyObject *UNUSED(self), PyObject *args)
int fontid;
float x, y, z;
- if (!PyArg_ParseTuple(args, "ifff:blf.position", &fontid, &x, &y, &z))
+ if (!PyArg_ParseTuple(args, "ifff:blf.position", &fontid, &x, &y, &z)) {
return NULL;
+ }
BLF_position(fontid, x, y, z);
@@ -75,8 +76,9 @@ static PyObject *py_blf_size(PyObject *UNUSED(self), PyObject *args)
{
int fontid, size, dpi;
- if (!PyArg_ParseTuple(args, "iii:blf.size", &fontid, &size, &dpi))
+ if (!PyArg_ParseTuple(args, "iii:blf.size", &fontid, &size, &dpi)) {
return NULL;
+ }
BLF_size(fontid, size, dpi);
@@ -99,8 +101,9 @@ static PyObject *py_blf_aspect(PyObject *UNUSED(self), PyObject *args)
float aspect;
int fontid;
- if (!PyArg_ParseTuple(args, "if:blf.aspect", &fontid, &aspect))
+ if (!PyArg_ParseTuple(args, "if:blf.aspect", &fontid, &aspect)) {
return NULL;
+ }
BLF_aspect(fontid, aspect, aspect, 1.0);
@@ -157,8 +160,9 @@ static PyObject *py_blf_blur(PyObject *UNUSED(self), PyObject *args)
{
int blur, fontid;
- if (!PyArg_ParseTuple(args, "ii:blf.blur", &fontid, &blur))
+ if (!PyArg_ParseTuple(args, "ii:blf.blur", &fontid, &blur)) {
return NULL;
+ }
BLF_blur(fontid, blur);
@@ -183,8 +187,9 @@ static PyObject *py_blf_draw(PyObject *UNUSED(self), PyObject *args)
int text_length;
int fontid;
- if (!PyArg_ParseTuple(args, "is#:blf.draw", &fontid, &text, &text_length))
+ if (!PyArg_ParseTuple(args, "is#:blf.draw", &fontid, &text, &text_length)) {
return NULL;
+ }
BLF_draw(fontid, text, (unsigned int)text_length);
@@ -210,8 +215,9 @@ static PyObject *py_blf_dimensions(PyObject *UNUSED(self), PyObject *args)
PyObject *ret;
int fontid;
- if (!PyArg_ParseTuple(args, "is:blf.dimensions", &fontid, &text))
+ if (!PyArg_ParseTuple(args, "is:blf.dimensions", &fontid, &text)) {
return NULL;
+ }
BLF_width_and_height(fontid, text, INT_MAX, &r_width, &r_height);
@@ -243,8 +249,9 @@ static PyObject *py_blf_clipping(PyObject *UNUSED(self), PyObject *args)
float xmin, ymin, xmax, ymax;
int fontid;
- if (!PyArg_ParseTuple(args, "iffff:blf.clipping", &fontid, &xmin, &ymin, &xmax, &ymax))
+ if (!PyArg_ParseTuple(args, "iffff:blf.clipping", &fontid, &xmin, &ymin, &xmax, &ymax)) {
return NULL;
+ }
BLF_clipping(fontid, xmin, ymin, xmax, ymax);
@@ -266,8 +273,9 @@ static PyObject *py_blf_word_wrap(PyObject *UNUSED(self), PyObject *args)
int wrap_width;
int fontid;
- if (!PyArg_ParseTuple(args, "ii:blf.word_wrap", &fontid, &wrap_width))
+ if (!PyArg_ParseTuple(args, "ii:blf.word_wrap", &fontid, &wrap_width)) {
return NULL;
+ }
BLF_wordwrap(fontid, wrap_width);
@@ -288,8 +296,9 @@ static PyObject *py_blf_disable(PyObject *UNUSED(self), PyObject *args)
{
int option, fontid;
- if (!PyArg_ParseTuple(args, "ii:blf.disable", &fontid, &option))
+ if (!PyArg_ParseTuple(args, "ii:blf.disable", &fontid, &option)) {
return NULL;
+ }
BLF_disable(fontid, option);
@@ -310,8 +319,9 @@ static PyObject *py_blf_enable(PyObject *UNUSED(self), PyObject *args)
{
int option, fontid;
- if (!PyArg_ParseTuple(args, "ii:blf.enable", &fontid, &option))
+ if (!PyArg_ParseTuple(args, "ii:blf.enable", &fontid, &option)) {
return NULL;
+ }
BLF_enable(fontid, option);
@@ -333,8 +343,9 @@ static PyObject *py_blf_rotation(PyObject *UNUSED(self), PyObject *args)
float angle;
int fontid;
- if (!PyArg_ParseTuple(args, "if:blf.rotation", &fontid, &angle))
+ if (!PyArg_ParseTuple(args, "if:blf.rotation", &fontid, &angle)) {
return NULL;
+ }
BLF_rotation(fontid, angle);
@@ -397,8 +408,9 @@ static PyObject *py_blf_shadow_offset(PyObject *UNUSED(self), PyObject *args)
{
int x, y, fontid;
- if (!PyArg_ParseTuple(args, "iii:blf.shadow_offset", &fontid, &x, &y))
+ if (!PyArg_ParseTuple(args, "iii:blf.shadow_offset", &fontid, &x, &y)) {
return NULL;
+ }
BLF_shadow_offset(fontid, x, y);
@@ -419,8 +431,9 @@ static PyObject *py_blf_load(PyObject *UNUSED(self), PyObject *args)
{
const char *filename;
- if (!PyArg_ParseTuple(args, "s:blf.load", &filename))
+ if (!PyArg_ParseTuple(args, "s:blf.load", &filename)) {
return NULL;
+ }
return PyLong_FromLong(BLF_load(filename));
}
@@ -437,8 +450,9 @@ static PyObject *py_blf_unload(PyObject *UNUSED(self), PyObject *args)
{
const char *filename;
- if (!PyArg_ParseTuple(args, "s:blf.unload", &filename))
+ if (!PyArg_ParseTuple(args, "s:blf.unload", &filename)) {
return NULL;
+ }
BLF_unload(filename);
diff --git a/source/blender/python/generic/bpy_internal_import.c b/source/blender/python/generic/bpy_internal_import.c
index 96b5645f0e7..0baa4008f2d 100644
--- a/source/blender/python/generic/bpy_internal_import.c
+++ b/source/blender/python/generic/bpy_internal_import.c
@@ -180,8 +180,9 @@ PyObject *bpy_text_import_name(const char *name, int *found)
}
/* we know this cant be importable, the name is too long for blender! */
- if (namelen >= (MAX_ID_NAME - 2) - 3)
+ if (namelen >= (MAX_ID_NAME - 2) - 3) {
return NULL;
+ }
memcpy(txtname, name, namelen);
memcpy(&txtname[namelen], ".py", 4);
@@ -200,10 +201,12 @@ PyObject *bpy_text_import_name(const char *name, int *found)
maggie = maggie->next;
}
- if (!text)
+ if (!text) {
return NULL;
- else
+ }
+ else {
*found = 1;
+ }
return bpy_text_import(text);
}
@@ -229,8 +232,9 @@ PyObject *bpy_text_reimport(PyObject *module, int *found)
*found = 0;
/* get name, filename from the module itself */
- if ((name = PyModule_GetName(module)) == NULL)
+ if ((name = PyModule_GetName(module)) == NULL) {
return NULL;
+ }
{
PyObject *module_file = PyModule_GetFilenameObject(module);
@@ -248,10 +252,12 @@ PyObject *bpy_text_reimport(PyObject *module, int *found)
text = BLI_findstring(&maggie->texts, BLI_path_basename(filepath), offsetof(ID, name) + 2);
/* uh-oh.... didn't find it */
- if (!text)
+ if (!text) {
return NULL;
- else
+ }
+ else {
*found = 1;
+ }
if (bpy_text_compile(text) == false) {
return NULL;
@@ -283,8 +289,9 @@ static PyObject *blender_import(PyObject *UNUSED(self), PyObject *args, PyObject
/* import existing builtin modules or modules that have been imported already */
newmodule = PyImport_ImportModuleLevel(name, globals, locals, fromlist, level);
- if (newmodule)
+ if (newmodule) {
return newmodule;
+ }
PyErr_Fetch(&exception, &err, &tb); /* get the python error in case we cant import as blender text either */
@@ -330,8 +337,9 @@ static PyObject *blender_reload(PyObject *UNUSED(self), PyObject *module)
newmodule = PyObject_CallFunctionObjArgs(imp_reload_orig, module, NULL);
- if (newmodule)
+ if (newmodule) {
return newmodule;
+ }
/* no file, try importing from memory */
PyErr_Fetch(&exception, &err, &tb); /*restore for probable later use */
diff --git a/source/blender/python/generic/idprop_py_api.c b/source/blender/python/generic/idprop_py_api.c
index 6c5177d4759..f18d02a4405 100644
--- a/source/blender/python/generic/idprop_py_api.c
+++ b/source/blender/python/generic/idprop_py_api.c
@@ -419,11 +419,17 @@ static int idp_array_type_from_formatstr_and_size(const char *typestr, Py_ssize_
char format = PyC_StructFmt_type_from_str(typestr);
if (PyC_StructFmt_type_is_float_any(format)) {
- if (itemsize == 4) return IDP_FLOAT;
- if (itemsize == 8) return IDP_DOUBLE;
+ if (itemsize == 4) {
+ return IDP_FLOAT;
+ }
+ if (itemsize == 8) {
+ return IDP_DOUBLE;
+ }
}
if (PyC_StructFmt_type_is_int_any(format)) {
- if (itemsize == 4) return IDP_INT;
+ if (itemsize == 4) {
+ return IDP_INT;
+ }
}
return -1;
@@ -431,9 +437,15 @@ static int idp_array_type_from_formatstr_and_size(const char *typestr, Py_ssize_
static const char *idp_format_from_array_type(int type)
{
- if (type == IDP_INT) return "i";
- if (type == IDP_FLOAT) return "f";
- if (type == IDP_DOUBLE) return "d";
+ if (type == IDP_INT) {
+ return "i";
+ }
+ if (type == IDP_FLOAT) {
+ return "f";
+ }
+ if (type == IDP_DOUBLE) {
+ return "d";
+ }
return NULL;
}
@@ -936,8 +948,9 @@ PyObject *BPy_Wrap_GetKeys(IDProperty *prop)
IDProperty *loop;
int i;
- for (i = 0, loop = prop->data.group.first; loop && (i < prop->len); loop = loop->next, i++)
+ for (i = 0, loop = prop->data.group.first; loop && (i < prop->len); loop = loop->next, i++) {
PyList_SET_ITEM(list, i, PyUnicode_FromString(loop->name));
+ }
/* if the id prop is corrupt, count the remaining */
for ( ; loop; loop = loop->next, i++) {
@@ -1067,7 +1080,9 @@ static PyObject *BPy_IDGroup_update(BPy_IDProperty *self, PyObject *value)
else if (PyDict_Check(value)) {
while (PyDict_Next(value, &i, &pkey, &pval)) {
BPy_IDGroup_Map_SetItem(self, pkey, pval);
- if (PyErr_Occurred()) return NULL;
+ if (PyErr_Occurred()) {
+ return NULL;
+ }
}
}
else {
@@ -1113,14 +1128,16 @@ static PyObject *BPy_IDGroup_get(BPy_IDProperty *self, PyObject *args)
const char *key;
PyObject *def = Py_None;
- if (!PyArg_ParseTuple(args, "s|O:get", &key, &def))
+ if (!PyArg_ParseTuple(args, "s|O:get", &key, &def)) {
return NULL;
+ }
idprop = IDP_GetPropertyFromGroup(self->prop, key);
if (idprop) {
PyObject *pyobj = BPy_IDGroup_WrapData(self->id, idprop, self->prop);
- if (pyobj)
+ if (pyobj) {
return pyobj;
+ }
}
Py_INCREF(def);
@@ -1376,7 +1393,9 @@ static PyObject *BPy_IDArray_slice(BPy_IDArray *self, int begin, int end)
int count;
CLAMP(begin, 0, prop->len);
- if (end < 0) end = prop->len + end + 1;
+ if (end < 0) {
+ end = prop->len + end + 1;
+ }
CLAMP(end, 0, prop->len);
begin = MIN2(begin, end);
@@ -1446,17 +1465,20 @@ static PyObject *BPy_IDArray_subscript(BPy_IDArray *self, PyObject *item)
if (PyIndex_Check(item)) {
Py_ssize_t i;
i = PyNumber_AsSsize_t(item, PyExc_IndexError);
- if (i == -1 && PyErr_Occurred())
+ if (i == -1 && PyErr_Occurred()) {
return NULL;
- if (i < 0)
+ }
+ if (i < 0) {
i += self->prop->len;
+ }
return BPy_IDArray_GetItem(self, i);
}
else if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelength;
- if (PySlice_GetIndicesEx(item, self->prop->len, &start, &stop, &step, &slicelength) < 0)
+ if (PySlice_GetIndicesEx(item, self->prop->len, &start, &stop, &step, &slicelength) < 0) {
return NULL;
+ }
if (slicelength <= 0) {
return PyTuple_New(0);
@@ -1481,20 +1503,24 @@ static int BPy_IDArray_ass_subscript(BPy_IDArray *self, PyObject *item, PyObject
{
if (PyIndex_Check(item)) {
Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
- if (i == -1 && PyErr_Occurred())
+ if (i == -1 && PyErr_Occurred()) {
return -1;
- if (i < 0)
+ }
+ if (i < 0) {
i += self->prop->len;
+ }
return BPy_IDArray_SetItem(self, i, value);
}
else if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelength;
- if (PySlice_GetIndicesEx(item, self->prop->len, &start, &stop, &step, &slicelength) < 0)
+ if (PySlice_GetIndicesEx(item, self->prop->len, &start, &stop, &step, &slicelength) < 0) {
return -1;
+ }
- if (step == 1)
+ if (step == 1) {
return BPy_IDArray_ass_slice(self, start, stop, value);
+ }
else {
PyErr_SetString(PyExc_TypeError, "slice steps not supported with vectors");
return -1;
@@ -1516,9 +1542,9 @@ static PyMappingMethods BPy_IDArray_AsMapping = {
static int itemsize_by_idarray_type(int array_type)
{
- if (array_type == IDP_INT) return sizeof(int);
- if (array_type == IDP_FLOAT) return sizeof(float);
- if (array_type == IDP_DOUBLE) return sizeof(double);
+ if (array_type == IDP_INT) { return sizeof(int); }
+ if (array_type == IDP_FLOAT) { return sizeof(float); }
+ if (array_type == IDP_DOUBLE) { return sizeof(double); }
return -1; /* should never happen */
}
diff --git a/source/blender/python/generic/py_capi_utils.c b/source/blender/python/generic/py_capi_utils.c
index f18e794ead3..0c10737609c 100644
--- a/source/blender/python/generic/py_capi_utils.c
+++ b/source/blender/python/generic/py_capi_utils.c
@@ -319,8 +319,12 @@ void PyC_FileAndNum(const char **filename, int *lineno)
{
PyFrameObject *frame;
- if (filename) *filename = NULL;
- if (lineno) *lineno = -1;
+ if (filename) {
+ *filename = NULL;
+ }
+ if (lineno) {
+ *lineno = -1;
+ }
if (!(frame = PyThreadState_GET()->frame)) {
return;
@@ -384,10 +388,13 @@ PyObject *PyC_Object_GetAttrStringArgs(PyObject *o, Py_ssize_t n, ...)
attr = va_arg(vargs, char *);
item = PyObject_GetAttrString(item, attr);
- if (item)
+ if (item) {
Py_DECREF(item);
- else /* python will set the error value here */
+ }
+ else {
+ /* python will set the error value here */
break;
+ }
}
va_end(vargs);
@@ -527,8 +534,9 @@ PyObject *PyC_ExceptionBuffer(void)
PyObject *error_type, *error_value, *error_traceback;
- if (!PyErr_Occurred())
+ if (!PyErr_Occurred()) {
return NULL;
+ }
PyErr_Fetch(&error_type, &error_value, &error_traceback);
@@ -593,8 +601,9 @@ PyObject *PyC_ExceptionBuffer_Simple(void)
PyObject *error_type, *error_value, *error_traceback;
- if (!PyErr_Occurred())
+ if (!PyErr_Occurred()) {
return NULL;
+ }
PyErr_Fetch(&error_type, &error_value, &error_traceback);
@@ -775,9 +784,10 @@ void PyC_SetHomePath(const char *py_path_bundle)
#ifdef __APPLE__
/* OSX allow file/directory names to contain : character (represented as / in the Finder)
* but current Python lib (release 3.1.1) doesn't handle these correctly */
- if (strchr(py_path_bundle, ':'))
+ if (strchr(py_path_bundle, ':')) {
printf("Warning : Blender application is located in a path containing : or / chars\
\nThis may make python import function fail\n");
+ }
#endif
diff --git a/source/blender/python/gpu/gpu_py_offscreen.c b/source/blender/python/gpu/gpu_py_offscreen.c
index 5482677defc..cd9e162b1aa 100644
--- a/source/blender/python/gpu/gpu_py_offscreen.c
+++ b/source/blender/python/gpu/gpu_py_offscreen.c
@@ -299,8 +299,9 @@ static PyObject *bpygpu_offscreen_bind_context_exit(BPyGPUOffScreen *self, PyObj
static void BPyGPUOffScreen__tp_dealloc(BPyGPUOffScreen *self)
{
- if (self->ofs)
+ if (self->ofs) {
GPU_offscreen_free(self->ofs);
+ }
Py_TYPE(self)->tp_free((PyObject *)self);
}
diff --git a/source/blender/python/gpu/gpu_py_types.c b/source/blender/python/gpu/gpu_py_types.c
index 7ed1832eb57..67bdc070168 100644
--- a/source/blender/python/gpu/gpu_py_types.c
+++ b/source/blender/python/gpu/gpu_py_types.c
@@ -45,18 +45,24 @@ PyObject *BPyInit_gpu_types(void)
submodule = PyModule_Create(&BPyGPU_types_module_def);
- if (PyType_Ready(&BPyGPUVertFormat_Type) < 0)
+ if (PyType_Ready(&BPyGPUVertFormat_Type) < 0) {
return NULL;
- if (PyType_Ready(&BPyGPUVertBuf_Type) < 0)
+ }
+ if (PyType_Ready(&BPyGPUVertBuf_Type) < 0) {
return NULL;
- if (PyType_Ready(&BPyGPUIndexBuf_Type) < 0)
+ }
+ if (PyType_Ready(&BPyGPUIndexBuf_Type) < 0) {
return NULL;
- if (PyType_Ready(&BPyGPUBatch_Type) < 0)
+ }
+ if (PyType_Ready(&BPyGPUBatch_Type) < 0) {
return NULL;
- if (PyType_Ready(&BPyGPUOffScreen_Type) < 0)
+ }
+ if (PyType_Ready(&BPyGPUOffScreen_Type) < 0) {
return NULL;
- if (PyType_Ready(&BPyGPUShader_Type) < 0)
+ }
+ if (PyType_Ready(&BPyGPUShader_Type) < 0) {
return NULL;
+ }
#define MODULE_TYPE_ADD(s, t) \
PyModule_AddObject(s, t.tp_name, (PyObject *)&t); Py_INCREF((PyObject *)&t)
diff --git a/source/blender/python/intern/bpy.c b/source/blender/python/intern/bpy.c
index 55d226e1461..f67ed1a3713 100644
--- a/source/blender/python/intern/bpy.c
+++ b/source/blender/python/intern/bpy.c
@@ -126,9 +126,15 @@ static PyObject *bpy_blend_paths(PyObject *UNUSED(self), PyObject *args, PyObjec
return NULL;
}
- if (absolute) flag |= BKE_BPATH_TRAVERSE_ABS;
- if (!packed) flag |= BKE_BPATH_TRAVERSE_SKIP_PACKED;
- if (local) flag |= BKE_BPATH_TRAVERSE_SKIP_LIBRARY;
+ if (absolute) {
+ flag |= BKE_BPATH_TRAVERSE_ABS;
+ }
+ if (!packed) {
+ flag |= BKE_BPATH_TRAVERSE_SKIP_PACKED;
+ }
+ if (local) {
+ flag |= BKE_BPATH_TRAVERSE_SKIP_LIBRARY;
+ }
list = PyList_New(0);
@@ -157,10 +163,10 @@ static PyObject *bpy_user_resource(PyObject *UNUSED(self), PyObject *args, PyObj
}
/* stupid string compare */
- if (STREQ(type, "DATAFILES")) folder_id = BLENDER_USER_DATAFILES;
- else if (STREQ(type, "CONFIG")) folder_id = BLENDER_USER_CONFIG;
- else if (STREQ(type, "SCRIPTS")) folder_id = BLENDER_USER_SCRIPTS;
- else if (STREQ(type, "AUTOSAVE")) folder_id = BLENDER_USER_AUTOSAVE;
+ if (STREQ(type, "DATAFILES")) { folder_id = BLENDER_USER_DATAFILES; }
+ else if (STREQ(type, "CONFIG")) { folder_id = BLENDER_USER_CONFIG; }
+ else if (STREQ(type, "SCRIPTS")) { folder_id = BLENDER_USER_SCRIPTS; }
+ else if (STREQ(type, "AUTOSAVE")) { folder_id = BLENDER_USER_AUTOSAVE; }
else {
PyErr_SetString(PyExc_ValueError, "invalid resource argument");
return NULL;
@@ -203,9 +209,9 @@ static PyObject *bpy_resource_path(PyObject *UNUSED(self), PyObject *args, PyObj
}
/* stupid string compare */
- if (STREQ(type, "USER")) folder_id = BLENDER_RESOURCE_PATH_USER;
- else if (STREQ(type, "LOCAL")) folder_id = BLENDER_RESOURCE_PATH_LOCAL;
- else if (STREQ(type, "SYSTEM")) folder_id = BLENDER_RESOURCE_PATH_SYSTEM;
+ if (STREQ(type, "USER")) { folder_id = BLENDER_RESOURCE_PATH_USER; }
+ else if (STREQ(type, "LOCAL")) { folder_id = BLENDER_RESOURCE_PATH_LOCAL; }
+ else if (STREQ(type, "SYSTEM")) { folder_id = BLENDER_RESOURCE_PATH_SYSTEM; }
else {
PyErr_SetString(PyExc_ValueError, "invalid resource argument");
return NULL;
diff --git a/source/blender/python/intern/bpy_app.c b/source/blender/python/intern/bpy_app.c
index 252fd1b3e23..2cd3086dae1 100644
--- a/source/blender/python/intern/bpy_app.c
+++ b/source/blender/python/intern/bpy_app.c
@@ -253,8 +253,12 @@ static int bpy_app_debug_set(PyObject *UNUSED(self), PyObject *value, void *clos
return -1;
}
- if (param) G.debug |= flag;
- else G.debug &= ~flag;
+ if (param) {
+ G.debug |= flag;
+ }
+ else {
+ G.debug &= ~flag;
+ }
return 0;
}
@@ -278,8 +282,12 @@ static int bpy_app_global_flag_set(PyObject *UNUSED(self), PyObject *value, void
return -1;
}
- if (param) G.f |= flag;
- else G.f &= ~flag;
+ if (param) {
+ G.f |= flag;
+ }
+ else {
+ G.f &= ~flag;
+ }
return 0;
}
diff --git a/source/blender/python/intern/bpy_app_handlers.c b/source/blender/python/intern/bpy_app_handlers.c
index b6b9f294810..c91c0d69a16 100644
--- a/source/blender/python/intern/bpy_app_handlers.c
+++ b/source/blender/python/intern/bpy_app_handlers.c
@@ -90,8 +90,9 @@ static PyObject *bpy_app_handlers_persistent_new(PyTypeObject *UNUSED(type), PyO
{
PyObject *value;
- if (!PyArg_ParseTuple(args, "O:bpy.app.handlers.persistent", &value))
+ if (!PyArg_ParseTuple(args, "O:bpy.app.handlers.persistent", &value)) {
return NULL;
+ }
if (PyFunction_Check(value)) {
PyObject **dict_ptr = _PyObject_GetDictPtr(value);
diff --git a/source/blender/python/intern/bpy_app_translations.c b/source/blender/python/intern/bpy_app_translations.c
index 1ed68201a2e..f571caee8ec 100644
--- a/source/blender/python/intern/bpy_app_translations.c
+++ b/source/blender/python/intern/bpy_app_translations.c
@@ -89,8 +89,9 @@ static bool _ghashutil_keycmp(const void *a, const void *b)
const GHashKey *B = b;
/* Note: comparing msgid first, most of the time it will be enough! */
- if (BLI_ghashutil_strcmp(A->msgid, B->msgid) == false)
+ if (BLI_ghashutil_strcmp(A->msgid, B->msgid) == false) {
return BLI_ghashutil_strcmp(A->msgctxt, B->msgctxt);
+ }
return true; /* true means they are not equal! */
}
@@ -249,8 +250,9 @@ const char *BPY_app_translations_py_pgettext(const char *msgctxt, const char *ms
const char *tmp;
/* Just in case, should never happen! */
- if (!_translations)
+ if (!_translations) {
return msgid;
+ }
tmp = BLT_lang_get();
if (!STREQ(tmp, locale) || !_translations_cache) {
@@ -458,8 +460,9 @@ static PyObject *app_translations_locales_get(PyObject *UNUSED(self), void *UNUS
if (items) {
/* This is not elegant, but simple! */
for (it = items; it->identifier; it++) {
- if (it->value)
+ if (it->value) {
num_locales++;
+ }
}
}
@@ -467,8 +470,9 @@ static PyObject *app_translations_locales_get(PyObject *UNUSED(self), void *UNUS
if (items) {
for (it = items; it->identifier; it++) {
- if (it->value)
+ if (it->value) {
PyTuple_SET_ITEM(ret, pos++, PyUnicode_FromString(it->description));
+ }
}
}
@@ -801,8 +805,9 @@ PyObject *BPY_app_translations_struct(void)
PyStructSequence_InitType(&BlenderAppTranslationsContextsType, &app_translations_contexts_desc);
}
- if (PyType_Ready(&BlenderAppTranslationsType) < 0)
+ if (PyType_Ready(&BlenderAppTranslationsType) < 0) {
return NULL;
+ }
ret = PyObject_CallObject((PyObject *)&BlenderAppTranslationsType, NULL);
diff --git a/source/blender/python/intern/bpy_capi_utils.c b/source/blender/python/intern/bpy_capi_utils.c
index 3a5b3077ee6..549a06f5b28 100644
--- a/source/blender/python/intern/bpy_capi_utils.c
+++ b/source/blender/python/intern/bpy_capi_utils.c
@@ -48,8 +48,9 @@ char *BPy_enum_as_string(const EnumPropertyItem *item)
char *cstring;
for (e = item; item->identifier; item++) {
- if (item->identifier[0])
+ if (item->identifier[0]) {
BLI_dynstr_appendf(dynstr, (e == item) ? "'%s'" : ", '%s'", item->identifier);
+ }
}
cstring = BLI_dynstr_get_cstring(dynstr);
@@ -93,8 +94,9 @@ bool BPy_errors_to_report_ex(ReportList *reports, const bool use_full, const boo
{
PyObject *pystring;
- if (!PyErr_Occurred())
+ if (!PyErr_Occurred()) {
return 1;
+ }
/* less hassle if we allow NULL */
if (reports == NULL) {
diff --git a/source/blender/python/intern/bpy_driver.c b/source/blender/python/intern/bpy_driver.c
index 93d9225ad01..cb23739ca33 100644
--- a/source/blender/python/intern/bpy_driver.c
+++ b/source/blender/python/intern/bpy_driver.c
@@ -69,13 +69,17 @@ int bpy_pydriver_create_dict(void)
PyObject *d, *mod;
/* validate namespace for driver evaluation */
- if (bpy_pydriver_Dict) return -1;
+ if (bpy_pydriver_Dict) {
+ return -1;
+ }
d = PyDict_New();
- if (d == NULL)
+ if (d == NULL) {
return -1;
- else
+ }
+ else {
bpy_pydriver_Dict = d;
+ }
/* import some modules: builtins, bpy, math, (Blender.noise)*/
PyDict_SetItemString(d, "__builtins__", PyEval_GetBuiltins());
@@ -205,8 +209,9 @@ void BPY_driver_reset(void)
PyGILState_STATE gilstate;
bool use_gil = true; /* !PyC_IsInterpreterActive(); */
- if (use_gil)
+ if (use_gil) {
gilstate = PyGILState_Ensure();
+ }
if (bpy_pydriver_Dict) { /* free the global dict used by pydrivers */
PyDict_Clear(bpy_pydriver_Dict);
@@ -227,8 +232,9 @@ void BPY_driver_reset(void)
/* freed when clearing driver dict */
g_pydriver_state_prev.self = NULL;
- if (use_gil)
+ if (use_gil) {
PyGILState_Release(gilstate);
+ }
return;
}
@@ -399,8 +405,9 @@ float BPY_driver_exec(struct PathResolvedRNA *anim_rna, ChannelDriver *driver, C
/* get the py expression to be evaluated */
expr = driver_orig->expression;
- if (expr[0] == '\0')
+ if (expr[0] == '\0') {
return 0.0f;
+ }
#ifndef USE_BYTECODE_WHITELIST
if (!(G.f & G_FLAG_SCRIPT_AUTOEXEC)) {
@@ -418,8 +425,9 @@ float BPY_driver_exec(struct PathResolvedRNA *anim_rna, ChannelDriver *driver, C
use_gil = true; /* !PyC_IsInterpreterActive(); */
- if (use_gil)
+ if (use_gil) {
gilstate = PyGILState_Ensure();
+ }
/* needed since drivers are updated directly after undo where 'main' is
* re-allocated [#28807] */
@@ -429,8 +437,9 @@ float BPY_driver_exec(struct PathResolvedRNA *anim_rna, ChannelDriver *driver, C
if (!bpy_pydriver_Dict) {
if (bpy_pydriver_create_dict() != 0) {
fprintf(stderr, "PyDriver error: couldn't create Python dictionary\n");
- if (use_gil)
+ if (use_gil) {
PyGILState_Release(gilstate);
+ }
return 0.0f;
}
}
@@ -445,8 +454,9 @@ float BPY_driver_exec(struct PathResolvedRNA *anim_rna, ChannelDriver *driver, C
bpy_pydriver_namespace_clear_self();
}
- if (driver_orig->expr_comp == NULL)
+ if (driver_orig->expr_comp == NULL) {
driver_orig->flag |= DRIVER_FLAG_RECOMPILE;
+ }
/* compile the expression first if it hasn't been compiled or needs to be rebuilt */
if (driver_orig->flag & DRIVER_FLAG_RECOMPILE) {
@@ -571,8 +581,9 @@ float BPY_driver_exec(struct PathResolvedRNA *anim_rna, ChannelDriver *driver, C
retval = PyRun_String(expr, Py_eval_input, bpy_pydriver_Dict, driver_vars);
#else
/* evaluate the compiled expression */
- if (expr_code)
+ if (expr_code) {
retval = PyEval_EvalCode((void *)expr_code, bpy_pydriver_Dict, driver_vars);
+ }
#endif
/* decref the driver vars first... */
@@ -593,8 +604,9 @@ float BPY_driver_exec(struct PathResolvedRNA *anim_rna, ChannelDriver *driver, C
Py_DECREF(retval);
}
- if (use_gil)
+ if (use_gil) {
PyGILState_Release(gilstate);
+ }
if (isfinite(result)) {
return (float)result;
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index 189fb97f3d2..e07e39642e9 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -98,8 +98,9 @@ void BPY_context_update(bContext *C)
/* don't do this from a non-main (e.g. render) thread, it can cause a race
* condition on C->data.recursion. ideal solution would be to disable
* context entirely from non-main threads, but that's more complicated */
- if (!BLI_thread_is_main())
+ if (!BLI_thread_is_main()) {
return;
+ }
BPy_SetContext(C);
bpy_import_main_set(CTX_data_main(C));
@@ -110,8 +111,9 @@ void bpy_context_set(bContext *C, PyGILState_STATE *gilstate)
{
py_call_level++;
- if (gilstate)
+ if (gilstate) {
*gilstate = PyGILState_Ensure();
+ }
if (py_call_level == 1) {
BPY_context_update(C);
@@ -135,8 +137,9 @@ void bpy_context_clear(bContext *UNUSED(C), PyGILState_STATE *gilstate)
{
py_call_level--;
- if (gilstate)
+ if (gilstate) {
PyGILState_Release(*gilstate);
+ }
if (py_call_level < 0) {
fprintf(stderr, "ERROR: Python context internal state bug. this should not happen!\n");
@@ -163,14 +166,16 @@ void BPY_text_free_code(Text *text)
PyGILState_STATE gilstate;
bool use_gil = !PyC_IsInterpreterActive();
- if (use_gil)
+ if (use_gil) {
gilstate = PyGILState_Ensure();
+ }
Py_DECREF((PyObject *)text->compiled);
text->compiled = NULL;
- if (use_gil)
+ if (use_gil) {
PyGILState_Release(gilstate);
+ }
}
}
@@ -184,8 +189,9 @@ void BPY_modules_update(bContext *C)
/* refreshes the main struct */
BPY_update_rna_module();
- if (bpy_context_module)
+ if (bpy_context_module) {
bpy_context_module->ptr.data = (void *)C;
+ }
}
void BPY_context_set(bContext *C)
@@ -371,11 +377,13 @@ void BPY_python_end(void)
printf("*bpy stats* - ");
printf("tot exec: %d, ", bpy_timer_count);
printf("tot run: %.4fsec, ", bpy_timer_run_tot);
- if (bpy_timer_count > 0)
+ if (bpy_timer_count > 0) {
printf("average run: %.6fsec, ", (bpy_timer_run_tot / bpy_timer_count));
+ }
- if (bpy_timer > 0.0)
+ if (bpy_timer > 0.0) {
printf("tot usage %.4f%%", (bpy_timer_run_tot / bpy_timer) * 100.0);
+ }
printf("\n");
@@ -750,8 +758,9 @@ void BPY_modules_load_user(bContext *C)
Text *text;
/* can happen on file load */
- if (bmain == NULL)
+ if (bmain == NULL) {
return;
+ }
/* update pointers since this can run from a nested script
* on file load */
@@ -802,8 +811,9 @@ int BPY_context_member_get(bContext *C, const char *member, bContextDataResult *
PointerRNA *ptr = NULL;
bool done = false;
- if (use_gil)
+ if (use_gil) {
gilstate = PyGILState_Ensure();
+ }
pyctx = (PyObject *)CTX_py_dict_get(C);
item = PyDict_GetItemString(pyctx, member);
@@ -870,8 +880,9 @@ int BPY_context_member_get(bContext *C, const char *member, bContextDataResult *
CLOG_INFO(BPY_LOG_CONTEXT, 2, "'%s' found", member);
}
- if (use_gil)
+ if (use_gil) {
PyGILState_Release(gilstate);
+ }
return done;
}
@@ -971,8 +982,9 @@ PyInit_bpy(void)
dealloc_obj_Type.tp_dealloc = dealloc_obj_dealloc;
dealloc_obj_Type.tp_flags = Py_TPFLAGS_DEFAULT;
- if (PyType_Ready(&dealloc_obj_Type) < 0)
+ if (PyType_Ready(&dealloc_obj_Type) < 0) {
return NULL;
+ }
dob = (dealloc_obj *) dealloc_obj_Type.tp_alloc(&dealloc_obj_Type, 0);
dob->mod = bpy_proxy; /* borrow */
diff --git a/source/blender/python/intern/bpy_library_load.c b/source/blender/python/intern/bpy_library_load.c
index bf12db0f3a1..77fb6bf1525 100644
--- a/source/blender/python/intern/bpy_library_load.c
+++ b/source/blender/python/intern/bpy_library_load.c
@@ -476,8 +476,9 @@ int BPY_library_load_module(PyObject *mod_par)
/* some compilers don't like accessing this directly, delay assignment */
bpy_lib_Type.tp_getattro = PyObject_GenericGetAttr;
- if (PyType_Ready(&bpy_lib_Type) < 0)
+ if (PyType_Ready(&bpy_lib_Type) < 0) {
return -1;
+ }
return 0;
}
diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c
index 98b2f871c54..ff6bd3840e9 100644
--- a/source/blender/python/intern/bpy_operator.c
+++ b/source/blender/python/intern/bpy_operator.c
@@ -93,8 +93,9 @@ static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args)
return NULL;
}
- if (!PyArg_ParseTuple(args, "s|Os:_bpy.ops.poll", &opname, &context_dict, &context_str))
+ if (!PyArg_ParseTuple(args, "s|Os:_bpy.ops.poll", &opname, &context_dict, &context_str)) {
return NULL;
+ }
ot = WM_operatortype_find(opname, true);
@@ -362,8 +363,9 @@ static PyObject *pyop_as_string(PyObject *UNUSED(self), PyObject *args)
error_val = pyrna_pydict_to_props(&ptr, kw, false, "Converting py args to operator properties: ");
}
- if (error_val == 0)
+ if (error_val == 0) {
buf = WM_operator_pystring_ex(C, NULL, all_args, macro_args, ot, &ptr);
+ }
WM_operator_properties_free(&ptr);
diff --git a/source/blender/python/intern/bpy_operator_wrap.c b/source/blender/python/intern/bpy_operator_wrap.c
index 6f1450fcbc2..6a130a7c52b 100644
--- a/source/blender/python/intern/bpy_operator_wrap.c
+++ b/source/blender/python/intern/bpy_operator_wrap.c
@@ -162,8 +162,9 @@ PyObject *PYOP_wrap_macro_define(PyObject *UNUSED(self), PyObject *args)
const char *opname;
const char *macroname;
- if (!PyArg_ParseTuple(args, "Os:_bpy.ops.macro_define", &macro, &opname))
+ if (!PyArg_ParseTuple(args, "Os:_bpy.ops.macro_define", &macro, &opname)) {
return NULL;
+ }
if (WM_operatortype_find(opname, true) == NULL) {
PyErr_Format(PyExc_ValueError,
diff --git a/source/blender/python/intern/bpy_props.c b/source/blender/python/intern/bpy_props.c
index 385b02f231e..18a39f39e70 100644
--- a/source/blender/python/intern/bpy_props.c
+++ b/source/blender/python/intern/bpy_props.c
@@ -201,10 +201,12 @@ static PyObject *bpy_prop_deferred_return(PyObject *func, PyObject *kw)
PyTuple_SET_ITEM(ret, 0, func);
Py_INCREF(func);
- if (kw == NULL)
+ if (kw == NULL) {
kw = PyDict_New();
- else
+ }
+ else {
Py_INCREF(kw);
+ }
PyTuple_SET_ITEM(ret, 1, kw);
@@ -282,8 +284,9 @@ static bool bpy_prop_boolean_get_cb(struct PointerRNA *ptr, struct PropertyRNA *
use_gil = true; /* !PyC_IsInterpreterActive(); */
- if (use_gil)
+ if (use_gil) {
gilstate = PyGILState_Ensure();
+ }
py_func = py_data[BPY_DATA_CB_SLOT_GET];
@@ -313,8 +316,9 @@ static bool bpy_prop_boolean_get_cb(struct PointerRNA *ptr, struct PropertyRNA *
Py_DECREF(ret);
}
- if (use_gil)
+ if (use_gil) {
PyGILState_Release(gilstate);
+ }
if (!is_write_ok) {
pyrna_write_set(false);
@@ -342,8 +346,9 @@ static void bpy_prop_boolean_set_cb(struct PointerRNA *ptr, struct PropertyRNA *
use_gil = true; /* !PyC_IsInterpreterActive(); */
- if (use_gil)
+ if (use_gil) {
gilstate = PyGILState_Ensure();
+ }
py_func = py_data[BPY_DATA_CB_SLOT_SET];
@@ -369,8 +374,9 @@ static void bpy_prop_boolean_set_cb(struct PointerRNA *ptr, struct PropertyRNA *
Py_DECREF(ret);
}
- if (use_gil)
+ if (use_gil) {
PyGILState_Release(gilstate);
+ }
if (!is_write_ok) {
pyrna_write_set(false);
@@ -395,8 +401,9 @@ static bool bpy_prop_poll_cb(struct PointerRNA *self, PointerRNA candidate, stru
py_candidate = pyrna_struct_as_instance(&candidate);
py_func = py_data[BPY_DATA_CB_SLOT_POLL];
- if (!is_write_ok)
+ if (!is_write_ok) {
pyrna_write_set(true);
+ }
args = PyTuple_New(2);
PyTuple_SET_ITEM(args, 0, py_self);
@@ -416,8 +423,9 @@ static bool bpy_prop_poll_cb(struct PointerRNA *self, PointerRNA candidate, stru
}
PyGILState_Release(gilstate);
- if (!is_write_ok)
+ if (!is_write_ok) {
pyrna_write_set(false);
+ }
return result;
}
@@ -442,8 +450,9 @@ static void bpy_prop_boolean_array_get_cb(struct PointerRNA *ptr, struct Propert
use_gil = true; /* !PyC_IsInterpreterActive(); */
- if (use_gil)
+ if (use_gil) {
gilstate = PyGILState_Ensure();
+ }
py_func = py_data[BPY_DATA_CB_SLOT_GET];
@@ -458,15 +467,17 @@ static void bpy_prop_boolean_array_get_cb(struct PointerRNA *ptr, struct Propert
if (ret == NULL) {
PyC_Err_PrintWithFunc(py_func);
- for (i = 0; i < len; ++i)
+ for (i = 0; i < len; ++i) {
values[i] = false;
+ }
}
else {
if (PyC_AsArray(values, ret, len, &PyBool_Type, false, "BoolVectorProperty get") == -1) {
PyC_Err_PrintWithFunc(py_func);
- for (i = 0; i < len; ++i)
+ for (i = 0; i < len; ++i) {
values[i] = false;
+ }
/* PyC_AsArray decrements refcount internally on error */
}
@@ -475,8 +486,9 @@ static void bpy_prop_boolean_array_get_cb(struct PointerRNA *ptr, struct Propert
}
}
- if (use_gil)
+ if (use_gil) {
PyGILState_Release(gilstate);
+ }
if (!is_write_ok) {
pyrna_write_set(false);
@@ -504,8 +516,9 @@ static void bpy_prop_boolean_array_set_cb(struct PointerRNA *ptr, struct Propert
use_gil = true; /* !PyC_IsInterpreterActive(); */
- if (use_gil)
+ if (use_gil) {
gilstate = PyGILState_Ensure();
+ }
py_func = py_data[BPY_DATA_CB_SLOT_SET];
@@ -532,8 +545,9 @@ static void bpy_prop_boolean_array_set_cb(struct PointerRNA *ptr, struct Propert
Py_DECREF(ret);
}
- if (use_gil)
+ if (use_gil) {
PyGILState_Release(gilstate);
+ }
if (!is_write_ok) {
pyrna_write_set(false);
@@ -560,8 +574,9 @@ static int bpy_prop_int_get_cb(struct PointerRNA *ptr, struct PropertyRNA *prop)
use_gil = true; /* !PyC_IsInterpreterActive(); */
- if (use_gil)
+ if (use_gil) {
gilstate = PyGILState_Ensure();
+ }
py_func = py_data[BPY_DATA_CB_SLOT_GET];
@@ -588,8 +603,9 @@ static int bpy_prop_int_get_cb(struct PointerRNA *ptr, struct PropertyRNA *prop)
Py_DECREF(ret);
}
- if (use_gil)
+ if (use_gil) {
PyGILState_Release(gilstate);
+ }
if (!is_write_ok) {
pyrna_write_set(false);
@@ -617,8 +633,9 @@ static void bpy_prop_int_set_cb(struct PointerRNA *ptr, struct PropertyRNA *prop
use_gil = true; /* !PyC_IsInterpreterActive(); */
- if (use_gil)
+ if (use_gil) {
gilstate = PyGILState_Ensure();
+ }
py_func = py_data[BPY_DATA_CB_SLOT_SET];
@@ -644,8 +661,9 @@ static void bpy_prop_int_set_cb(struct PointerRNA *ptr, struct PropertyRNA *prop
Py_DECREF(ret);
}
- if (use_gil)
+ if (use_gil) {
PyGILState_Release(gilstate);
+ }
if (!is_write_ok) {
pyrna_write_set(false);
@@ -672,8 +690,9 @@ static void bpy_prop_int_array_get_cb(struct PointerRNA *ptr, struct PropertyRNA
use_gil = true; /* !PyC_IsInterpreterActive(); */
- if (use_gil)
+ if (use_gil) {
gilstate = PyGILState_Ensure();
+ }
py_func = py_data[BPY_DATA_CB_SLOT_GET];
@@ -688,15 +707,17 @@ static void bpy_prop_int_array_get_cb(struct PointerRNA *ptr, struct PropertyRNA
if (ret == NULL) {
PyC_Err_PrintWithFunc(py_func);
- for (i = 0; i < len; ++i)
+ for (i = 0; i < len; ++i) {
values[i] = 0;
+ }
}
else {
if (PyC_AsArray(values, ret, len, &PyLong_Type, false, "IntVectorProperty get") == -1) {
PyC_Err_PrintWithFunc(py_func);
- for (i = 0; i < len; ++i)
+ for (i = 0; i < len; ++i) {
values[i] = 0;
+ }
/* PyC_AsArray decrements refcount internally on error */
}
@@ -705,8 +726,9 @@ static void bpy_prop_int_array_get_cb(struct PointerRNA *ptr, struct PropertyRNA
}
}
- if (use_gil)
+ if (use_gil) {
PyGILState_Release(gilstate);
+ }
if (!is_write_ok) {
pyrna_write_set(false);
@@ -734,8 +756,9 @@ static void bpy_prop_int_array_set_cb(struct PointerRNA *ptr, struct PropertyRNA
use_gil = true; /* !PyC_IsInterpreterActive(); */
- if (use_gil)
+ if (use_gil) {
gilstate = PyGILState_Ensure();
+ }
py_func = py_data[BPY_DATA_CB_SLOT_SET];
@@ -762,8 +785,9 @@ static void bpy_prop_int_array_set_cb(struct PointerRNA *ptr, struct PropertyRNA
Py_DECREF(ret);
}
- if (use_gil)
+ if (use_gil) {
PyGILState_Release(gilstate);
+ }
if (!is_write_ok) {
pyrna_write_set(false);
@@ -790,8 +814,9 @@ static float bpy_prop_float_get_cb(struct PointerRNA *ptr, struct PropertyRNA *p
use_gil = true; /* !PyC_IsInterpreterActive(); */
- if (use_gil)
+ if (use_gil) {
gilstate = PyGILState_Ensure();
+ }
py_func = py_data[BPY_DATA_CB_SLOT_GET];
@@ -818,8 +843,9 @@ static float bpy_prop_float_get_cb(struct PointerRNA *ptr, struct PropertyRNA *p
Py_DECREF(ret);
}
- if (use_gil)
+ if (use_gil) {
PyGILState_Release(gilstate);
+ }
if (!is_write_ok) {
pyrna_write_set(false);
@@ -847,8 +873,9 @@ static void bpy_prop_float_set_cb(struct PointerRNA *ptr, struct PropertyRNA *pr
use_gil = true; /* !PyC_IsInterpreterActive(); */
- if (use_gil)
+ if (use_gil) {
gilstate = PyGILState_Ensure();
+ }
py_func = py_data[BPY_DATA_CB_SLOT_SET];
@@ -874,8 +901,9 @@ static void bpy_prop_float_set_cb(struct PointerRNA *ptr, struct PropertyRNA *pr
Py_DECREF(ret);
}
- if (use_gil)
+ if (use_gil) {
PyGILState_Release(gilstate);
+ }
if (!is_write_ok) {
pyrna_write_set(false);
@@ -902,8 +930,9 @@ static void bpy_prop_float_array_get_cb(struct PointerRNA *ptr, struct PropertyR
use_gil = true; /* !PyC_IsInterpreterActive(); */
- if (use_gil)
+ if (use_gil) {
gilstate = PyGILState_Ensure();
+ }
py_func = py_data[BPY_DATA_CB_SLOT_GET];
@@ -918,15 +947,17 @@ static void bpy_prop_float_array_get_cb(struct PointerRNA *ptr, struct PropertyR
if (ret == NULL) {
PyC_Err_PrintWithFunc(py_func);
- for (i = 0; i < len; ++i)
+ for (i = 0; i < len; ++i) {
values[i] = 0.0f;
+ }
}
else {
if (PyC_AsArray(values, ret, len, &PyFloat_Type, false, "FloatVectorProperty get") == -1) {
PyC_Err_PrintWithFunc(py_func);
- for (i = 0; i < len; ++i)
+ for (i = 0; i < len; ++i) {
values[i] = 0.0f;
+ }
/* PyC_AsArray decrements refcount internally on error */
}
@@ -935,8 +966,9 @@ static void bpy_prop_float_array_get_cb(struct PointerRNA *ptr, struct PropertyR
}
}
- if (use_gil)
+ if (use_gil) {
PyGILState_Release(gilstate);
+ }
if (!is_write_ok) {
pyrna_write_set(false);
@@ -964,8 +996,9 @@ static void bpy_prop_float_array_set_cb(struct PointerRNA *ptr, struct PropertyR
use_gil = true; /* !PyC_IsInterpreterActive(); */
- if (use_gil)
+ if (use_gil) {
gilstate = PyGILState_Ensure();
+ }
py_func = py_data[BPY_DATA_CB_SLOT_SET];
@@ -992,8 +1025,9 @@ static void bpy_prop_float_array_set_cb(struct PointerRNA *ptr, struct PropertyR
Py_DECREF(ret);
}
- if (use_gil)
+ if (use_gil) {
PyGILState_Release(gilstate);
+ }
if (!is_write_ok) {
pyrna_write_set(false);
@@ -1019,8 +1053,9 @@ static void bpy_prop_string_get_cb(struct PointerRNA *ptr, struct PropertyRNA *p
use_gil = true; /* !PyC_IsInterpreterActive(); */
- if (use_gil)
+ if (use_gil) {
gilstate = PyGILState_Ensure();
+ }
py_func = py_data[BPY_DATA_CB_SLOT_GET];
@@ -1051,8 +1086,9 @@ static void bpy_prop_string_get_cb(struct PointerRNA *ptr, struct PropertyRNA *p
Py_DECREF(ret);
}
- if (use_gil)
+ if (use_gil) {
PyGILState_Release(gilstate);
+ }
if (!is_write_ok) {
pyrna_write_set(false);
@@ -1079,8 +1115,9 @@ static int bpy_prop_string_length_cb(struct PointerRNA *ptr, struct PropertyRNA
use_gil = true; /* !PyC_IsInterpreterActive(); */
- if (use_gil)
+ if (use_gil) {
gilstate = PyGILState_Ensure();
+ }
py_func = py_data[BPY_DATA_CB_SLOT_GET];
@@ -1111,8 +1148,9 @@ static int bpy_prop_string_length_cb(struct PointerRNA *ptr, struct PropertyRNA
Py_DECREF(ret);
}
- if (use_gil)
+ if (use_gil) {
PyGILState_Release(gilstate);
+ }
if (!is_write_ok) {
pyrna_write_set(false);
@@ -1141,8 +1179,9 @@ static void bpy_prop_string_set_cb(struct PointerRNA *ptr, struct PropertyRNA *p
use_gil = true; /* !PyC_IsInterpreterActive(); */
- if (use_gil)
+ if (use_gil) {
gilstate = PyGILState_Ensure();
+ }
py_func = py_data[BPY_DATA_CB_SLOT_SET];
@@ -1155,8 +1194,9 @@ static void bpy_prop_string_set_cb(struct PointerRNA *ptr, struct PropertyRNA *p
PyErr_SetString(PyExc_ValueError, "the return value must be a string");
PyC_Err_PrintWithFunc(py_func);
}
- else
+ else {
PyTuple_SET_ITEM(args, 1, py_value);
+ }
ret = PyObject_CallObject(py_func, args);
@@ -1174,8 +1214,9 @@ static void bpy_prop_string_set_cb(struct PointerRNA *ptr, struct PropertyRNA *p
Py_DECREF(ret);
}
- if (use_gil)
+ if (use_gil) {
PyGILState_Release(gilstate);
+ }
if (!is_write_ok) {
pyrna_write_set(false);
@@ -1202,8 +1243,9 @@ static int bpy_prop_enum_get_cb(struct PointerRNA *ptr, struct PropertyRNA *prop
use_gil = true; /* !PyC_IsInterpreterActive(); */
- if (use_gil)
+ if (use_gil) {
gilstate = PyGILState_Ensure();
+ }
py_func = py_data[BPY_DATA_CB_SLOT_GET];
@@ -1230,8 +1272,9 @@ static int bpy_prop_enum_get_cb(struct PointerRNA *ptr, struct PropertyRNA *prop
Py_DECREF(ret);
}
- if (use_gil)
+ if (use_gil) {
PyGILState_Release(gilstate);
+ }
if (!is_write_ok) {
pyrna_write_set(false);
@@ -1259,8 +1302,9 @@ static void bpy_prop_enum_set_cb(struct PointerRNA *ptr, struct PropertyRNA *pro
use_gil = true; /* !PyC_IsInterpreterActive(); */
- if (use_gil)
+ if (use_gil) {
gilstate = PyGILState_Ensure();
+ }
py_func = py_data[BPY_DATA_CB_SLOT_SET];
@@ -1286,8 +1330,9 @@ static void bpy_prop_enum_set_cb(struct PointerRNA *ptr, struct PropertyRNA *pro
Py_DECREF(ret);
}
- if (use_gil)
+ if (use_gil) {
PyGILState_Release(gilstate);
+ }
if (!is_write_ok) {
pyrna_write_set(false);
@@ -1423,8 +1468,9 @@ static const EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject *
}
}
- if (tmp_icon)
+ if (tmp_icon) {
tmp.icon = icon_id_from_name(tmp_icon);
+ }
items[i] = tmp;
@@ -2139,8 +2185,9 @@ static PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject
return NULL;
}
- if (pydef && PyC_AsArray(def, pydef, size, &PyBool_Type, false, "BoolVectorProperty(default=sequence)") == -1)
+ if (pydef && PyC_AsArray(def, pydef, size, &PyBool_Type, false, "BoolVectorProperty(default=sequence)") == -1) {
return NULL;
+ }
if (bpy_prop_callback_check(update_cb, "update", 2) == -1) {
return NULL;
@@ -2155,7 +2202,9 @@ static PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject
// prop = RNA_def_boolean_array(srna, id, size, pydef ? def:NULL, name ? name : id, description);
prop = RNA_def_property(srna, id, PROP_BOOLEAN, subtype);
RNA_def_property_array(prop, size);
- if (pydef) RNA_def_property_boolean_array_default(prop, def);
+ if (pydef) {
+ RNA_def_property_boolean_array_default(prop, def);
+ }
RNA_def_property_ui_text(prop, name ? name : id, description);
if (py_tags) {
@@ -2366,8 +2415,9 @@ static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject
return NULL;
}
- if (pydef && PyC_AsArray(def, pydef, size, &PyLong_Type, false, "IntVectorProperty(default=sequence)") == -1)
+ if (pydef && PyC_AsArray(def, pydef, size, &PyLong_Type, false, "IntVectorProperty(default=sequence)") == -1) {
return NULL;
+ }
if (bpy_prop_callback_check(update_cb, "update", 2) == -1) {
return NULL;
@@ -2381,7 +2431,9 @@ static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject
prop = RNA_def_property(srna, id, PROP_INT, subtype);
RNA_def_property_array(prop, size);
- if (pydef) RNA_def_property_int_array_default(prop, def);
+ if (pydef) {
+ RNA_def_property_int_array_default(prop, def);
+ }
RNA_def_property_range(prop, min, max);
RNA_def_property_ui_text(prop, name ? name : id, description);
RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, 3);
@@ -2618,8 +2670,9 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec
return NULL;
}
- if (pydef && PyC_AsArray(def, pydef, size, &PyFloat_Type, false, "FloatVectorProperty(default=sequence)") == -1)
+ if (pydef && PyC_AsArray(def, pydef, size, &PyFloat_Type, false, "FloatVectorProperty(default=sequence)") == -1) {
return NULL;
+ }
if (bpy_prop_callback_check(update_cb, "update", 2) == -1) {
return NULL;
@@ -2633,7 +2686,9 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec
prop = RNA_def_property(srna, id, PROP_FLOAT, subtype | unit);
RNA_def_property_array(prop, size);
- if (pydef) RNA_def_property_float_array_default(prop, def);
+ if (pydef) {
+ RNA_def_property_float_array_default(prop, def);
+ }
RNA_def_property_range(prop, min, max);
RNA_def_property_ui_text(prop, name ? name : id, description);
RNA_def_property_ui_range(prop, MAX2(soft_min, min), MIN2(soft_max, max), step, precision);
@@ -2728,8 +2783,12 @@ static PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw
}
prop = RNA_def_property(srna, id, PROP_STRING, subtype);
- if (maxlen != 0) RNA_def_property_string_maxlength(prop, maxlen + 1); /* +1 since it includes null terminator */
- if (def && def[0]) RNA_def_property_string_default(prop, def);
+ if (maxlen != 0) {
+ RNA_def_property_string_maxlength(prop, maxlen + 1); /* +1 since it includes null terminator */
+ }
+ if (def && def[0]) {
+ RNA_def_property_string_default(prop, def);
+ }
RNA_def_property_ui_text(prop, name ? name : id, description);
if (py_tags) {
@@ -2890,8 +2949,12 @@ static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
}
}
- if (opts & PROP_ENUM_FLAG) prop = RNA_def_enum_flag(srna, id, eitems, defvalue, name ? name : id, description);
- else prop = RNA_def_enum(srna, id, eitems, defvalue, name ? name : id, description);
+ if (opts & PROP_ENUM_FLAG) {
+ prop = RNA_def_enum_flag(srna, id, eitems, defvalue, name ? name : id, description);
+ }
+ else {
+ prop = RNA_def_enum(srna, id, eitems, defvalue, name ? name : id, description);
+ }
if (py_tags) {
RNA_def_property_tags(prop, prop_tags);
@@ -2994,8 +3057,9 @@ PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw)
BPY_PROPDEF_CHECK(PointerProperty, property_flag_items);
ptype = pointer_type_from_py(type, "PointerProperty(...)");
- if (!ptype)
+ if (!ptype) {
return NULL;
+ }
if (!RNA_struct_is_a(ptype, &RNA_PropertyGroup) && !RNA_struct_is_ID(ptype)) {
PyErr_Format(PyExc_TypeError,
"PointerProperty(...) expected an RNA type derived from %.200s or %.200s",
@@ -3077,8 +3141,9 @@ PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
BPY_PROPDEF_CHECK(CollectionProperty, property_flag_items);
ptype = pointer_type_from_py(type, "CollectionProperty(...):");
- if (!ptype)
+ if (!ptype) {
return NULL;
+ }
if (!RNA_struct_is_a(ptype, &RNA_PropertyGroup)) {
PyErr_Format(
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index 4e96479242b..f695464ec42 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -314,8 +314,12 @@ static bool rna_id_write_error(PointerRNA *ptr, PyObject *key)
if (!ELEM(idcode, ID_WM, ID_SCR, ID_WS)) { /* may need more added here */
const char *idtype = BKE_idcode_to_name(idcode);
const char *pyname;
- if (key && PyUnicode_Check(key)) pyname = _PyUnicode_AsString(key);
- else pyname = "<UNKNOWN>";
+ if (key && PyUnicode_Check(key)) {
+ pyname = _PyUnicode_AsString(key);
+ }
+ else {
+ pyname = "<UNKNOWN>";
+ }
/* make a nice string error */
BLI_assert(idtype != NULL);
@@ -392,8 +396,9 @@ static int mathutils_rna_vector_get(BaseMathObject *bmo, int subtype)
PYRNA_PROP_CHECK_INT(self);
- if (self->prop == NULL)
+ if (self->prop == NULL) {
return -1;
+ }
RNA_property_float_get_array(&self->ptr, self->prop, bmo->data);
@@ -414,8 +419,9 @@ static int mathutils_rna_vector_set(BaseMathObject *bmo, int subtype)
PYRNA_PROP_CHECK_INT(self);
- if (self->prop == NULL)
+ if (self->prop == NULL) {
return -1;
+ }
#ifdef USE_PEDANTIC_WRITE
if (rna_disallow_writes && rna_id_write_error(&self->ptr, NULL)) {
@@ -465,8 +471,9 @@ static int mathutils_rna_vector_get_index(BaseMathObject *bmo, int UNUSED(subtyp
PYRNA_PROP_CHECK_INT(self);
- if (self->prop == NULL)
+ if (self->prop == NULL) {
return -1;
+ }
bmo->data[index] = RNA_property_float_get_index(&self->ptr, self->prop, index);
return 0;
@@ -478,8 +485,9 @@ static int mathutils_rna_vector_set_index(BaseMathObject *bmo, int UNUSED(subtyp
PYRNA_PROP_CHECK_INT(self);
- if (self->prop == NULL)
+ if (self->prop == NULL) {
return -1;
+ }
#ifdef USE_PEDANTIC_WRITE
if (rna_disallow_writes && rna_id_write_error(&self->ptr, NULL)) {
@@ -522,8 +530,9 @@ static int mathutils_rna_matrix_get(BaseMathObject *bmo, int UNUSED(subtype))
PYRNA_PROP_CHECK_INT(self);
- if (self->prop == NULL)
+ if (self->prop == NULL) {
return -1;
+ }
RNA_property_float_get_array(&self->ptr, self->prop, bmo->data);
return 0;
@@ -535,8 +544,9 @@ static int mathutils_rna_matrix_set(BaseMathObject *bmo, int UNUSED(subtype))
PYRNA_PROP_CHECK_INT(self);
- if (self->prop == NULL)
+ if (self->prop == NULL) {
return -1;
+ }
#ifdef USE_PEDANTIC_WRITE
if (rna_disallow_writes && rna_id_write_error(&self->ptr, NULL)) {
@@ -639,8 +649,10 @@ PyObject *pyrna_math_object_from_array(PointerRNA *ptr, PropertyRNA *prop)
totdim = RNA_property_array_dimension(ptr, prop, NULL);
if (totdim == 1 || (totdim == 2 && subtype == PROP_MATRIX)) {
- if (!is_thick)
- ret = pyrna_prop_CreatePyObject(ptr, prop); /* owned by the mathutils PyObject */
+ if (!is_thick) {
+ /* owned by the mathutils PyObject */
+ ret = pyrna_prop_CreatePyObject(ptr, prop);
+ }
switch (subtype) {
case PROP_ALL_VECTOR_SUBTYPES:
@@ -801,8 +813,9 @@ static PyObject *pyrna_struct_richcmp(PyObject *a, PyObject *b, int op)
PyObject *res;
int ok = -1; /* zero is true */
- if (BPy_StructRNA_Check(a) && BPy_StructRNA_Check(b))
+ if (BPy_StructRNA_Check(a) && BPy_StructRNA_Check(b)) {
ok = pyrna_struct_compare((BPy_StructRNA *)a, (BPy_StructRNA *)b);
+ }
switch (op) {
case Py_NE:
@@ -831,8 +844,9 @@ static PyObject *pyrna_prop_richcmp(PyObject *a, PyObject *b, int op)
PyObject *res;
int ok = -1; /* zero is true */
- if (BPy_PropertyRNA_Check(a) && BPy_PropertyRNA_Check(b))
+ if (BPy_PropertyRNA_Check(a) && BPy_PropertyRNA_Check(b)) {
ok = pyrna_prop_compare((BPy_PropertyRNA *)a, (BPy_PropertyRNA *)b);
+ }
switch (op) {
case Py_NE:
@@ -888,8 +902,10 @@ static PyObject *pyrna_struct_repr(BPy_StructRNA *self)
PyObject *tmp_str;
PyObject *ret;
- if (id == NULL || !PYRNA_STRUCT_IS_VALID(self))
- return pyrna_struct_str(self); /* fallback */
+ if (id == NULL || !PYRNA_STRUCT_IS_VALID(self)) {
+ /* fallback */
+ return pyrna_struct_str(self);
+ }
tmp_str = PyUnicode_FromString(id->name + 2);
@@ -959,8 +975,9 @@ static PyObject *pyrna_prop_str(BPy_PropertyRNA *self)
len = pyrna_prop_array_length((BPy_PropertyArrayRNA *)self);
}
- if (len != -1)
+ if (len != -1) {
sprintf(--c, "[%d]", len);
+ }
}
/* if a pointer, try to print name of pointer target too */
@@ -1004,8 +1021,10 @@ static PyObject *pyrna_prop_repr_ex(
PYRNA_PROP_CHECK_OBJ(self);
- if (id == NULL)
- return pyrna_prop_str(self); /* fallback */
+ if (id == NULL) {
+ /* fallback */
+ return pyrna_prop_str(self);
+ }
tmp_str = PyUnicode_FromString(id->name + 2);
@@ -1066,19 +1085,23 @@ static Py_hash_t pyrna_struct_hash(BPy_StructRNA *self)
static long pyrna_prop_hash(BPy_PropertyRNA *self)
{
long x, y;
- if (self->ptr.data == NULL)
+ if (self->ptr.data == NULL) {
x = 0;
+ }
else {
x = _Py_HashPointer(self->ptr.data);
- if (x == -1)
+ if (x == -1) {
return -1;
+ }
}
y = _Py_HashPointer((void *)(self->prop));
- if (y == -1)
+ if (y == -1) {
return -1;
+ }
x ^= y;
- if (x == -1)
+ if (x == -1) {
x = -2;
+ }
return x;
}
@@ -1425,8 +1448,9 @@ static PyObject *pyrna_enum_to_py(PointerRNA *ptr, PropertyRNA *prop, int val)
PyErr_Warn(PyExc_RuntimeWarning, error_str);
#endif
- if (ptr_name)
+ if (ptr_name) {
MEM_freeN((void *)ptr_name);
+ }
}
ret = PyUnicode_FromString("");
@@ -1582,7 +1606,9 @@ int pyrna_pydict_to_props(
while (PyDict_Next(kw, &pos, &key, &value)) {
arg_name = _PyUnicode_AsString(key);
- if (RNA_struct_find_property(ptr, arg_name) == NULL) break;
+ if (RNA_struct_find_property(ptr, arg_name) == NULL) {
+ break;
+ }
arg_name = NULL;
}
@@ -1649,8 +1675,12 @@ static int pyrna_py_to_prop(
return -1;
}
else {
- if (data) *((bool *)data) = param;
- else RNA_property_boolean_set(ptr, prop, param);
+ if (data) {
+ *((bool *)data) = param;
+ }
+ else {
+ RNA_property_boolean_set(ptr, prop, param);
+ }
}
break;
}
@@ -1755,8 +1785,12 @@ static int pyrna_py_to_prop(
return -1;
}
else {
- if (data) *((char **)data) = (char *)param;
- else RNA_property_string_set_bytes(ptr, prop, param, PyBytes_Size(value));
+ if (data) {
+ *((char **)data) = (char *)param;
+ }
+ else {
+ RNA_property_string_set_bytes(ptr, prop, param, PyBytes_Size(value));
+ }
}
}
else {
@@ -1796,8 +1830,12 @@ static int pyrna_py_to_prop(
else {
/* same as bytes */
/* XXX, this is suspect but needed for function calls, need to see if theres a better way */
- if (data) *((char **)data) = (char *)param;
- else RNA_property_string_set(ptr, prop, param);
+ if (data) {
+ *((char **)data) = (char *)param;
+ }
+ else {
+ RNA_property_string_set(ptr, prop, param);
+ }
}
#ifdef USE_STRING_COERCE
Py_XDECREF(value_coerce);
@@ -1823,8 +1861,12 @@ static int pyrna_py_to_prop(
}
}
- if (data) *((int *)data) = val;
- else RNA_property_enum_set(ptr, prop, val);
+ if (data) {
+ *((int *)data) = val;
+ }
+ else {
+ RNA_property_enum_set(ptr, prop, val);
+ }
break;
}
@@ -1922,23 +1964,29 @@ static int pyrna_py_to_prop(
if (flag_parameter & PARM_RNAPTR) {
if (flag & PROP_THICK_WRAP) {
- if (value == Py_None)
+ if (value == Py_None) {
memset(data, 0, sizeof(PointerRNA));
- else if (RNA_struct_is_a(param->ptr.type, ptr_type))
+ }
+ else if (RNA_struct_is_a(param->ptr.type, ptr_type)) {
*((PointerRNA *)data) = param->ptr;
- else
+ }
+ else {
raise_error = true;
+ }
}
else {
/* for function calls, we sometimes want to pass the 'ptr' directly,
* watch out that it remains valid!, possibly we could support this later if needed */
BLI_assert(value_new == NULL);
- if (value == Py_None)
+ if (value == Py_None) {
*((void **)data) = NULL;
- else if (RNA_struct_is_a(param->ptr.type, ptr_type))
+ }
+ else if (RNA_struct_is_a(param->ptr.type, ptr_type)) {
*((PointerRNA **)data) = &param->ptr;
- else
+ }
+ else {
raise_error = true;
+ }
}
}
else if (value == Py_None) {
@@ -1953,10 +2001,12 @@ static int pyrna_py_to_prop(
}
else {
/* data == NULL, assign to RNA */
- if (value == Py_None || RNA_struct_is_a(param->ptr.type, ptr_type))
+ if (value == Py_None || RNA_struct_is_a(param->ptr.type, ptr_type)) {
RNA_property_pointer_set(ptr, prop, value == Py_None ? PointerRNA_NULL : param->ptr);
- else
+ }
+ else {
raise_error = true;
+ }
}
if (raise_error) {
@@ -2027,8 +2077,9 @@ static int pyrna_py_to_prop(
link->ptr = itemptr;
BLI_addtail(lb, link);
}
- else
+ else {
RNA_property_collection_add(ptr, prop, &itemptr);
+ }
if (pyrna_pydict_to_props(
&itemptr, item, true,
@@ -2152,10 +2203,12 @@ static Py_ssize_t pyrna_prop_array_length(BPy_PropertyArrayRNA *self)
{
PYRNA_PROP_CHECK_INT((BPy_PropertyRNA *)self);
- if (RNA_property_array_dimension(&self->ptr, self->prop, NULL) > 1)
+ if (RNA_property_array_dimension(&self->ptr, self->prop, NULL) > 1) {
return RNA_property_multi_array_length(&self->ptr, self->prop, self->arraydim);
- else
+ }
+ else {
return RNA_property_array_length(&self->ptr, self->prop);
+ }
}
static Py_ssize_t pyrna_prop_collection_length(BPy_PropertyRNA *self)
@@ -2271,10 +2324,13 @@ static PyObject *pyrna_prop_array_subscript_int(BPy_PropertyArrayRNA *self, int
len = pyrna_prop_array_length(self);
- if (keynum < 0) keynum += len;
+ if (keynum < 0) {
+ keynum += len;
+ }
- if (keynum >= 0 && keynum < len)
+ if (keynum >= 0 && keynum < len) {
return pyrna_prop_array_to_py_index(self, keynum);
+ }
PyErr_Format(PyExc_IndexError,
"bpy_prop_array[index]: index %d out of range", keynum);
@@ -2287,8 +2343,9 @@ static PyObject *pyrna_prop_collection_subscript_str(BPy_PropertyRNA *self, cons
PYRNA_PROP_CHECK_OBJ(self);
- if (RNA_property_collection_lookup_string(&self->ptr, self->prop, keyname, &newptr))
+ if (RNA_property_collection_lookup_string(&self->ptr, self->prop, keyname, &newptr)) {
return pyrna_struct_CreatePyObject(&newptr);
+ }
PyErr_Format(PyExc_KeyError, "bpy_prop_collection[key]: key \"%.200s\" not found", keyname);
return NULL;
@@ -2463,8 +2520,9 @@ static PyObject *pyrna_prop_array_subscript_slice(
totdim = RNA_property_array_dimension(ptr, prop, NULL);
if (totdim > 1) {
- for (count = start; count < stop; count++)
+ for (count = start; count < stop; count++) {
PyTuple_SET_ITEM(tuple, count - start, pyrna_prop_array_to_py_index(self, count));
+ }
}
else {
switch (RNA_property_type(prop)) {
@@ -2476,8 +2534,9 @@ static PyObject *pyrna_prop_array_subscript_slice(
else { values = values_stack; }
RNA_property_float_get_array(ptr, prop, values);
- for (count = start; count < stop; count++)
+ for (count = start; count < stop; count++) {
PyTuple_SET_ITEM(tuple, count - start, PyFloat_FromDouble(values[count]));
+ }
if (values != values_stack) {
PyMem_FREE(values);
@@ -2492,8 +2551,9 @@ static PyObject *pyrna_prop_array_subscript_slice(
else { values = values_stack; }
RNA_property_boolean_get_array(ptr, prop, values);
- for (count = start; count < stop; count++)
+ for (count = start; count < stop; count++) {
PyTuple_SET_ITEM(tuple, count - start, PyBool_FromLong(values[count]));
+ }
if (values != values_stack) {
PyMem_FREE(values);
@@ -2508,8 +2568,9 @@ static PyObject *pyrna_prop_array_subscript_slice(
else { values = values_stack; }
RNA_property_int_get_array(ptr, prop, values);
- for (count = start; count < stop; count++)
+ for (count = start; count < stop; count++) {
PyTuple_SET_ITEM(tuple, count - start, PyLong_FromLong(values[count]));
+ }
if (values != values_stack) {
PyMem_FREE(values);
@@ -2537,8 +2598,9 @@ static PyObject *pyrna_prop_collection_subscript(BPy_PropertyRNA *self, PyObject
}
else if (PyIndex_Check(key)) {
Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
- if (i == -1 && PyErr_Occurred())
+ if (i == -1 && PyErr_Occurred()) {
return NULL;
+ }
return pyrna_prop_collection_subscript_int(self, i);
}
@@ -2560,14 +2622,22 @@ static PyObject *pyrna_prop_collection_subscript(BPy_PropertyRNA *self, PyObject
Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX;
/* avoid PySlice_GetIndicesEx because it needs to know the length ahead of time. */
- if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) return NULL;
- if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) return NULL;
+ if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) {
+ return NULL;
+ }
+ if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) {
+ return NULL;
+ }
if (start < 0 || stop < 0) {
/* only get the length for negative values */
Py_ssize_t len = (Py_ssize_t)RNA_property_collection_length(&self->ptr, self->prop);
- if (start < 0) start += len;
- if (stop < 0) stop += len;
+ if (start < 0) {
+ start += len;
+ }
+ if (stop < 0) {
+ stop += len;
+ }
}
if (stop - start <= 0) {
@@ -2662,8 +2732,9 @@ static int pyrna_prop_collection_ass_subscript(BPy_PropertyRNA *self, PyObject *
#endif
if (PyIndex_Check(key)) {
Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
- if (i == -1 && PyErr_Occurred())
+ if (i == -1 && PyErr_Occurred()) {
return -1;
+ }
return pyrna_prop_collection_ass_subscript_int(self, i, value);
}
@@ -2726,8 +2797,9 @@ static PyObject *pyrna_prop_array_subscript(BPy_PropertyArrayRNA *self, PyObject
#endif
if (PyIndex_Check(key)) {
Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
- if (i == -1 && PyErr_Occurred())
+ if (i == -1 && PyErr_Occurred()) {
return NULL;
+ }
return pyrna_prop_array_subscript_int(self, i);
}
else if (PySlice_Check(key)) {
@@ -2751,8 +2823,9 @@ static PyObject *pyrna_prop_array_subscript(BPy_PropertyArrayRNA *self, PyObject
int len = pyrna_prop_array_length(self);
Py_ssize_t start, stop, slicelength;
- if (PySlice_GetIndicesEx(key, len, &start, &stop, &step, &slicelength) < 0)
+ if (PySlice_GetIndicesEx(key, len, &start, &stop, &step, &slicelength) < 0) {
return NULL;
+ }
if (slicelength <= 0) {
return PyTuple_New(0);
@@ -2963,8 +3036,12 @@ static int prop_subscript_ass_array_slice(
totdim - arraydim, &dimsize[arraydim],
range);
- if (PyErr_Occurred()) ret = -1;
- else RNA_property_float_set_array(ptr, prop, values);
+ if (PyErr_Occurred()) {
+ ret = -1;
+ }
+ else {
+ RNA_property_float_set_array(ptr, prop, values);
+ }
break;
}
case PROP_INT:
@@ -2986,8 +3063,12 @@ static int prop_subscript_ass_array_slice(
totdim - arraydim, &dimsize[arraydim],
range);
- if (PyErr_Occurred()) ret = -1;
- else RNA_property_int_set_array(ptr, prop, values);
+ if (PyErr_Occurred()) {
+ ret = -1;
+ }
+ else {
+ RNA_property_int_set_array(ptr, prop, values);
+ }
break;
}
case PROP_BOOLEAN:
@@ -3006,8 +3087,12 @@ static int prop_subscript_ass_array_slice(
value_items, &values[arrayoffset + (start * span)],
totdim - arraydim, &dimsize[arraydim]);
- if (PyErr_Occurred()) ret = -1;
- else RNA_property_boolean_set_array(ptr, prop, values);
+ if (PyErr_Occurred()) {
+ ret = -1;
+ }
+ else {
+ RNA_property_boolean_set_array(ptr, prop, values);
+ }
break;
}
default:
@@ -3034,10 +3119,13 @@ static int prop_subscript_ass_array_int(BPy_PropertyArrayRNA *self, Py_ssize_t k
len = pyrna_prop_array_length(self);
- if (keynum < 0) keynum += len;
+ if (keynum < 0) {
+ keynum += len;
+ }
- if (keynum >= 0 && keynum < len)
+ if (keynum >= 0 && keynum < len) {
return pyrna_py_to_prop_array_index(self, keynum, value);
+ }
PyErr_SetString(PyExc_IndexError,
"bpy_prop_array[index] = value: index out of range");
@@ -3165,8 +3253,9 @@ static int pyrna_prop_collection_contains(BPy_PropertyRNA *self, PyObject *key)
return -1;
}
- if (RNA_property_collection_lookup_string(&self->ptr, self->prop, keyname, &newptr))
+ if (RNA_property_collection_lookup_string(&self->ptr, self->prop, keyname, &newptr)) {
return 1;
+ }
return 0;
}
@@ -3191,8 +3280,9 @@ static int pyrna_struct_contains(BPy_StructRNA *self, PyObject *value)
group = RNA_struct_idprops(&self->ptr, 0);
- if (!group)
+ if (!group) {
return 0;
+ }
return IDP_GetPropertyFromGroup(group, name) ? 1 : 0;
}
@@ -3335,8 +3425,9 @@ static PyObject *pyrna_struct_keys(BPy_PropertyRNA *self)
group = RNA_struct_idprops(&self->ptr, 0);
- if (group == NULL)
+ if (group == NULL) {
return PyList_New(0);
+ }
return BPy_Wrap_GetKeys(group);
}
@@ -3363,8 +3454,9 @@ static PyObject *pyrna_struct_items(BPy_PropertyRNA *self)
group = RNA_struct_idprops(&self->ptr, 0);
- if (group == NULL)
+ if (group == NULL) {
return PyList_New(0);
+ }
return BPy_Wrap_GetItems(self->ptr.id.data, group);
}
@@ -3391,8 +3483,9 @@ static PyObject *pyrna_struct_values(BPy_PropertyRNA *self)
group = RNA_struct_idprops(&self->ptr, 0);
- if (group == NULL)
+ if (group == NULL) {
return PyList_New(0);
+ }
return BPy_Wrap_GetValues(self->ptr.id.data, group);
}
@@ -3413,8 +3506,9 @@ static PyObject *pyrna_struct_is_property_set(BPy_StructRNA *self, PyObject *arg
PYRNA_STRUCT_CHECK_OBJ(self);
- if (!PyArg_ParseTuple(args, "s:is_property_set", &name))
+ if (!PyArg_ParseTuple(args, "s:is_property_set", &name)) {
return NULL;
+ }
if ((prop = RNA_struct_find_property(&self->ptr, name)) == NULL) {
PyErr_Format(PyExc_TypeError,
@@ -3438,8 +3532,9 @@ static PyObject *pyrna_struct_property_unset(BPy_StructRNA *self, PyObject *args
PYRNA_STRUCT_CHECK_OBJ(self);
- if (!PyArg_ParseTuple(args, "s:property_unset", &name))
+ if (!PyArg_ParseTuple(args, "s:property_unset", &name)) {
return NULL;
+ }
if ((prop = RNA_struct_find_property(&self->ptr, name)) == NULL) {
PyErr_Format(PyExc_TypeError,
@@ -3468,8 +3563,9 @@ static PyObject *pyrna_struct_is_property_hidden(BPy_StructRNA *self, PyObject *
PYRNA_STRUCT_CHECK_OBJ(self);
- if (!PyArg_ParseTuple(args, "s:is_property_hidden", &name))
+ if (!PyArg_ParseTuple(args, "s:is_property_hidden", &name)) {
return NULL;
+ }
if ((prop = RNA_struct_find_property(&self->ptr, name)) == NULL) {
PyErr_Format(PyExc_TypeError,
@@ -3496,8 +3592,9 @@ static PyObject *pyrna_struct_is_property_readonly(BPy_StructRNA *self, PyObject
PYRNA_STRUCT_CHECK_OBJ(self);
- if (!PyArg_ParseTuple(args, "s:is_property_readonly", &name))
+ if (!PyArg_ParseTuple(args, "s:is_property_readonly", &name)) {
return NULL;
+ }
if ((prop = RNA_struct_find_property(&self->ptr, name)) == NULL) {
PyErr_Format(PyExc_TypeError,
@@ -3592,8 +3689,9 @@ static PyObject *pyrna_struct_path_resolve(BPy_StructRNA *self, PyObject *args)
PYRNA_STRUCT_CHECK_OBJ(self);
- if (!PyArg_ParseTuple(args, "s|O!:path_resolve", &path, &PyBool_Type, &coerce))
+ if (!PyArg_ParseTuple(args, "s|O!:path_resolve", &path, &PyBool_Type, &coerce)) {
return NULL;
+ }
if (RNA_path_resolve_full(&self->ptr, path, &r_ptr, &r_prop, &index)) {
if (r_prop) {
@@ -3650,8 +3748,9 @@ static PyObject *pyrna_struct_path_from_id(BPy_StructRNA *self, PyObject *args)
PYRNA_STRUCT_CHECK_OBJ(self);
- if (!PyArg_ParseTuple(args, "|s:path_from_id", &name))
+ if (!PyArg_ParseTuple(args, "|s:path_from_id", &name)) {
return NULL;
+ }
if (name) {
prop = RNA_struct_find_property(&self->ptr, name);
@@ -3990,8 +4089,9 @@ static PyObject *pyrna_struct_dir(BPy_StructRNA *self)
* */
ret = PyList_New(0);
- if (!BPy_StructRNA_CheckExact(self))
+ if (!BPy_StructRNA_CheckExact(self)) {
pyrna_dir_members_py(ret, (PyObject *)self);
+ }
pyrna_dir_members_rna(ret, &self->ptr);
@@ -4636,8 +4736,9 @@ static PyObject *pyrna_prop_collection_items(BPy_PropertyRNA *self)
nameptr = RNA_struct_name_get_alloc(&itemptr, name, sizeof(name), &namelen);
if (nameptr) {
PyTuple_SET_ITEM(item, 0, PyUnicode_FromStringAndSize(nameptr, namelen));
- if (name != nameptr)
+ if (name != nameptr) {
MEM_freeN(nameptr);
+ }
}
else {
/* a bit strange but better then returning an empty list */
@@ -4693,8 +4794,9 @@ static PyObject *pyrna_struct_get(BPy_StructRNA *self, PyObject *args)
PYRNA_STRUCT_CHECK_OBJ(self);
- if (!PyArg_ParseTuple(args, "s|O:get", &key, &def))
+ if (!PyArg_ParseTuple(args, "s|O:get", &key, &def)) {
return NULL;
+ }
/* mostly copied from BPy_IDGroup_Map_GetItem */
if (RNA_struct_idprops_check(self->ptr.type) == 0) {
@@ -4737,8 +4839,9 @@ static PyObject *pyrna_struct_pop(BPy_StructRNA *self, PyObject *args)
PYRNA_STRUCT_CHECK_OBJ(self);
- if (!PyArg_ParseTuple(args, "s|O:get", &key, &def))
+ if (!PyArg_ParseTuple(args, "s|O:get", &key, &def)) {
return NULL;
+ }
/* mostly copied from BPy_IDGroup_Map_GetItem */
if (RNA_struct_idprops_check(self->ptr.type) == 0) {
@@ -4801,14 +4904,16 @@ static PyObject *pyrna_prop_collection_get(BPy_PropertyRNA *self, PyObject *args
PYRNA_PROP_CHECK_OBJ(self);
- if (!PyArg_ParseTuple(args, "O|O:get", &key_ob, &def))
+ if (!PyArg_ParseTuple(args, "O|O:get", &key_ob, &def)) {
return NULL;
+ }
if (PyUnicode_Check(key_ob)) {
const char *key = _PyUnicode_AsString(key_ob);
- if (RNA_property_collection_lookup_string(&self->ptr, self->prop, key, &newptr))
+ if (RNA_property_collection_lookup_string(&self->ptr, self->prop, key, &newptr)) {
return pyrna_struct_CreatePyObject(&newptr);
+ }
}
else if (PyTuple_Check(key_ob)) {
PyObject *ret = pyrna_prop_collection_subscript_str_lib_pair(self, key_ob,
@@ -4942,13 +5047,16 @@ static int foreach_parse_args(
*size = RNA_raw_type_sizeof(*raw_type);
#if 0 /* works fine but not strictly needed, we could allow RNA_property_collection_raw_* to do the checks */
- if ((*attr_tot) < 1)
+ if ((*attr_tot) < 1) {
*attr_tot = 1;
+ }
- if (RNA_property_type(self->prop) == PROP_COLLECTION)
+ if (RNA_property_type(self->prop) == PROP_COLLECTION) {
array_tot = RNA_property_collection_length(&self->ptr, self->prop);
- else
+ }
+ else {
array_tot = RNA_property_array_length(&self->ptr, self->prop);
+ }
target_tot = array_tot * (*attr_tot);
@@ -4978,14 +5086,26 @@ static bool foreach_compat_buffer(RawPropertyType raw_type, int attr_signed, con
switch (raw_type) {
case PROP_RAW_CHAR:
- if (attr_signed) return (f == 'b') ? 1 : 0;
- else return (f == 'B') ? 1 : 0;
+ if (attr_signed) {
+ return (f == 'b') ? 1 : 0;
+ }
+ else {
+ return (f == 'B') ? 1 : 0;
+ }
case PROP_RAW_SHORT:
- if (attr_signed) return (f == 'h') ? 1 : 0;
- else return (f == 'H') ? 1 : 0;
+ if (attr_signed) {
+ return (f == 'h') ? 1 : 0;
+ }
+ else {
+ return (f == 'H') ? 1 : 0;
+ }
case PROP_RAW_INT:
- if (attr_signed) return (f == 'i') ? 1 : 0;
- else return (f == 'I') ? 1 : 0;
+ if (attr_signed) {
+ return (f == 'i') ? 1 : 0;
+ }
+ else {
+ return (f == 'I') ? 1 : 0;
+ }
case PROP_RAW_BOOLEAN:
return (f == '?') ? 1 : 0;
case PROP_RAW_FLOAT:
@@ -5013,11 +5133,13 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set)
bool attr_signed;
RawPropertyType raw_type;
- if (foreach_parse_args(self, args, &attr, &seq, &tot, &size, &raw_type, &attr_tot, &attr_signed) == -1)
+ if (foreach_parse_args(self, args, &attr, &seq, &tot, &size, &raw_type, &attr_tot, &attr_signed) == -1) {
return NULL;
+ }
- if (tot == 0)
+ if (tot == 0) {
Py_RETURN_NONE;
+ }
@@ -5098,7 +5220,10 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set)
ok = RNA_property_collection_raw_get(NULL, &self->ptr, self->prop, attr, array, raw_type, tot);
- if (!ok) i = tot; /* skip the loop */
+ if (!ok) {
+ /* skip the loop */
+ i = tot;
+ }
for ( ; i < tot; i++) {
@@ -5135,8 +5260,9 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set)
}
}
- if (array)
+ if (array) {
PyMem_Free(array);
+ }
if (PyErr_Occurred()) {
/* Maybe we could make our own error */
@@ -5348,8 +5474,9 @@ static PyObject *pyrna_prop_new(PyTypeObject *type, PyObject *args, PyObject *UN
{
BPy_PropertyRNA *base;
- if (!PyArg_ParseTuple(args, "O!:bpy_prop.__new__", &pyrna_prop_Type, &base))
+ if (!PyArg_ParseTuple(args, "O!:bpy_prop.__new__", &pyrna_prop_Type, &base)) {
return NULL;
+ }
if (type == Py_TYPE(base)) {
return Py_INCREF_RET((PyObject *)base);
@@ -5383,8 +5510,9 @@ static PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *dat
len = data_alloc->array_tot;
data = data_alloc->array;
}
- else
+ else {
len = RNA_property_array_length(ptr, prop);
+ }
/* resolve the array from a new pytype */
@@ -5393,13 +5521,15 @@ static PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *dat
switch (type) {
case PROP_BOOLEAN:
ret = PyTuple_New(len);
- for (a = 0; a < len; a++)
+ for (a = 0; a < len; a++) {
PyTuple_SET_ITEM(ret, a, PyBool_FromLong(((bool *)data)[a]));
+ }
break;
case PROP_INT:
ret = PyTuple_New(len);
- for (a = 0; a < len; a++)
+ for (a = 0; a < len; a++) {
PyTuple_SET_ITEM(ret, a, PyLong_FromLong(((int *)data)[a]));
+ }
break;
case PROP_FLOAT:
switch (RNA_property_subtype(prop)) {
@@ -5420,8 +5550,9 @@ static PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *dat
#endif
default:
ret = PyTuple_New(len);
- for (a = 0; a < len; a++)
+ for (a = 0; a < len; a++) {
PyTuple_SET_ITEM(ret, a, PyFloat_FromDouble(((float *)data)[a]));
+ }
break;
}
break;
@@ -5451,10 +5582,12 @@ static PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *dat
PyObject *value_coerce = NULL;
const int subtype = RNA_property_subtype(prop);
- if (flag & PROP_THICK_WRAP)
+ if (flag & PROP_THICK_WRAP) {
data_ch = (char *)data;
- else
+ }
+ else {
data_ch = *(char **)data;
+ }
#ifdef USE_STRING_COERCE
if (subtype == PROP_BYTESTRING) {
@@ -5674,8 +5807,9 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject
#else
item = small_dict_get_item_string(kw, RNA_property_identifier(parm)); /* borrow ref */
#endif
- if (item)
+ if (item) {
kw_tot++; /* make sure invalid keywords are not given */
+ }
kw_arg = true;
}
@@ -5712,19 +5846,21 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject
char error_prefix[512];
PyErr_Clear(); /* re-raise */
- if (kw_arg == true)
+ if (kw_arg == true) {
BLI_snprintf(error_prefix, sizeof(error_prefix),
"%.200s.%.200s(): error with keyword argument \"%.200s\" - ",
RNA_struct_identifier(self_ptr->type),
RNA_function_identifier(self_func),
RNA_property_identifier(parm));
- else
+ }
+ else {
BLI_snprintf(error_prefix, sizeof(error_prefix),
"%.200s.%.200s(): error with argument %d, \"%.200s\" - ",
RNA_struct_identifier(self_ptr->type),
RNA_function_identifier(self_func),
i,
RNA_property_identifier(parm));
+ }
pyrna_py_to_prop(&funcptr, parm, iter.data, item, error_prefix);
@@ -5783,8 +5919,9 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject
RNA_parameter_list_begin(&parms, &iter);
for (; iter.valid; RNA_parameter_list_next(&iter)) {
parm = iter.parm;
- if (RNA_parameter_flag(parm) & PARM_OUTPUT)
+ if (RNA_parameter_flag(parm) & PARM_OUTPUT) {
continue;
+ }
BLI_dynstr_appendf(good_args, first ? "%s" : ", %s", RNA_property_identifier(parm));
first = false;
@@ -5831,18 +5968,21 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject
for (; iter.valid; RNA_parameter_list_next(&iter)) {
parm = iter.parm;
- if (RNA_parameter_flag(parm) & PARM_OUTPUT)
+ if (RNA_parameter_flag(parm) & PARM_OUTPUT) {
PyTuple_SET_ITEM(ret, i++, pyrna_param_to_py(&funcptr, parm, iter.data));
+ }
}
RNA_parameter_list_end(&iter);
}
- else
+ else {
ret = pyrna_param_to_py(&funcptr, pret_single, retdata_single);
+ }
/* possible there is an error in conversion */
- if (ret == NULL)
+ if (ret == NULL) {
err = -1;
+ }
}
}
}
@@ -5865,11 +6005,13 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject
RNA_parameter_list_end(&iter);
RNA_parameter_list_free(&parms);
- if (ret)
+ if (ret) {
return ret;
+ }
- if (err == -1)
+ if (err == -1) {
return NULL;
+ }
Py_RETURN_NONE;
}
@@ -6660,8 +6802,9 @@ static void pyrna_subtype_set_rna(PyObject *newclass, StructRNA *srna)
Py_INCREF(newclass);
- if (RNA_struct_py_type_get(srna))
+ if (RNA_struct_py_type_get(srna)) {
PyC_ObSpit("RNA WAS SET - ", RNA_struct_py_type_get(srna));
+ }
Py_XDECREF(((PyObject *)RNA_struct_py_type_get(srna)));
@@ -7074,30 +7217,38 @@ void BPY_rna_init(void)
#endif
/* metaclass */
- if (PyType_Ready(&pyrna_struct_meta_idprop_Type) < 0)
+ if (PyType_Ready(&pyrna_struct_meta_idprop_Type) < 0) {
return;
+ }
- if (PyType_Ready(&pyrna_struct_Type) < 0)
+ if (PyType_Ready(&pyrna_struct_Type) < 0) {
return;
+ }
- if (PyType_Ready(&pyrna_prop_Type) < 0)
+ if (PyType_Ready(&pyrna_prop_Type) < 0) {
return;
+ }
- if (PyType_Ready(&pyrna_prop_array_Type) < 0)
+ if (PyType_Ready(&pyrna_prop_array_Type) < 0) {
return;
+ }
- if (PyType_Ready(&pyrna_prop_collection_Type) < 0)
+ if (PyType_Ready(&pyrna_prop_collection_Type) < 0) {
return;
+ }
- if (PyType_Ready(&pyrna_prop_collection_idprop_Type) < 0)
+ if (PyType_Ready(&pyrna_prop_collection_idprop_Type) < 0) {
return;
+ }
- if (PyType_Ready(&pyrna_func_Type) < 0)
+ if (PyType_Ready(&pyrna_func_Type) < 0) {
return;
+ }
#ifdef USE_PYRNA_ITER
- if (PyType_Ready(&pyrna_prop_collection_iter_Type) < 0)
+ if (PyType_Ready(&pyrna_prop_collection_iter_Type) < 0) {
return;
+ }
#endif
}
@@ -7239,8 +7390,9 @@ PyObject *BPY_rna_types(void)
pyrna_basetype_Type.tp_flags = Py_TPFLAGS_DEFAULT;
pyrna_basetype_Type.tp_methods = pyrna_basetype_methods;
- if (PyType_Ready(&pyrna_basetype_Type) < 0)
+ if (PyType_Ready(&pyrna_basetype_Type) < 0) {
return NULL;
+ }
}
/* static members for the base class */
@@ -7288,8 +7440,9 @@ StructRNA *pyrna_struct_as_srna(PyObject *self, const bool parent, const char *e
if (parent) {
/* be very careful with this since it will return a parent classes srna.
* modifying this will do confusing stuff! */
- if (py_srna == NULL)
+ if (py_srna == NULL) {
py_srna = (BPy_StructRNA *)PyObject_GetAttr(self, bpy_intern_str_bl_rna);
+ }
}
if (py_srna == NULL) {
@@ -7473,8 +7626,9 @@ static int pyrna_deferred_register_props(StructRNA *srna, PyObject *class_dict)
}
ret = deferred_register_prop(srna, key, item);
- if (ret != 0)
+ if (ret != 0) {
break;
+ }
}
}
@@ -7518,8 +7672,9 @@ int pyrna_deferred_register_class(StructRNA *srna, PyTypeObject *py_class)
{
/* Panels and Menus don't need this
* save some time and skip the checks here */
- if (!RNA_struct_idprops_register_check(srna))
+ if (!RNA_struct_idprops_register_check(srna)) {
return 0;
+ }
return pyrna_deferred_register_class_recursive(srna, py_class);
}
@@ -7541,16 +7696,18 @@ static int rna_function_arg_count(FunctionRNA *func, int *min_count)
if (!(RNA_parameter_flag(parm) & PARM_OUTPUT)) {
if (!done_min_count && (RNA_parameter_flag(parm) & PARM_PYFUNC_OPTIONAL)) {
/* From now on, following parameters are optional in py func */
- if (min_count)
+ if (min_count) {
*min_count = count;
+ }
done_min_count = true;
}
count++;
}
}
- if (!done_min_count && min_count)
+ if (!done_min_count && min_count) {
*min_count = count;
+ }
return count;
}
@@ -7567,8 +7724,9 @@ static int bpy_class_validate_recursive(PointerRNA *dummyptr, StructRNA *srna, v
const char *py_class_name = ((PyTypeObject *)py_class)->tp_name; /* __name__ */
if (srna_base) {
- if (bpy_class_validate_recursive(dummyptr, srna_base, py_data, have_function) != 0)
+ if (bpy_class_validate_recursive(dummyptr, srna_base, py_data, have_function) != 0) {
return -1;
+ }
}
if (base_class) {
@@ -7591,8 +7749,9 @@ static int bpy_class_validate_recursive(PointerRNA *dummyptr, StructRNA *srna, v
* Keep this as-is since its working but we should be using 'FUNC_USE_SELF_TYPE' for many functions. */
const bool is_staticmethod = (flag & FUNC_NO_SELF) && !(flag & FUNC_USE_SELF_TYPE);
- if (!(flag & FUNC_REGISTER))
+ if (!(flag & FUNC_REGISTER)) {
continue;
+ }
item = PyObject_GetAttrString(py_class, RNA_function_identifier(func));
@@ -7672,8 +7831,9 @@ static int bpy_class_validate_recursive(PointerRNA *dummyptr, StructRNA *srna, v
PropertyRNA *prop = (PropertyRNA *)link;
const int flag = RNA_property_flag(prop);
- if (!(flag & PROP_REGISTER))
+ if (!(flag & PROP_REGISTER)) {
continue;
+ }
/* TODO(campbell): Use Python3.7x _PyObject_LookupAttr(), also in the macro below. */
identifier = RNA_property_identifier(prop);
@@ -7769,8 +7929,9 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param
/* XXX, this is needed because render engine calls without a context
* this should be supported at some point but at the moment its not! */
- if (C == NULL)
+ if (C == NULL) {
C = BPy_GetContext();
+ }
/* annoying!, need to check if the screen gets set to NULL which is a
* hint that the file was actually re-loaded. */
@@ -7792,8 +7953,9 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param
}
/* end exception */
- if (py_class_instance == NULL)
+ if (py_class_instance == NULL) {
py_srna = pyrna_struct_CreatePyObject(ptr);
+ }
if (py_class_instance) {
/* special case, instance is cached */
@@ -8055,8 +8217,9 @@ static void bpy_class_free(void *pyob_ptr)
/* remove the rna attribute instead. */
PyDict_DelItem(((PyTypeObject *)self)->tp_dict, bpy_intern_str_bl_rna);
- if (PyErr_Occurred())
+ if (PyErr_Occurred()) {
PyErr_Clear();
+ }
#if 0 /* needs further investigation, too annoying so quiet for now */
if (G.debug & G_DEBUG_PYTHON) {
@@ -8197,8 +8360,9 @@ static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class
/* warning: gets parent classes srna, only for the register function */
srna = pyrna_struct_as_srna(py_class, true, "register_class(...):");
- if (srna == NULL)
+ if (srna == NULL) {
return NULL;
+ }
/* fails in cases, cant use this check but would like to :| */
#if 0
@@ -8245,8 +8409,9 @@ static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class
/* python errors validating are not converted into reports so the check above will fail.
* the cause for returning NULL will be printed as an error */
- if (srna_new == NULL)
+ if (srna_new == NULL) {
return NULL;
+ }
pyrna_subtype_set_rna(py_class, srna_new); /* takes a ref to py_class */
@@ -8260,8 +8425,9 @@ static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class
*
* item = PyObject_GetAttrString(py_class, "__dict__");
*/
- if (pyrna_deferred_register_class(srna_new, (PyTypeObject *)py_class) != 0)
+ if (pyrna_deferred_register_class(srna_new, (PyTypeObject *)py_class) != 0) {
return NULL;
+ }
/* call classed register method () */
switch (_PyObject_LookupAttr(py_class, bpy_intern_str_register, &py_cls_meth)) {
@@ -8354,8 +8520,9 @@ static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_cla
}
srna = pyrna_struct_as_srna(py_class, false, "unregister_class(...):");
- if (srna == NULL)
+ if (srna == NULL) {
return NULL;
+ }
/* check that we have a unregister callback for this type */
unreg = RNA_struct_unregister(srna);
@@ -8423,8 +8590,9 @@ static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_cla
unreg(CTX_data_main(C), srna); /* calls bpy_class_free, this decref's py_class */
PyDict_DelItem(((PyTypeObject *)py_class)->tp_dict, bpy_intern_str_bl_rna);
- if (PyErr_Occurred())
+ if (PyErr_Occurred()) {
PyErr_Clear(); //return NULL;
+ }
Py_RETURN_NONE;
}
diff --git a/source/blender/python/intern/bpy_rna_anim.c b/source/blender/python/intern/bpy_rna_anim.c
index faead661f1f..a25906ac9a1 100644
--- a/source/blender/python/intern/bpy_rna_anim.c
+++ b/source/blender/python/intern/bpy_rna_anim.c
@@ -339,8 +339,9 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb
}
MEM_freeN((void *)path_full);
- if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1)
+ if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) {
return NULL;
+ }
return PyBool_FromLong(result);
}
@@ -356,8 +357,9 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb
result = insert_keyframe(G_MAIN, depsgraph, &reports, id, NULL, group_name, path_full, index, cfra, keytype, NULL, options);
MEM_freeN((void *)path_full);
- if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1)
+ if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) {
return NULL;
+ }
return PyBool_FromLong(result);
}
@@ -452,8 +454,9 @@ PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args, PyOb
}
MEM_freeN((void *)path_full);
- if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1)
+ if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) {
return NULL;
+ }
return PyBool_FromLong(result);
}
@@ -466,8 +469,9 @@ PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args, PyOb
result = delete_keyframe(G.main, &reports, (ID *)self->ptr.id.data, NULL, group_name, path_full, index, cfra, 0);
MEM_freeN((void *)path_full);
- if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1)
+ if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) {
return NULL;
+ }
return PyBool_FromLong(result);
}
@@ -493,8 +497,9 @@ PyObject *pyrna_struct_driver_add(BPy_StructRNA *self, PyObject *args)
PYRNA_STRUCT_CHECK_OBJ(self);
- if (!PyArg_ParseTuple(args, "s|i:driver_add", &path, &index))
+ if (!PyArg_ParseTuple(args, "s|i:driver_add", &path, &index)) {
return NULL;
+ }
if (pyrna_struct_anim_args_parse(
&self->ptr, "bpy_struct.driver_add():", path,
@@ -512,8 +517,9 @@ PyObject *pyrna_struct_driver_add(BPy_StructRNA *self, PyObject *args)
result = ANIM_add_driver(&reports, (ID *)self->ptr.id.data, path_full, index,
CREATEDRIVER_WITH_FMODIFIER, DRIVER_TYPE_PYTHON);
- if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1)
+ if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) {
return NULL;
+ }
if (result) {
ID *id = self->ptr.id.data;
@@ -592,8 +598,9 @@ PyObject *pyrna_struct_driver_remove(BPy_StructRNA *self, PyObject *args)
MEM_freeN((void *)path_full);
}
- if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1)
+ if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) {
return NULL;
+ }
WM_event_add_notifier(BPy_GetContext(), NC_ANIMATION | ND_FCURVES_ORDER, NULL);
diff --git a/source/blender/python/intern/bpy_rna_array.c b/source/blender/python/intern/bpy_rna_array.c
index a87da8782bc..4cc3c4c0fae 100644
--- a/source/blender/python/intern/bpy_rna_array.c
+++ b/source/blender/python/intern/bpy_rna_array.c
@@ -276,8 +276,9 @@ static int validate_array_length(PyObject *rvalue, PointerRNA *ptr, PropertyRNA
*
* arr[2][3][4] = x
* lvalue_dim = 2 */
- for (i = lvalue_dim; i < totdim; i++)
+ for (i = lvalue_dim; i < totdim; i++) {
len *= dimsize[i];
+ }
}
if (tot != len) {
@@ -308,8 +309,9 @@ static int validate_array(PyObject *rvalue, PointerRNA *ptr, PropertyRNA *prop,
if (MatrixObject_Check(rvalue)) {
MatrixObject *pymat = (MatrixObject *)rvalue;
- if (BaseMath_ReadCallback(pymat) == -1)
+ if (BaseMath_ReadCallback(pymat) == -1) {
return -1;
+ }
if (RNA_property_type(prop) != PROP_FLOAT) {
PyErr_Format(PyExc_ValueError, "%s %.200s.%.200s, matrix assign to non float array",
@@ -512,8 +514,9 @@ static int py_to_array_index(
lvalue_dim++;
- for (i = lvalue_dim; i < totdim; i++)
+ for (i = lvalue_dim; i < totdim; i++) {
index *= dimsize[i];
+ }
index += arrayoffset;
@@ -751,8 +754,9 @@ static PyObject *pyrna_py_from_array_internal(PointerRNA *ptr, PropertyRNA *prop
for (i = 0; i < len; i++) {
PyObject *item;
- if (dim + 1 < totdim)
+ if (dim + 1 < totdim) {
item = pyrna_py_from_array_internal(ptr, prop, dim + 1, index);
+ }
else {
item = pyrna_array_index(ptr, prop, *index);
*index = *index + 1;
@@ -802,8 +806,9 @@ PyObject *pyrna_py_from_array_index(BPy_PropertyArrayRNA *self, PointerRNA *ptr,
* x = arr[2][3]
* index = offset + 3 * 5 */
- for (i = arraydim + 1; i < totdim; i++)
+ for (i = arraydim + 1; i < totdim; i++) {
index *= dimsize[i];
+ }
ret->arrayoffset = arrayoffset + index;
}
@@ -822,7 +827,9 @@ PyObject *pyrna_py_from_array(PointerRNA *ptr, PropertyRNA *prop)
ret = pyrna_math_object_from_array(ptr, prop);
/* is this a maths object? */
- if (ret) return ret;
+ if (ret) {
+ return ret;
+ }
return pyrna_prop_CreatePyObject(ptr, prop);
}
@@ -834,8 +841,10 @@ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value)
int type;
int i;
- if (len == 0) /* possible with dynamic arrays */
+ if (len == 0) {
+ /* possible with dynamic arrays */
return 0;
+ }
if (RNA_property_array_dimension(ptr, prop, NULL) > 1) {
PyErr_SetString(PyExc_TypeError, "PropertyRNA - multi dimensional arrays not supported yet");
@@ -871,8 +880,9 @@ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value)
}
}
- if (tmp_arr != tmp)
+ if (tmp_arr != tmp) {
PyMem_FREE(tmp_arr);
+ }
return i < len ? 1 : 0;
}
@@ -904,8 +914,9 @@ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value)
}
}
- if (tmp_arr != tmp)
+ if (tmp_arr != tmp) {
PyMem_FREE(tmp_arr);
+ }
return i < len ? 1 : 0;
}
@@ -937,8 +948,9 @@ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value)
}
}
- if (tmp_arr != tmp)
+ if (tmp_arr != tmp) {
PyMem_FREE(tmp_arr);
+ }
return i < len ? 1 : 0;
}
diff --git a/source/blender/python/intern/bpy_rna_callback.c b/source/blender/python/intern/bpy_rna_callback.c
index 025ea586fee..30ea657200c 100644
--- a/source/blender/python/intern/bpy_rna_callback.c
+++ b/source/blender/python/intern/bpy_rna_callback.c
@@ -136,8 +136,9 @@ PyObject *pyrna_callback_add(BPy_StructRNA *self, PyObject *args)
char *cb_event_str = NULL;
int cb_event;
- if (!PyArg_ParseTuple(args, "OO!|s:bpy_struct.callback_add", &cb_func, &PyTuple_Type, &cb_args, &cb_event_str))
+ if (!PyArg_ParseTuple(args, "OO!|s:bpy_struct.callback_add", &cb_func, &PyTuple_Type, &cb_args, &cb_event_str)) {
return NULL;
+ }
if (!PyCallable_Check(cb_func)) {
PyErr_SetString(PyExc_TypeError, "callback_add(): first argument isn't callable");
@@ -174,8 +175,9 @@ PyObject *pyrna_callback_remove(BPy_StructRNA *self, PyObject *args)
void *handle;
void *customdata;
- if (!PyArg_ParseTuple(args, "O!:callback_remove", &PyCapsule_Type, &py_handle))
+ if (!PyArg_ParseTuple(args, "O!:callback_remove", &PyCapsule_Type, &py_handle)) {
return NULL;
+ }
handle = PyCapsule_GetPointer(py_handle, rna_capsual_id);
@@ -205,21 +207,21 @@ PyObject *pyrna_callback_remove(BPy_StructRNA *self, PyObject *args)
/* reverse of rna_Space_refine() */
static eSpace_Type rna_Space_refine_reverse(StructRNA *srna)
{
- if (srna == &RNA_SpaceView3D) return SPACE_VIEW3D;
- if (srna == &RNA_SpaceGraphEditor) return SPACE_GRAPH;
- if (srna == &RNA_SpaceOutliner) return SPACE_OUTLINER;
- if (srna == &RNA_SpaceProperties) return SPACE_PROPERTIES;
- if (srna == &RNA_SpaceFileBrowser) return SPACE_FILE;
- if (srna == &RNA_SpaceImageEditor) return SPACE_IMAGE;
- if (srna == &RNA_SpaceInfo) return SPACE_INFO;
- if (srna == &RNA_SpaceSequenceEditor) return SPACE_SEQ;
- if (srna == &RNA_SpaceTextEditor) return SPACE_TEXT;
- if (srna == &RNA_SpaceDopeSheetEditor) return SPACE_ACTION;
- if (srna == &RNA_SpaceNLA) return SPACE_NLA;
- if (srna == &RNA_SpaceNodeEditor) return SPACE_NODE;
- if (srna == &RNA_SpaceConsole) return SPACE_CONSOLE;
- if (srna == &RNA_SpacePreferences) return SPACE_USERPREF;
- if (srna == &RNA_SpaceClipEditor) return SPACE_CLIP;
+ if (srna == &RNA_SpaceView3D) { return SPACE_VIEW3D; }
+ if (srna == &RNA_SpaceGraphEditor) { return SPACE_GRAPH; }
+ if (srna == &RNA_SpaceOutliner) { return SPACE_OUTLINER; }
+ if (srna == &RNA_SpaceProperties) { return SPACE_PROPERTIES; }
+ if (srna == &RNA_SpaceFileBrowser) { return SPACE_FILE; }
+ if (srna == &RNA_SpaceImageEditor) { return SPACE_IMAGE; }
+ if (srna == &RNA_SpaceInfo) { return SPACE_INFO; }
+ if (srna == &RNA_SpaceSequenceEditor) { return SPACE_SEQ; }
+ if (srna == &RNA_SpaceTextEditor) { return SPACE_TEXT; }
+ if (srna == &RNA_SpaceDopeSheetEditor) { return SPACE_ACTION; }
+ if (srna == &RNA_SpaceNLA) { return SPACE_NLA; }
+ if (srna == &RNA_SpaceNodeEditor) { return SPACE_NODE; }
+ if (srna == &RNA_SpaceConsole) { return SPACE_CONSOLE; }
+ if (srna == &RNA_SpacePreferences) { return SPACE_USERPREF; }
+ if (srna == &RNA_SpaceClipEditor) { return SPACE_CLIP; }
return SPACE_EMPTY;
}
diff --git a/source/blender/python/intern/bpy_traceback.c b/source/blender/python/intern/bpy_traceback.c
index dd4d96cb806..77cd8d8a9b7 100644
--- a/source/blender/python/intern/bpy_traceback.c
+++ b/source/blender/python/intern/bpy_traceback.c
@@ -58,17 +58,20 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename,
/* new style errors. `err' is an instance */
*message = _PyObject_GetAttrId(err, &PyId_msg);
- if (!*message)
+ if (!*message) {
goto finally;
+ }
v = _PyObject_GetAttrId(err, &PyId_filename);
- if (!v)
+ if (!v) {
goto finally;
+ }
if (v == Py_None) {
Py_DECREF(v);
*filename = _PyUnicode_FromId(&PyId_string);
- if (*filename == NULL)
+ if (*filename == NULL) {
goto finally;
+ }
Py_INCREF(*filename);
}
else {
@@ -76,31 +79,36 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename,
}
v = _PyObject_GetAttrId(err, &PyId_lineno);
- if (!v)
+ if (!v) {
goto finally;
+ }
hold = PyLong_AsLong(v);
Py_DECREF(v);
- if (hold < 0 && PyErr_Occurred())
+ if (hold < 0 && PyErr_Occurred()) {
goto finally;
+ }
*lineno = (int)hold;
v = _PyObject_GetAttrId(err, &PyId_offset);
- if (!v)
+ if (!v) {
goto finally;
+ }
if (v == Py_None) {
*offset = -1;
Py_DECREF(v);
} else {
hold = PyLong_AsLong(v);
Py_DECREF(v);
- if (hold < 0 && PyErr_Occurred())
+ if (hold < 0 && PyErr_Occurred()) {
goto finally;
+ }
*offset = (int)hold;
}
v = _PyObject_GetAttrId(err, &PyId_text);
- if (!v)
+ if (!v) {
goto finally;
+ }
if (v == Py_None) {
Py_DECREF(v);
*text = NULL;
diff --git a/source/blender/python/mathutils/mathutils.c b/source/blender/python/mathutils/mathutils.c
index f577ef3b441..41738ced41a 100644
--- a/source/blender/python/mathutils/mathutils.c
+++ b/source/blender/python/mathutils/mathutils.c
@@ -105,15 +105,17 @@ Py_hash_t mathutils_array_hash(const float *array, size_t array_len)
i = 0;
while (--len >= 0) {
y = _Py_HashDouble((double)(array[i++]));
- if (y == -1)
+ if (y == -1) {
return -1;
+ }
x = (x ^ y) * mult;
/* the cast might truncate len; that doesn't change hash stability */
mult += (Py_hash_t)(82520UL + len + len);
}
x += 97531UL;
- if (x == (Py_uhash_t)-1)
+ if (x == (Py_uhash_t)-1) {
x = -2;
+ }
return x;
}
@@ -392,8 +394,9 @@ int EXPP_VectorsAreEqual(const float *vecA, const float *vecB, int size, int flo
{
int x;
for (x = 0; x < size; x++) {
- if (EXPP_FloatsAreEqual(vecA[x], vecB[x], floatSteps) == 0)
+ if (EXPP_FloatsAreEqual(vecA[x], vecB[x], floatSteps) == 0) {
return 0;
+ }
}
return 1;
}
@@ -425,8 +428,10 @@ unsigned char Mathutils_RegisterCallback(Mathutils_Callback *cb)
/* find the first free slot */
for (i = 0; mathutils_callbacks[i]; i++) {
- if (mathutils_callbacks[i] == cb) /* already registered? */
+ if (mathutils_callbacks[i] == cb) {
+ /* already registered? */
return i;
+ }
}
BLI_assert(i + 1 < MATHUTILS_TOT_CB);
@@ -611,18 +616,24 @@ PyMODINIT_FUNC PyInit_mathutils(void)
PyObject *submodule;
PyObject *sys_modules = PyImport_GetModuleDict();
- if (PyType_Ready(&vector_Type) < 0)
+ if (PyType_Ready(&vector_Type) < 0) {
return NULL;
- if (PyType_Ready(&matrix_Type) < 0)
+ }
+ if (PyType_Ready(&matrix_Type) < 0) {
return NULL;
- if (PyType_Ready(&matrix_access_Type) < 0)
+ }
+ if (PyType_Ready(&matrix_access_Type) < 0) {
return NULL;
- if (PyType_Ready(&euler_Type) < 0)
+ }
+ if (PyType_Ready(&euler_Type) < 0) {
return NULL;
- if (PyType_Ready(&quaternion_Type) < 0)
+ }
+ if (PyType_Ready(&quaternion_Type) < 0) {
return NULL;
- if (PyType_Ready(&color_Type) < 0)
+ }
+ if (PyType_Ready(&color_Type) < 0) {
return NULL;
+ }
mod = PyModule_Create(&M_Mathutils_module_def);
diff --git a/source/blender/python/mathutils/mathutils_Color.c b/source/blender/python/mathutils/mathutils_Color.c
index b05b8c81cf9..c97d2720720 100644
--- a/source/blender/python/mathutils/mathutils_Color.c
+++ b/source/blender/python/mathutils/mathutils_Color.c
@@ -52,8 +52,9 @@ static PyObject *Color_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
case 0:
break;
case 1:
- if ((mathutils_array_parse(col, COLOR_SIZE, COLOR_SIZE, PyTuple_GET_ITEM(args, 0), "mathutils.Color()")) == -1)
+ if ((mathutils_array_parse(col, COLOR_SIZE, COLOR_SIZE, PyTuple_GET_ITEM(args, 0), "mathutils.Color()")) == -1) {
return NULL;
+ }
break;
default:
PyErr_SetString(PyExc_TypeError,
@@ -101,8 +102,9 @@ PyDoc_STRVAR(Color_copy_doc,
);
static PyObject *Color_copy(ColorObject *self)
{
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
return Color_CreatePyObject(self->col, Py_TYPE(self));
}
@@ -121,8 +123,9 @@ static PyObject *Color_repr(ColorObject *self)
{
PyObject *ret, *tuple;
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
tuple = Color_ToTupleExt(self, -1);
@@ -137,8 +140,9 @@ static PyObject *Color_str(ColorObject *self)
{
DynStr *ds;
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
ds = BLI_dynstr_new();
@@ -160,8 +164,9 @@ static PyObject *Color_richcmpr(PyObject *a, PyObject *b, int op)
ColorObject *colA = (ColorObject *)a;
ColorObject *colB = (ColorObject *)b;
- if (BaseMath_ReadCallback(colA) == -1 || BaseMath_ReadCallback(colB) == -1)
+ if (BaseMath_ReadCallback(colA) == -1 || BaseMath_ReadCallback(colB) == -1) {
return NULL;
+ }
ok = EXPP_VectorsAreEqual(colA->col, colB->col, COLOR_SIZE, 1) ? 0 : -1;
}
@@ -190,11 +195,13 @@ static PyObject *Color_richcmpr(PyObject *a, PyObject *b, int op)
static Py_hash_t Color_hash(ColorObject *self)
{
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return -1;
+ }
- if (BaseMathObject_Prepare_ForHash(self) == -1)
+ if (BaseMathObject_Prepare_ForHash(self) == -1) {
return -1;
+ }
return mathutils_array_hash(self->col, COLOR_SIZE);
}
@@ -210,7 +217,9 @@ static int Color_len(ColorObject *UNUSED(self))
/* sequence accessor (get) */
static PyObject *Color_item(ColorObject *self, int i)
{
- if (i < 0) i = COLOR_SIZE - i;
+ if (i < 0) {
+ i = COLOR_SIZE - i;
+ }
if (i < 0 || i >= COLOR_SIZE) {
PyErr_SetString(PyExc_IndexError,
@@ -219,8 +228,9 @@ static PyObject *Color_item(ColorObject *self, int i)
return NULL;
}
- if (BaseMath_ReadIndexCallback(self, i) == -1)
+ if (BaseMath_ReadIndexCallback(self, i) == -1) {
return NULL;
+ }
return PyFloat_FromDouble(self->col[i]);
@@ -231,8 +241,9 @@ static int Color_ass_item(ColorObject *self, int i, PyObject *value)
{
float f;
- if (BaseMath_Prepare_ForWrite(self) == -1)
+ if (BaseMath_Prepare_ForWrite(self) == -1) {
return -1;
+ }
f = PyFloat_AsDouble(value);
if (f == -1 && PyErr_Occurred()) { /* parsed item not a number */
@@ -242,7 +253,9 @@ static int Color_ass_item(ColorObject *self, int i, PyObject *value)
return -1;
}
- if (i < 0) i = COLOR_SIZE - i;
+ if (i < 0) {
+ i = COLOR_SIZE - i;
+ }
if (i < 0 || i >= COLOR_SIZE) {
PyErr_SetString(PyExc_IndexError, "color[item] = x: "
@@ -252,8 +265,9 @@ static int Color_ass_item(ColorObject *self, int i, PyObject *value)
self->col[i] = f;
- if (BaseMath_WriteIndexCallback(self, i) == -1)
+ if (BaseMath_WriteIndexCallback(self, i) == -1) {
return -1;
+ }
return 0;
}
@@ -264,11 +278,14 @@ static PyObject *Color_slice(ColorObject *self, int begin, int end)
PyObject *tuple;
int count;
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
CLAMP(begin, 0, COLOR_SIZE);
- if (end < 0) end = (COLOR_SIZE + 1) + end;
+ if (end < 0) {
+ end = (COLOR_SIZE + 1) + end;
+ }
CLAMP(end, 0, COLOR_SIZE);
begin = MIN2(begin, end);
@@ -286,16 +303,20 @@ static int Color_ass_slice(ColorObject *self, int begin, int end, PyObject *seq)
int i, size;
float col[COLOR_SIZE];
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return -1;
+ }
CLAMP(begin, 0, COLOR_SIZE);
- if (end < 0) end = (COLOR_SIZE + 1) + end;
+ if (end < 0) {
+ end = (COLOR_SIZE + 1) + end;
+ }
CLAMP(end, 0, COLOR_SIZE);
begin = MIN2(begin, end);
- if ((size = mathutils_array_parse(col, 0, COLOR_SIZE, seq, "mathutils.Color[begin:end] = []")) == -1)
+ if ((size = mathutils_array_parse(col, 0, COLOR_SIZE, seq, "mathutils.Color[begin:end] = []")) == -1) {
return -1;
+ }
if (size != (end - begin)) {
PyErr_SetString(PyExc_ValueError,
@@ -304,8 +325,9 @@ static int Color_ass_slice(ColorObject *self, int begin, int end, PyObject *seq)
return -1;
}
- for (i = 0; i < COLOR_SIZE; i++)
+ for (i = 0; i < COLOR_SIZE; i++) {
self->col[begin + i] = col[i];
+ }
(void)BaseMath_WriteCallback(self);
return 0;
@@ -316,17 +338,20 @@ static PyObject *Color_subscript(ColorObject *self, PyObject *item)
if (PyIndex_Check(item)) {
Py_ssize_t i;
i = PyNumber_AsSsize_t(item, PyExc_IndexError);
- if (i == -1 && PyErr_Occurred())
+ if (i == -1 && PyErr_Occurred()) {
return NULL;
- if (i < 0)
+ }
+ if (i < 0) {
i += COLOR_SIZE;
+ }
return Color_item(self, i);
}
else if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelength;
- if (PySlice_GetIndicesEx(item, COLOR_SIZE, &start, &stop, &step, &slicelength) < 0)
+ if (PySlice_GetIndicesEx(item, COLOR_SIZE, &start, &stop, &step, &slicelength) < 0) {
return NULL;
+ }
if (slicelength <= 0) {
return PyTuple_New(0);
@@ -352,20 +377,24 @@ static int Color_ass_subscript(ColorObject *self, PyObject *item, PyObject *valu
{
if (PyIndex_Check(item)) {
Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
- if (i == -1 && PyErr_Occurred())
+ if (i == -1 && PyErr_Occurred()) {
return -1;
- if (i < 0)
+ }
+ if (i < 0) {
i += COLOR_SIZE;
+ }
return Color_ass_item(self, i, value);
}
else if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelength;
- if (PySlice_GetIndicesEx(item, COLOR_SIZE, &start, &stop, &step, &slicelength) < 0)
+ if (PySlice_GetIndicesEx(item, COLOR_SIZE, &start, &stop, &step, &slicelength) < 0) {
return -1;
+ }
- if (step == 1)
+ if (step == 1) {
return Color_ass_slice(self, start, stop, value);
+ }
else {
PyErr_SetString(PyExc_IndexError,
"slice steps not supported with color");
@@ -419,8 +448,9 @@ static PyObject *Color_add(PyObject *v1, PyObject *v2)
color1 = (ColorObject *)v1;
color2 = (ColorObject *)v2;
- if (BaseMath_ReadCallback(color1) == -1 || BaseMath_ReadCallback(color2) == -1)
+ if (BaseMath_ReadCallback(color1) == -1 || BaseMath_ReadCallback(color2) == -1) {
return NULL;
+ }
add_vn_vnvn(col, color1->col, color2->col, COLOR_SIZE);
@@ -442,8 +472,9 @@ static PyObject *Color_iadd(PyObject *v1, PyObject *v2)
color1 = (ColorObject *)v1;
color2 = (ColorObject *)v2;
- if (BaseMath_ReadCallback_ForWrite(color1) == -1 || BaseMath_ReadCallback(color2) == -1)
+ if (BaseMath_ReadCallback_ForWrite(color1) == -1 || BaseMath_ReadCallback(color2) == -1) {
return NULL;
+ }
add_vn_vn(color1->col, color2->col, COLOR_SIZE);
@@ -468,8 +499,9 @@ static PyObject *Color_sub(PyObject *v1, PyObject *v2)
color1 = (ColorObject *)v1;
color2 = (ColorObject *)v2;
- if (BaseMath_ReadCallback(color1) == -1 || BaseMath_ReadCallback(color2) == -1)
+ if (BaseMath_ReadCallback(color1) == -1 || BaseMath_ReadCallback(color2) == -1) {
return NULL;
+ }
sub_vn_vnvn(col, color1->col, color2->col, COLOR_SIZE);
@@ -491,8 +523,9 @@ static PyObject *Color_isub(PyObject *v1, PyObject *v2)
color1 = (ColorObject *)v1;
color2 = (ColorObject *)v2;
- if (BaseMath_ReadCallback_ForWrite(color1) == -1 || BaseMath_ReadCallback(color2) == -1)
+ if (BaseMath_ReadCallback_ForWrite(color1) == -1 || BaseMath_ReadCallback(color2) == -1) {
return NULL;
+ }
sub_vn_vn(color1->col, color2->col, COLOR_SIZE);
@@ -516,13 +549,15 @@ static PyObject *Color_mul(PyObject *v1, PyObject *v2)
if (ColorObject_Check(v1)) {
color1 = (ColorObject *)v1;
- if (BaseMath_ReadCallback(color1) == -1)
+ if (BaseMath_ReadCallback(color1) == -1) {
return NULL;
+ }
}
if (ColorObject_Check(v2)) {
color2 = (ColorObject *)v2;
- if (BaseMath_ReadCallback(color2) == -1)
+ if (BaseMath_ReadCallback(color2) == -1) {
return NULL;
+ }
}
@@ -558,8 +593,9 @@ static PyObject *Color_div(PyObject *v1, PyObject *v2)
if (ColorObject_Check(v1)) {
color1 = (ColorObject *)v1;
- if (BaseMath_ReadCallback(color1) == -1)
+ if (BaseMath_ReadCallback(color1) == -1) {
return NULL;
+ }
}
else {
PyErr_SetString(PyExc_TypeError,
@@ -590,8 +626,9 @@ static PyObject *Color_imul(PyObject *v1, PyObject *v2)
ColorObject *color = (ColorObject *)v1;
float scalar;
- if (BaseMath_ReadCallback_ForWrite(color) == -1)
+ if (BaseMath_ReadCallback_ForWrite(color) == -1) {
return NULL;
+ }
/* only support color *= float */
if (((scalar = PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred()) == 0) { /* COLOR *= FLOAT */
@@ -616,8 +653,9 @@ static PyObject *Color_idiv(PyObject *v1, PyObject *v2)
ColorObject *color = (ColorObject *)v1;
float scalar;
- if (BaseMath_ReadCallback_ForWrite(color) == -1)
+ if (BaseMath_ReadCallback_ForWrite(color) == -1) {
return NULL;
+ }
/* only support color /= float */
if (((scalar = PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred()) == 0) { /* COLOR /= FLOAT */
@@ -648,8 +686,9 @@ static PyObject *Color_neg(ColorObject *self)
{
float tcol[COLOR_SIZE];
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
negate_vn_vn(tcol, self->col, COLOR_SIZE);
return Color_CreatePyObject(tcol, Py_TYPE(self));
@@ -718,8 +757,9 @@ static PyObject *Color_channel_hsv_get(ColorObject *self, void *type)
float hsv[3];
int i = POINTER_AS_INT(type);
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
rgb_to_hsv(self->col[0], self->col[1], self->col[2], &(hsv[0]), &(hsv[1]), &(hsv[2]));
@@ -739,16 +779,18 @@ static int Color_channel_hsv_set(ColorObject *self, PyObject *value, void *type)
return -1;
}
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return -1;
+ }
rgb_to_hsv_v(self->col, hsv);
CLAMP(f, 0.0f, 1.0f);
hsv[i] = f;
hsv_to_rgb_v(hsv, self->col);
- if (BaseMath_WriteCallback(self) == -1)
+ if (BaseMath_WriteCallback(self) == -1) {
return -1;
+ }
return 0;
}
@@ -760,8 +802,9 @@ static PyObject *Color_hsv_get(ColorObject *self, void *UNUSED(closure))
float hsv[3];
PyObject *ret;
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
rgb_to_hsv(self->col[0], self->col[1], self->col[2], &(hsv[0]), &(hsv[1]), &(hsv[2]));
@@ -777,11 +820,13 @@ static int Color_hsv_set(ColorObject *self, PyObject *value, void *UNUSED(closur
{
float hsv[3];
- if (mathutils_array_parse(hsv, 3, 3, value, "mathutils.Color.hsv = value") == -1)
+ if (mathutils_array_parse(hsv, 3, 3, value, "mathutils.Color.hsv = value") == -1) {
return -1;
+ }
- if (BaseMath_Prepare_ForWrite(self) == -1)
+ if (BaseMath_Prepare_ForWrite(self) == -1) {
return -1;
+ }
CLAMP(hsv[0], 0.0f, 1.0f);
CLAMP(hsv[1], 0.0f, 1.0f);
@@ -789,8 +834,9 @@ static int Color_hsv_set(ColorObject *self, PyObject *value, void *UNUSED(closur
hsv_to_rgb_v(hsv, self->col);
- if (BaseMath_WriteCallback(self) == -1)
+ if (BaseMath_WriteCallback(self) == -1) {
return -1;
+ }
return 0;
}
@@ -913,10 +959,12 @@ PyObject *Color_CreatePyObject(
self->cb_type = self->cb_subtype = 0;
/* NEW */
- if (col)
+ if (col) {
copy_v3_v3(self->col, col);
- else
+ }
+ else {
zero_v3(self->col);
+ }
self->flag = BASE_MATH_FLAG_DEFAULT;
}
diff --git a/source/blender/python/mathutils/mathutils_Euler.c b/source/blender/python/mathutils/mathutils_Euler.c
index a3336309574..e928049644b 100644
--- a/source/blender/python/mathutils/mathutils_Euler.c
+++ b/source/blender/python/mathutils/mathutils_Euler.c
@@ -51,19 +51,22 @@ static PyObject *Euler_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return NULL;
}
- if (!PyArg_ParseTuple(args, "|Os:mathutils.Euler", &seq, &order_str))
+ if (!PyArg_ParseTuple(args, "|Os:mathutils.Euler", &seq, &order_str)) {
return NULL;
+ }
switch (PyTuple_GET_SIZE(args)) {
case 0:
break;
case 2:
- if ((order = euler_order_from_string(order_str, "mathutils.Euler()")) == -1)
+ if ((order = euler_order_from_string(order_str, "mathutils.Euler()")) == -1) {
return NULL;
+ }
ATTR_FALLTHROUGH;
case 1:
- if (mathutils_array_parse(eul, EULER_SIZE, EULER_SIZE, seq, "mathutils.Euler()") == -1)
+ if (mathutils_array_parse(eul, EULER_SIZE, EULER_SIZE, seq, "mathutils.Euler()") == -1) {
return NULL;
+ }
break;
}
return Euler_CreatePyObject(eul, order, type);
@@ -141,8 +144,9 @@ static PyObject *Euler_to_quaternion(EulerObject *self)
{
float quat[4];
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
eulO_to_quat(quat, self->eul, self->order);
@@ -162,8 +166,9 @@ static PyObject *Euler_to_matrix(EulerObject *self)
{
float mat[9];
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
eulO_to_mat3((float (*)[3])mat, self->eul, self->order);
@@ -177,13 +182,15 @@ PyDoc_STRVAR(Euler_zero_doc,
);
static PyObject *Euler_zero(EulerObject *self)
{
- if (BaseMath_Prepare_ForWrite(self) == -1)
+ if (BaseMath_Prepare_ForWrite(self) == -1) {
return NULL;
+ }
zero_v3(self->eul);
- if (BaseMath_WriteCallback(self) == -1)
+ if (BaseMath_WriteCallback(self) == -1) {
return NULL;
+ }
Py_RETURN_NONE;
}
@@ -218,8 +225,9 @@ static PyObject *Euler_rotate_axis(EulerObject *self, PyObject *args)
return NULL;
}
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return NULL;
+ }
rotate_eulO(self->eul, self->order, (char)axis, angle);
@@ -241,11 +249,13 @@ static PyObject *Euler_rotate(EulerObject *self, PyObject *value)
{
float self_rmat[3][3], other_rmat[3][3], rmat[3][3];
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return NULL;
+ }
- if (mathutils_any_to_rotmat(other_rmat, value, "euler.rotate(value)") == -1)
+ if (mathutils_any_to_rotmat(other_rmat, value, "euler.rotate(value)") == -1) {
return NULL;
+ }
eulO_to_mat3(self_rmat, self->eul, self->order);
mul_m3_m3m3(rmat, other_rmat, self_rmat);
@@ -268,8 +278,9 @@ static PyObject *Euler_make_compatible(EulerObject *self, PyObject *value)
{
float teul[EULER_SIZE];
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return NULL;
+ }
if (mathutils_array_parse(teul, EULER_SIZE, EULER_SIZE, value,
"euler.make_compatible(other), invalid 'other' arg") == -1)
@@ -300,8 +311,9 @@ PyDoc_STRVAR(Euler_copy_doc,
);
static PyObject *Euler_copy(EulerObject *self)
{
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
return Euler_CreatePyObject(self->eul, self->order, Py_TYPE(self));
}
@@ -320,8 +332,9 @@ static PyObject *Euler_repr(EulerObject *self)
{
PyObject *ret, *tuple;
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
tuple = Euler_ToTupleExt(self, -1);
@@ -336,8 +349,9 @@ static PyObject *Euler_str(EulerObject *self)
{
DynStr *ds;
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
ds = BLI_dynstr_new();
@@ -357,8 +371,9 @@ static PyObject *Euler_richcmpr(PyObject *a, PyObject *b, int op)
EulerObject *eulA = (EulerObject *)a;
EulerObject *eulB = (EulerObject *)b;
- if (BaseMath_ReadCallback(eulA) == -1 || BaseMath_ReadCallback(eulB) == -1)
+ if (BaseMath_ReadCallback(eulA) == -1 || BaseMath_ReadCallback(eulB) == -1) {
return NULL;
+ }
ok = ((eulA->order == eulB->order) && EXPP_VectorsAreEqual(eulA->eul, eulB->eul, EULER_SIZE, 1)) ? 0 : -1;
}
@@ -387,11 +402,13 @@ static PyObject *Euler_richcmpr(PyObject *a, PyObject *b, int op)
static Py_hash_t Euler_hash(EulerObject *self)
{
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return -1;
+ }
- if (BaseMathObject_Prepare_ForHash(self) == -1)
+ if (BaseMathObject_Prepare_ForHash(self) == -1) {
return -1;
+ }
return mathutils_array_hash(self->eul, EULER_SIZE);
}
@@ -407,7 +424,9 @@ static int Euler_len(EulerObject *UNUSED(self))
/* sequence accessor (get) */
static PyObject *Euler_item(EulerObject *self, int i)
{
- if (i < 0) i = EULER_SIZE - i;
+ if (i < 0) {
+ i = EULER_SIZE - i;
+ }
if (i < 0 || i >= EULER_SIZE) {
PyErr_SetString(PyExc_IndexError,
@@ -416,8 +435,9 @@ static PyObject *Euler_item(EulerObject *self, int i)
return NULL;
}
- if (BaseMath_ReadIndexCallback(self, i) == -1)
+ if (BaseMath_ReadIndexCallback(self, i) == -1) {
return NULL;
+ }
return PyFloat_FromDouble(self->eul[i]);
@@ -428,8 +448,9 @@ static int Euler_ass_item(EulerObject *self, int i, PyObject *value)
{
float f;
- if (BaseMath_Prepare_ForWrite(self) == -1)
+ if (BaseMath_Prepare_ForWrite(self) == -1) {
return -1;
+ }
f = PyFloat_AsDouble(value);
if (f == -1 && PyErr_Occurred()) { /* parsed item not a number */
@@ -439,7 +460,9 @@ static int Euler_ass_item(EulerObject *self, int i, PyObject *value)
return -1;
}
- if (i < 0) i = EULER_SIZE - i;
+ if (i < 0) {
+ i = EULER_SIZE - i;
+ }
if (i < 0 || i >= EULER_SIZE) {
PyErr_SetString(PyExc_IndexError,
@@ -450,8 +473,9 @@ static int Euler_ass_item(EulerObject *self, int i, PyObject *value)
self->eul[i] = f;
- if (BaseMath_WriteIndexCallback(self, i) == -1)
+ if (BaseMath_WriteIndexCallback(self, i) == -1) {
return -1;
+ }
return 0;
}
@@ -462,11 +486,14 @@ static PyObject *Euler_slice(EulerObject *self, int begin, int end)
PyObject *tuple;
int count;
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
CLAMP(begin, 0, EULER_SIZE);
- if (end < 0) end = (EULER_SIZE + 1) + end;
+ if (end < 0) {
+ end = (EULER_SIZE + 1) + end;
+ }
CLAMP(end, 0, EULER_SIZE);
begin = MIN2(begin, end);
@@ -484,16 +511,20 @@ static int Euler_ass_slice(EulerObject *self, int begin, int end, PyObject *seq)
int i, size;
float eul[EULER_SIZE];
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return -1;
+ }
CLAMP(begin, 0, EULER_SIZE);
- if (end < 0) end = (EULER_SIZE + 1) + end;
+ if (end < 0) {
+ end = (EULER_SIZE + 1) + end;
+ }
CLAMP(end, 0, EULER_SIZE);
begin = MIN2(begin, end);
- if ((size = mathutils_array_parse(eul, 0, EULER_SIZE, seq, "mathutils.Euler[begin:end] = []")) == -1)
+ if ((size = mathutils_array_parse(eul, 0, EULER_SIZE, seq, "mathutils.Euler[begin:end] = []")) == -1) {
return -1;
+ }
if (size != (end - begin)) {
PyErr_SetString(PyExc_ValueError,
@@ -502,8 +533,9 @@ static int Euler_ass_slice(EulerObject *self, int begin, int end, PyObject *seq)
return -1;
}
- for (i = 0; i < EULER_SIZE; i++)
+ for (i = 0; i < EULER_SIZE; i++) {
self->eul[begin + i] = eul[i];
+ }
(void)BaseMath_WriteCallback(self);
return 0;
@@ -514,17 +546,20 @@ static PyObject *Euler_subscript(EulerObject *self, PyObject *item)
if (PyIndex_Check(item)) {
Py_ssize_t i;
i = PyNumber_AsSsize_t(item, PyExc_IndexError);
- if (i == -1 && PyErr_Occurred())
+ if (i == -1 && PyErr_Occurred()) {
return NULL;
- if (i < 0)
+ }
+ if (i < 0) {
i += EULER_SIZE;
+ }
return Euler_item(self, i);
}
else if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelength;
- if (PySlice_GetIndicesEx(item, EULER_SIZE, &start, &stop, &step, &slicelength) < 0)
+ if (PySlice_GetIndicesEx(item, EULER_SIZE, &start, &stop, &step, &slicelength) < 0) {
return NULL;
+ }
if (slicelength <= 0) {
return PyTuple_New(0);
@@ -551,20 +586,24 @@ static int Euler_ass_subscript(EulerObject *self, PyObject *item, PyObject *valu
{
if (PyIndex_Check(item)) {
Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
- if (i == -1 && PyErr_Occurred())
+ if (i == -1 && PyErr_Occurred()) {
return -1;
- if (i < 0)
+ }
+ if (i < 0) {
i += EULER_SIZE;
+ }
return Euler_ass_item(self, i, value);
}
else if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelength;
- if (PySlice_GetIndicesEx(item, EULER_SIZE, &start, &stop, &step, &slicelength) < 0)
+ if (PySlice_GetIndicesEx(item, EULER_SIZE, &start, &stop, &step, &slicelength) < 0) {
return -1;
+ }
- if (step == 1)
+ if (step == 1) {
return Euler_ass_slice(self, start, stop, value);
+ }
else {
PyErr_SetString(PyExc_IndexError,
"slice steps not supported with euler");
@@ -621,8 +660,10 @@ PyDoc_STRVAR(Euler_order_doc,
);
static PyObject *Euler_order_get(EulerObject *self, void *UNUSED(closure))
{
- if (BaseMath_ReadCallback(self) == -1) /* can read order too */
+ if (BaseMath_ReadCallback(self) == -1) {
+ /* can read order too */
return NULL;
+ }
return PyUnicode_FromString(euler_order_str(self));
}
@@ -632,8 +673,9 @@ static int Euler_order_set(EulerObject *self, PyObject *value, void *UNUSED(clos
const char *order_str;
short order;
- if (BaseMath_Prepare_ForWrite(self) == -1)
+ if (BaseMath_Prepare_ForWrite(self) == -1) {
return -1;
+ }
if (((order_str = _PyUnicode_AsString(value)) == NULL) ||
((order = euler_order_from_string(order_str, "euler.order")) == -1))
diff --git a/source/blender/python/mathutils/mathutils_Matrix.c b/source/blender/python/mathutils/mathutils_Matrix.c
index 1f2d955c449..6477493d4a6 100644
--- a/source/blender/python/mathutils/mathutils_Matrix.c
+++ b/source/blender/python/mathutils/mathutils_Matrix.c
@@ -89,10 +89,12 @@ static int mathutils_matrix_row_get(BaseMathObject *bmo, int row)
MatrixObject *self = (MatrixObject *)bmo->cb_user;
int col;
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return -1;
- if (!matrix_row_vector_check(self, (VectorObject *)bmo, row))
+ }
+ if (!matrix_row_vector_check(self, (VectorObject *)bmo, row)) {
return -1;
+ }
for (col = 0; col < self->num_col; col++) {
bmo->data[col] = MATRIX_ITEM(self, row, col);
@@ -106,10 +108,12 @@ static int mathutils_matrix_row_set(BaseMathObject *bmo, int row)
MatrixObject *self = (MatrixObject *)bmo->cb_user;
int col;
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return -1;
- if (!matrix_row_vector_check(self, (VectorObject *)bmo, row))
+ }
+ if (!matrix_row_vector_check(self, (VectorObject *)bmo, row)) {
return -1;
+ }
for (col = 0; col < self->num_col; col++) {
MATRIX_ITEM(self, row, col) = bmo->data[col];
@@ -123,10 +127,12 @@ static int mathutils_matrix_row_get_index(BaseMathObject *bmo, int row, int col)
{
MatrixObject *self = (MatrixObject *)bmo->cb_user;
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return -1;
- if (!matrix_row_vector_check(self, (VectorObject *)bmo, row))
+ }
+ if (!matrix_row_vector_check(self, (VectorObject *)bmo, row)) {
return -1;
+ }
bmo->data[col] = MATRIX_ITEM(self, row, col);
return 0;
@@ -136,10 +142,12 @@ static int mathutils_matrix_row_set_index(BaseMathObject *bmo, int row, int col)
{
MatrixObject *self = (MatrixObject *)bmo->cb_user;
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return -1;
- if (!matrix_row_vector_check(self, (VectorObject *)bmo, row))
+ }
+ if (!matrix_row_vector_check(self, (VectorObject *)bmo, row)) {
return -1;
+ }
MATRIX_ITEM(self, row, col) = bmo->data[col];
@@ -174,10 +182,12 @@ static int mathutils_matrix_col_get(BaseMathObject *bmo, int col)
int num_row;
int row;
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return -1;
- if (!matrix_col_vector_check(self, (VectorObject *)bmo, col))
+ }
+ if (!matrix_col_vector_check(self, (VectorObject *)bmo, col)) {
return -1;
+ }
/* for 'translation' size will always be '3' even on 4x4 vec */
num_row = min_ii(self->num_row, ((VectorObject *)bmo)->size);
@@ -195,10 +205,12 @@ static int mathutils_matrix_col_set(BaseMathObject *bmo, int col)
int num_row;
int row;
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return -1;
- if (!matrix_col_vector_check(self, (VectorObject *)bmo, col))
+ }
+ if (!matrix_col_vector_check(self, (VectorObject *)bmo, col)) {
return -1;
+ }
/* for 'translation' size will always be '3' even on 4x4 vec */
num_row = min_ii(self->num_row, ((VectorObject *)bmo)->size);
@@ -215,10 +227,12 @@ static int mathutils_matrix_col_get_index(BaseMathObject *bmo, int col, int row)
{
MatrixObject *self = (MatrixObject *)bmo->cb_user;
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return -1;
- if (!matrix_col_vector_check(self, (VectorObject *)bmo, col))
+ }
+ if (!matrix_col_vector_check(self, (VectorObject *)bmo, col)) {
return -1;
+ }
bmo->data[row] = MATRIX_ITEM(self, row, col);
return 0;
@@ -228,10 +242,12 @@ static int mathutils_matrix_col_set_index(BaseMathObject *bmo, int col, int row)
{
MatrixObject *self = (MatrixObject *)bmo->cb_user;
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return -1;
- if (!matrix_col_vector_check(self, (VectorObject *)bmo, col))
+ }
+ if (!matrix_col_vector_check(self, (VectorObject *)bmo, col)) {
return -1;
+ }
MATRIX_ITEM(self, row, col) = bmo->data[row];
@@ -266,8 +282,9 @@ static int mathutils_matrix_translation_get(BaseMathObject *bmo, int col)
MatrixObject *self = (MatrixObject *)bmo->cb_user;
int row;
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return -1;
+ }
for (row = 0; row < 3; row++) {
bmo->data[row] = MATRIX_ITEM(self, row, col);
@@ -281,8 +298,9 @@ static int mathutils_matrix_translation_set(BaseMathObject *bmo, int col)
MatrixObject *self = (MatrixObject *)bmo->cb_user;
int row;
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return -1;
+ }
for (row = 0; row < 3; row++) {
MATRIX_ITEM(self, row, col) = bmo->data[row];
@@ -296,8 +314,9 @@ static int mathutils_matrix_translation_get_index(BaseMathObject *bmo, int col,
{
MatrixObject *self = (MatrixObject *)bmo->cb_user;
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return -1;
+ }
bmo->data[row] = MATRIX_ITEM(self, row, col);
return 0;
@@ -307,8 +326,9 @@ static int mathutils_matrix_translation_set_index(BaseMathObject *bmo, int col,
{
MatrixObject *self = (MatrixObject *)bmo->cb_user;
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return -1;
+ }
MATRIX_ITEM(self, row, col) = bmo->data[row];
@@ -516,8 +536,9 @@ static PyObject *C_Matrix_Rotation(PyObject *cls, PyObject *args)
if (vec) {
float tvec[3];
- if (mathutils_array_parse(tvec, 3, 3, vec, "Matrix.Rotation(angle, size, axis), invalid 'axis' arg") == -1)
+ if (mathutils_array_parse(tvec, 3, 3, vec, "Matrix.Rotation(angle, size, axis), invalid 'axis' arg") == -1) {
return NULL;
+ }
axis_angle_to_mat3((float (*)[3])mat, tvec, angle);
}
@@ -554,8 +575,9 @@ static PyObject *C_Matrix_Translation(PyObject *cls, PyObject *value)
unit_m4(mat);
- if (mathutils_array_parse(mat[3], 3, 4, value, "mathutils.Matrix.Translation(vector), invalid vector arg") == -1)
+ if (mathutils_array_parse(mat[3], 3, 4, value, "mathutils.Matrix.Translation(vector), invalid vector arg") == -1) {
return NULL;
+ }
return Matrix_CreatePyObject(&mat[0][0], 4, 4, (PyTypeObject *)cls);
}
@@ -1079,8 +1101,9 @@ static PyObject *Matrix_to_quaternion(MatrixObject *self)
{
float quat[4];
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
/* must be 3-4 cols, 3-4 rows, square matrix */
if ((self->num_row < 3) || (self->num_col < 3) || (self->num_row != self->num_col)) {
@@ -1125,15 +1148,18 @@ static PyObject *Matrix_to_euler(MatrixObject *self, PyObject *args)
float mat[3][3];
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
- if (!PyArg_ParseTuple(args, "|sO!:to_euler", &order_str, &euler_Type, &eul_compat))
+ if (!PyArg_ParseTuple(args, "|sO!:to_euler", &order_str, &euler_Type, &eul_compat)) {
return NULL;
+ }
if (eul_compat) {
- if (BaseMath_ReadCallback(eul_compat) == -1)
+ if (BaseMath_ReadCallback(eul_compat) == -1) {
return NULL;
+ }
copy_v3_v3(eul_compatf, eul_compat->eul);
}
@@ -1155,19 +1181,28 @@ static PyObject *Matrix_to_euler(MatrixObject *self, PyObject *args)
if (order_str) {
order = euler_order_from_string(order_str, "Matrix.to_euler()");
- if (order == -1)
+ if (order == -1) {
return NULL;
+ }
}
normalize_m3(mat);
if (eul_compat) {
- if (order == 1) mat3_normalized_to_compatible_eul(eul, eul_compatf, mat);
- else mat3_normalized_to_compatible_eulO(eul, eul_compatf, order, mat);
+ if (order == 1) {
+ mat3_normalized_to_compatible_eul(eul, eul_compatf, mat);
+ }
+ else {
+ mat3_normalized_to_compatible_eulO(eul, eul_compatf, order, mat);
+ }
}
else {
- if (order == 1) mat3_normalized_to_eul(eul, mat);
- else mat3_normalized_to_eulO(eul, order, mat);
+ if (order == 1) {
+ mat3_normalized_to_eul(eul, mat);
+ }
+ else {
+ mat3_normalized_to_eulO(eul, order, mat);
+ }
}
return Euler_CreatePyObject(eul, order, NULL);
@@ -1228,8 +1263,9 @@ PyDoc_STRVAR(Matrix_to_4x4_doc,
);
static PyObject *Matrix_to_4x4(MatrixObject *self)
{
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
if (self->num_row == 4 && self->num_col == 4) {
return Matrix_CreatePyObject(self->matrix, 4, 4, Py_TYPE(self));
@@ -1259,8 +1295,9 @@ static PyObject *Matrix_to_3x3(MatrixObject *self)
{
float mat[3][3];
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
if ((self->num_row < 3) || (self->num_col < 3)) {
PyErr_SetString(PyExc_ValueError,
@@ -1283,8 +1320,9 @@ PyDoc_STRVAR(Matrix_to_translation_doc,
);
static PyObject *Matrix_to_translation(MatrixObject *self)
{
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
if ((self->num_row < 3) || self->num_col < 4) {
PyErr_SetString(PyExc_ValueError,
@@ -1312,8 +1350,9 @@ static PyObject *Matrix_to_scale(MatrixObject *self)
float mat[3][3];
float size[3];
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
/*must be 3-4 cols, 3-4 rows, square matrix */
if ((self->num_row < 3) || (self->num_col < 3)) {
@@ -1401,8 +1440,9 @@ PyDoc_STRVAR(Matrix_invert_doc,
);
static PyObject *Matrix_invert(MatrixObject *self, PyObject *args)
{
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return NULL;
+ }
if (matrix_invert_is_compat(self) == false) {
return NULL;
@@ -1419,8 +1459,9 @@ static PyObject *Matrix_invert(MatrixObject *self, PyObject *args)
if (PyTuple_GET_SIZE(args) == 1) {
MatrixObject *fallback = (MatrixObject *)PyTuple_GET_ITEM(args, 0);
- if (BaseMath_ReadCallback(fallback) == -1)
+ if (BaseMath_ReadCallback(fallback) == -1) {
return NULL;
+ }
if (self != fallback) {
matrix_copy(self, fallback);
@@ -1451,8 +1492,9 @@ static PyObject *Matrix_inverted(MatrixObject *self, PyObject *args)
{
float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM];
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
if (matrix_invert_args_check(self, args, false) == false) {
return NULL;
@@ -1482,8 +1524,9 @@ static PyObject *Matrix_inverted(MatrixObject *self, PyObject *args)
static PyObject *Matrix_inverted_noargs(MatrixObject *self)
{
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return NULL;
+ }
if (matrix_invert_is_compat(self) == false) {
return NULL;
@@ -1512,8 +1555,9 @@ PyDoc_STRVAR(Matrix_invert_safe_doc,
);
static PyObject *Matrix_invert_safe(MatrixObject *self)
{
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return NULL;
+ }
if (matrix_invert_is_compat(self) == false) {
return NULL;
@@ -1539,8 +1583,9 @@ static PyObject *Matrix_inverted_safe(MatrixObject *self)
{
float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM];
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
if (matrix_invert_is_compat(self) == false) {
return NULL;
@@ -1563,8 +1608,9 @@ PyDoc_STRVAR(Matrix_adjugate_doc,
);
static PyObject *Matrix_adjugate(MatrixObject *self)
{
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return NULL;
+ }
if (self->num_col != self->num_row) {
PyErr_SetString(PyExc_ValueError,
@@ -1618,11 +1664,13 @@ static PyObject *Matrix_rotate(MatrixObject *self, PyObject *value)
{
float self_rmat[3][3], other_rmat[3][3], rmat[3][3];
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return NULL;
+ }
- if (mathutils_any_to_rotmat(other_rmat, value, "matrix.rotate(value)") == -1)
+ if (mathutils_any_to_rotmat(other_rmat, value, "matrix.rotate(value)") == -1) {
return NULL;
+ }
if (self->num_row != 3 || self->num_col != 3) {
PyErr_SetString(PyExc_ValueError,
@@ -1664,8 +1712,9 @@ static PyObject *Matrix_decompose(MatrixObject *self)
return NULL;
}
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
mat4_to_loc_rot_size(loc, rot, size, (float (*)[4])self->matrix);
mat3_to_quat(quat, rot);
@@ -1698,8 +1747,9 @@ static PyObject *Matrix_lerp(MatrixObject *self, PyObject *args)
MatrixObject *mat2 = NULL;
float fac, mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM];
- if (!PyArg_ParseTuple(args, "O!f:lerp", &matrix_Type, &mat2, &fac))
+ if (!PyArg_ParseTuple(args, "O!f:lerp", &matrix_Type, &mat2, &fac)) {
return NULL;
+ }
if (self->num_col != mat2->num_col || self->num_row != mat2->num_row) {
PyErr_SetString(PyExc_ValueError,
@@ -1708,8 +1758,9 @@ static PyObject *Matrix_lerp(MatrixObject *self, PyObject *args)
return NULL;
}
- if (BaseMath_ReadCallback(self) == -1 || BaseMath_ReadCallback(mat2) == -1)
+ if (BaseMath_ReadCallback(self) == -1 || BaseMath_ReadCallback(mat2) == -1) {
return NULL;
+ }
/* TODO, different sized matrix */
if (self->num_col == 4 && self->num_row == 4) {
@@ -1749,8 +1800,9 @@ PyDoc_STRVAR(Matrix_determinant_doc,
);
static PyObject *Matrix_determinant(MatrixObject *self)
{
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
if (self->num_col != self->num_row) {
PyErr_SetString(PyExc_ValueError,
@@ -1771,8 +1823,9 @@ PyDoc_STRVAR(Matrix_transpose_doc,
);
static PyObject *Matrix_transpose(MatrixObject *self)
{
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return NULL;
+ }
if (self->num_col != self->num_row) {
PyErr_SetString(PyExc_ValueError,
@@ -1818,8 +1871,9 @@ PyDoc_STRVAR(Matrix_normalize_doc,
);
static PyObject *Matrix_normalize(MatrixObject *self)
{
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return NULL;
+ }
if (self->num_col != self->num_row) {
PyErr_SetString(PyExc_ValueError,
@@ -1867,13 +1921,15 @@ PyDoc_STRVAR(Matrix_zero_doc,
);
static PyObject *Matrix_zero(MatrixObject *self)
{
- if (BaseMath_Prepare_ForWrite(self) == -1)
+ if (BaseMath_Prepare_ForWrite(self) == -1) {
return NULL;
+ }
copy_vn_fl(self->matrix, self->num_col * self->num_row, 0.0f);
- if (BaseMath_WriteCallback(self) == -1)
+ if (BaseMath_WriteCallback(self) == -1) {
return NULL;
+ }
Py_RETURN_NONE;
@@ -1906,8 +1962,9 @@ PyDoc_STRVAR(Matrix_identity_doc,
);
static PyObject *Matrix_identity(MatrixObject *self)
{
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return NULL;
+ }
if (self->num_col != self->num_row) {
PyErr_SetString(PyExc_ValueError,
@@ -1918,8 +1975,9 @@ static PyObject *Matrix_identity(MatrixObject *self)
matrix_identity_internal(self);
- if (BaseMath_WriteCallback(self) == -1)
+ if (BaseMath_WriteCallback(self) == -1) {
return NULL;
+ }
Py_RETURN_NONE;
}
@@ -1941,8 +1999,9 @@ PyDoc_STRVAR(Matrix_copy_doc,
);
static PyObject *Matrix_copy(MatrixObject *self)
{
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
return Matrix_copy_notest(self, self->matrix);
}
@@ -1961,8 +2020,9 @@ static PyObject *Matrix_repr(MatrixObject *self)
int col, row;
PyObject *rows[MATRIX_MAX_DIM] = {NULL};
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
for (row = 0; row < self->num_row; row++) {
rows[row] = PyTuple_New(self->num_col);
@@ -1998,8 +2058,9 @@ static PyObject *Matrix_str(MatrixObject *self)
char dummy_buf[64];
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
ds = BLI_dynstr_new();
@@ -2035,8 +2096,9 @@ static PyObject *Matrix_richcmpr(PyObject *a, PyObject *b, int op)
MatrixObject *matA = (MatrixObject *)a;
MatrixObject *matB = (MatrixObject *)b;
- if (BaseMath_ReadCallback(matA) == -1 || BaseMath_ReadCallback(matB) == -1)
+ if (BaseMath_ReadCallback(matA) == -1 || BaseMath_ReadCallback(matB) == -1) {
return NULL;
+ }
ok = ((matA->num_row == matB->num_row) &&
(matA->num_col == matB->num_col) &&
@@ -2070,11 +2132,13 @@ static Py_hash_t Matrix_hash(MatrixObject *self)
{
float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM];
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return -1;
+ }
- if (BaseMathObject_Prepare_ForHash(self) == -1)
+ if (BaseMathObject_Prepare_ForHash(self) == -1) {
return -1;
+ }
matrix_transpose_internal(mat, self);
@@ -2093,8 +2157,9 @@ static int Matrix_len(MatrixObject *self)
* the wrapped vector gives direct access to the matrix data */
static PyObject *Matrix_item_row(MatrixObject *self, int row)
{
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return NULL;
+ }
if (row < 0 || row >= self->num_row) {
PyErr_SetString(PyExc_IndexError,
@@ -2107,8 +2172,9 @@ static PyObject *Matrix_item_row(MatrixObject *self, int row)
/* same but column access */
static PyObject *Matrix_item_col(MatrixObject *self, int col)
{
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return NULL;
+ }
if (col < 0 || col >= self->num_col) {
PyErr_SetString(PyExc_IndexError,
@@ -2126,8 +2192,9 @@ static int Matrix_ass_item_row(MatrixObject *self, int row, PyObject *value)
{
int col;
float vec[MATRIX_MAX_DIM];
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return -1;
+ }
if (row >= self->num_row || row < 0) {
PyErr_SetString(PyExc_IndexError,
@@ -2151,8 +2218,9 @@ static int Matrix_ass_item_col(MatrixObject *self, int col, PyObject *value)
{
int row;
float vec[MATRIX_MAX_DIM];
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return -1;
+ }
if (col >= self->num_col || col < 0) {
PyErr_SetString(PyExc_IndexError,
@@ -2182,8 +2250,9 @@ static PyObject *Matrix_slice(MatrixObject *self, int begin, int end)
PyObject *tuple;
int count;
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
CLAMP(begin, 0, self->num_row);
CLAMP(end, 0, self->num_row);
@@ -2203,8 +2272,9 @@ static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *va
{
PyObject *value_fast;
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return -1;
+ }
CLAMP(begin, 0, self->num_row);
CLAMP(end, 0, self->num_row);
@@ -2276,8 +2346,9 @@ static PyObject *Matrix_add(PyObject *m1, PyObject *m2)
return NULL;
}
- if (BaseMath_ReadCallback(mat1) == -1 || BaseMath_ReadCallback(mat2) == -1)
+ if (BaseMath_ReadCallback(mat1) == -1 || BaseMath_ReadCallback(mat2) == -1) {
return NULL;
+ }
if (mat1->num_col != mat2->num_col || mat1->num_row != mat2->num_row) {
PyErr_SetString(PyExc_ValueError,
@@ -2308,8 +2379,9 @@ static PyObject *Matrix_sub(PyObject *m1, PyObject *m2)
return NULL;
}
- if (BaseMath_ReadCallback(mat1) == -1 || BaseMath_ReadCallback(mat2) == -1)
+ if (BaseMath_ReadCallback(mat1) == -1 || BaseMath_ReadCallback(mat2) == -1) {
return NULL;
+ }
if (mat1->num_col != mat2->num_col || mat1->num_row != mat2->num_row) {
PyErr_SetString(PyExc_ValueError,
@@ -2339,13 +2411,15 @@ static PyObject *Matrix_mul(PyObject *m1, PyObject *m2)
if (MatrixObject_Check(m1)) {
mat1 = (MatrixObject *)m1;
- if (BaseMath_ReadCallback(mat1) == -1)
+ if (BaseMath_ReadCallback(mat1) == -1) {
return NULL;
+ }
}
if (MatrixObject_Check(m2)) {
mat2 = (MatrixObject *)m2;
- if (BaseMath_ReadCallback(mat2) == -1)
+ if (BaseMath_ReadCallback(mat2) == -1) {
return NULL;
+ }
}
if (mat1 && mat2) {
@@ -2394,13 +2468,15 @@ static PyObject *Matrix_imul(PyObject *m1, PyObject *m2)
if (MatrixObject_Check(m1)) {
mat1 = (MatrixObject *)m1;
- if (BaseMath_ReadCallback(mat1) == -1)
+ if (BaseMath_ReadCallback(mat1) == -1) {
return NULL;
+ }
}
if (MatrixObject_Check(m2)) {
mat2 = (MatrixObject *)m2;
- if (BaseMath_ReadCallback(mat2) == -1)
+ if (BaseMath_ReadCallback(mat2) == -1) {
return NULL;
+ }
}
if (mat1 && mat2) {
@@ -2448,13 +2524,15 @@ static PyObject *Matrix_matmul(PyObject *m1, PyObject *m2)
if (MatrixObject_Check(m1)) {
mat1 = (MatrixObject *)m1;
- if (BaseMath_ReadCallback(mat1) == -1)
+ if (BaseMath_ReadCallback(mat1) == -1) {
return NULL;
+ }
}
if (MatrixObject_Check(m2)) {
mat2 = (MatrixObject *)m2;
- if (BaseMath_ReadCallback(mat2) == -1)
+ if (BaseMath_ReadCallback(mat2) == -1) {
return NULL;
+ }
}
if (mat1 && mat2) {
@@ -2487,8 +2565,9 @@ static PyObject *Matrix_matmul(PyObject *m1, PyObject *m2)
if (VectorObject_Check(m2)) {
VectorObject *vec2 = (VectorObject *)m2;
float tvec[MATRIX_MAX_DIM];
- if (BaseMath_ReadCallback(vec2) == -1)
+ if (BaseMath_ReadCallback(vec2) == -1) {
return NULL;
+ }
if (column_vector_multiplication(tvec, vec2, mat1) == -1) {
return NULL;
}
@@ -2518,13 +2597,15 @@ static PyObject *Matrix_imatmul(PyObject *m1, PyObject *m2)
if (MatrixObject_Check(m1)) {
mat1 = (MatrixObject *)m1;
- if (BaseMath_ReadCallback(mat1) == -1)
+ if (BaseMath_ReadCallback(mat1) == -1) {
return NULL;
+ }
}
if (MatrixObject_Check(m2)) {
mat2 = (MatrixObject *)m2;
- if (BaseMath_ReadCallback(mat2) == -1)
+ if (BaseMath_ReadCallback(mat2) == -1) {
return NULL;
+ }
}
if (mat1 && mat2) {
@@ -2587,17 +2668,20 @@ static PyObject *Matrix_subscript(MatrixObject *self, PyObject *item)
if (PyIndex_Check(item)) {
Py_ssize_t i;
i = PyNumber_AsSsize_t(item, PyExc_IndexError);
- if (i == -1 && PyErr_Occurred())
+ if (i == -1 && PyErr_Occurred()) {
return NULL;
- if (i < 0)
+ }
+ if (i < 0) {
i += self->num_row;
+ }
return Matrix_item_row(self, i);
}
else if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelength;
- if (PySlice_GetIndicesEx(item, self->num_row, &start, &stop, &step, &slicelength) < 0)
+ if (PySlice_GetIndicesEx(item, self->num_row, &start, &stop, &step, &slicelength) < 0) {
return NULL;
+ }
if (slicelength <= 0) {
return PyTuple_New(0);
@@ -2623,20 +2707,24 @@ static int Matrix_ass_subscript(MatrixObject *self, PyObject *item, PyObject *va
{
if (PyIndex_Check(item)) {
Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
- if (i == -1 && PyErr_Occurred())
+ if (i == -1 && PyErr_Occurred()) {
return -1;
- if (i < 0)
+ }
+ if (i < 0) {
i += self->num_row;
+ }
return Matrix_ass_item_row(self, i, value);
}
else if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelength;
- if (PySlice_GetIndicesEx(item, self->num_row, &start, &stop, &step, &slicelength) < 0)
+ if (PySlice_GetIndicesEx(item, self->num_row, &start, &stop, &step, &slicelength) < 0) {
return -1;
+ }
- if (step == 1)
+ if (step == 1) {
return Matrix_ass_slice(self, start, stop, value);
+ }
else {
PyErr_SetString(PyExc_IndexError,
"slice steps not supported with matrices");
@@ -2704,8 +2792,9 @@ static PyObject *Matrix_translation_get(MatrixObject *self, void *UNUSED(closure
{
PyObject *ret;
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
/*must be 4x4 square matrix*/
if (self->num_row != 4 || self->num_col != 4) {
@@ -2724,8 +2813,9 @@ static int Matrix_translation_set(MatrixObject *self, PyObject *value, void *UNU
{
float tvec[3];
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return -1;
+ }
/*must be 4x4 square matrix*/
if (self->num_row != 4 || self->num_col != 4) {
@@ -2769,8 +2859,9 @@ static PyObject *Matrix_median_scale_get(MatrixObject *self, void *UNUSED(closur
{
float mat[3][3];
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
/*must be 3-4 cols, 3-4 rows, square matrix*/
if ((self->num_row < 3) || (self->num_col < 3)) {
@@ -2790,14 +2881,17 @@ PyDoc_STRVAR(Matrix_is_negative_doc,
);
static PyObject *Matrix_is_negative_get(MatrixObject *self, void *UNUSED(closure))
{
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
/*must be 3-4 cols, 3-4 rows, square matrix*/
- if (self->num_row == 4 && self->num_col == 4)
+ if (self->num_row == 4 && self->num_col == 4) {
return PyBool_FromLong(is_negative_m4((float (*)[4])self->matrix));
- else if (self->num_row == 3 && self->num_col == 3)
+ }
+ else if (self->num_row == 3 && self->num_col == 3) {
return PyBool_FromLong(is_negative_m3((float (*)[3])self->matrix));
+ }
else {
PyErr_SetString(PyExc_AttributeError,
"Matrix.is_negative: "
@@ -2811,14 +2905,17 @@ PyDoc_STRVAR(Matrix_is_orthogonal_doc,
);
static PyObject *Matrix_is_orthogonal_get(MatrixObject *self, void *UNUSED(closure))
{
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
/*must be 3-4 cols, 3-4 rows, square matrix*/
- if (self->num_row == 4 && self->num_col == 4)
+ if (self->num_row == 4 && self->num_col == 4) {
return PyBool_FromLong(is_orthonormal_m4((float (*)[4])self->matrix));
- else if (self->num_row == 3 && self->num_col == 3)
+ }
+ else if (self->num_row == 3 && self->num_col == 3) {
return PyBool_FromLong(is_orthonormal_m3((float (*)[3])self->matrix));
+ }
else {
PyErr_SetString(PyExc_AttributeError,
"Matrix.is_orthogonal: "
@@ -2832,14 +2929,17 @@ PyDoc_STRVAR(Matrix_is_orthogonal_axis_vectors_doc,
);
static PyObject *Matrix_is_orthogonal_axis_vectors_get(MatrixObject *self, void *UNUSED(closure))
{
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
/*must be 3-4 cols, 3-4 rows, square matrix*/
- if (self->num_row == 4 && self->num_col == 4)
+ if (self->num_row == 4 && self->num_col == 4) {
return PyBool_FromLong(is_orthogonal_m4((float (*)[4])self->matrix));
- else if (self->num_row == 3 && self->num_col == 3)
+ }
+ else if (self->num_row == 3 && self->num_col == 3) {
return PyBool_FromLong(is_orthogonal_m3((float (*)[3])self->matrix));
+ }
else {
PyErr_SetString(PyExc_AttributeError,
"Matrix.is_orthogonal_axis_vectors: "
@@ -3208,7 +3308,9 @@ static PyObject *MatrixAccess_slice(MatrixAccessObject *self, int begin, int end
}
CLAMP(begin, 0, matrix_access_len);
- if (end < 0) end = (matrix_access_len + 1) + end;
+ if (end < 0) {
+ end = (matrix_access_len + 1) + end;
+ }
CLAMP(end, 0, matrix_access_len);
begin = MIN2(begin, end);
@@ -3227,24 +3329,28 @@ static PyObject *MatrixAccess_subscript(MatrixAccessObject *self, PyObject *item
if (PyIndex_Check(item)) {
Py_ssize_t i;
i = PyNumber_AsSsize_t(item, PyExc_IndexError);
- if (i == -1 && PyErr_Occurred())
+ if (i == -1 && PyErr_Occurred()) {
return NULL;
+ }
if (self->type == MAT_ACCESS_ROW) {
- if (i < 0)
+ if (i < 0) {
i += matrix_user->num_row;
+ }
return Matrix_item_row(matrix_user, i);
}
else { /* MAT_ACCESS_ROW */
- if (i < 0)
+ if (i < 0) {
i += matrix_user->num_col;
+ }
return Matrix_item_col(matrix_user, i);
}
}
else if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelength;
- if (PySlice_GetIndicesEx(item, MatrixAccess_len(self), &start, &stop, &step, &slicelength) < 0)
+ if (PySlice_GetIndicesEx(item, MatrixAccess_len(self), &start, &stop, &step, &slicelength) < 0) {
return NULL;
+ }
if (slicelength <= 0) {
return PyTuple_New(0);
@@ -3272,17 +3378,20 @@ static int MatrixAccess_ass_subscript(MatrixAccessObject *self, PyObject *item,
if (PyIndex_Check(item)) {
Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
- if (i == -1 && PyErr_Occurred())
+ if (i == -1 && PyErr_Occurred()) {
return -1;
+ }
if (self->type == MAT_ACCESS_ROW) {
- if (i < 0)
+ if (i < 0) {
i += matrix_user->num_row;
+ }
return Matrix_ass_item_row(matrix_user, i, value);
}
else { /* MAT_ACCESS_ROW */
- if (i < 0)
+ if (i < 0) {
i += matrix_user->num_col;
+ }
return Matrix_ass_item_col(matrix_user, i, value);
}
diff --git a/source/blender/python/mathutils/mathutils_Quaternion.c b/source/blender/python/mathutils/mathutils_Quaternion.c
index 5f7ab5fface..422a1ff28fa 100644
--- a/source/blender/python/mathutils/mathutils_Quaternion.c
+++ b/source/blender/python/mathutils/mathutils_Quaternion.c
@@ -87,31 +87,43 @@ static PyObject *Quaternion_to_euler(QuaternionObject *self, PyObject *args)
short order = EULER_ORDER_XYZ;
EulerObject *eul_compat = NULL;
- if (!PyArg_ParseTuple(args, "|sO!:to_euler", &order_str, &euler_Type, &eul_compat))
+ if (!PyArg_ParseTuple(args, "|sO!:to_euler", &order_str, &euler_Type, &eul_compat)) {
return NULL;
+ }
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
if (order_str) {
order = euler_order_from_string(order_str, "Matrix.to_euler()");
- if (order == -1)
+ if (order == -1) {
return NULL;
+ }
}
normalize_qt_qt(tquat, self->quat);
if (eul_compat) {
- if (BaseMath_ReadCallback(eul_compat) == -1)
+ if (BaseMath_ReadCallback(eul_compat) == -1) {
return NULL;
+ }
- if (order == EULER_ORDER_XYZ) quat_to_compatible_eul(eul, eul_compat->eul, tquat);
- else quat_to_compatible_eulO(eul, eul_compat->eul, order, tquat);
+ if (order == EULER_ORDER_XYZ) {
+ quat_to_compatible_eul(eul, eul_compat->eul, tquat);
+ }
+ else {
+ quat_to_compatible_eulO(eul, eul_compat->eul, order, tquat);
+ }
}
else {
- if (order == EULER_ORDER_XYZ) quat_to_eul(eul, tquat);
- else quat_to_eulO(eul, order, tquat);
+ if (order == EULER_ORDER_XYZ) {
+ quat_to_eul(eul, tquat);
+ }
+ else {
+ quat_to_eulO(eul, order, tquat);
+ }
}
return Euler_CreatePyObject(eul, order, NULL);
@@ -129,8 +141,9 @@ static PyObject *Quaternion_to_matrix(QuaternionObject *self)
{
float mat[9]; /* all values are set */
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
quat_to_mat3((float (*)[3])mat, self->quat);
return Matrix_CreatePyObject(mat, 3, 3, NULL);
@@ -153,8 +166,9 @@ static PyObject *Quaternion_to_axis_angle(QuaternionObject *self)
float axis[3];
float angle;
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
normalize_qt_qt(tquat, self->quat);
quat_to_axis_angle(axis, &angle, tquat);
@@ -185,8 +199,9 @@ static PyObject *Quaternion_to_exponential_map(QuaternionObject *self)
{
float expmap[3];
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
quat_to_expmap(expmap, self->quat);
return Vector_CreatePyObject(expmap, 3, NULL);
@@ -206,8 +221,9 @@ static PyObject *Quaternion_cross(QuaternionObject *self, PyObject *value)
{
float quat[QUAT_SIZE], tquat[QUAT_SIZE];
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
if (mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value,
"Quaternion.cross(other), invalid 'other' arg") == -1)
@@ -233,8 +249,9 @@ static PyObject *Quaternion_dot(QuaternionObject *self, PyObject *value)
{
float tquat[QUAT_SIZE];
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
if (mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value,
"Quaternion.dot(other), invalid 'other' arg") == -1)
@@ -259,8 +276,9 @@ static PyObject *Quaternion_rotation_difference(QuaternionObject *self, PyObject
{
float tquat[QUAT_SIZE], quat[QUAT_SIZE];
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
if (mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value,
"Quaternion.difference(other), invalid 'other' arg") == -1)
@@ -297,8 +315,9 @@ static PyObject *Quaternion_slerp(QuaternionObject *self, PyObject *args)
return NULL;
}
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
if (mathutils_array_parse(tquat, QUAT_SIZE, QUAT_SIZE, value,
"Quaternion.slerp(other), invalid 'other' arg") == -1)
@@ -331,11 +350,13 @@ static PyObject *Quaternion_rotate(QuaternionObject *self, PyObject *value)
float self_rmat[3][3], other_rmat[3][3], rmat[3][3];
float tquat[4], length;
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return NULL;
+ }
- if (mathutils_any_to_rotmat(other_rmat, value, "Quaternion.rotate(value)") == -1)
+ if (mathutils_any_to_rotmat(other_rmat, value, "Quaternion.rotate(value)") == -1) {
return NULL;
+ }
length = normalize_qt_qt(tquat, self->quat);
quat_to_mat3(self_rmat, tquat);
@@ -358,8 +379,9 @@ PyDoc_STRVAR(Quaternion_normalize_doc,
);
static PyObject *Quaternion_normalize(QuaternionObject *self)
{
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return NULL;
+ }
normalize_qt(self->quat);
@@ -386,8 +408,9 @@ PyDoc_STRVAR(Quaternion_invert_doc,
);
static PyObject *Quaternion_invert(QuaternionObject *self)
{
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return NULL;
+ }
invert_qt(self->quat);
@@ -416,8 +439,9 @@ PyDoc_STRVAR(Quaternion_identity_doc,
);
static PyObject *Quaternion_identity(QuaternionObject *self)
{
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return NULL;
+ }
unit_qt(self->quat);
@@ -434,8 +458,9 @@ PyDoc_STRVAR(Quaternion_negate_doc,
);
static PyObject *Quaternion_negate(QuaternionObject *self)
{
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return NULL;
+ }
mul_qt_fl(self->quat, -1.0f);
@@ -450,8 +475,9 @@ PyDoc_STRVAR(Quaternion_conjugate_doc,
);
static PyObject *Quaternion_conjugate(QuaternionObject *self)
{
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return NULL;
+ }
conjugate_qt(self->quat);
@@ -484,8 +510,9 @@ PyDoc_STRVAR(Quaternion_copy_doc,
);
static PyObject *Quaternion_copy(QuaternionObject *self)
{
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
return Quaternion_CreatePyObject(self->quat, Py_TYPE(self));
}
@@ -502,8 +529,9 @@ static PyObject *Quaternion_repr(QuaternionObject *self)
{
PyObject *ret, *tuple;
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
tuple = Quaternion_to_tuple_ext(self, -1);
@@ -518,8 +546,9 @@ static PyObject *Quaternion_str(QuaternionObject *self)
{
DynStr *ds;
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
ds = BLI_dynstr_new();
@@ -539,8 +568,9 @@ static PyObject *Quaternion_richcmpr(PyObject *a, PyObject *b, int op)
QuaternionObject *quatA = (QuaternionObject *)a;
QuaternionObject *quatB = (QuaternionObject *)b;
- if (BaseMath_ReadCallback(quatA) == -1 || BaseMath_ReadCallback(quatB) == -1)
+ if (BaseMath_ReadCallback(quatA) == -1 || BaseMath_ReadCallback(quatB) == -1) {
return NULL;
+ }
ok = (EXPP_VectorsAreEqual(quatA->quat, quatB->quat, QUAT_SIZE, 1)) ? 0 : -1;
}
@@ -569,11 +599,13 @@ static PyObject *Quaternion_richcmpr(PyObject *a, PyObject *b, int op)
static Py_hash_t Quaternion_hash(QuaternionObject *self)
{
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return -1;
+ }
- if (BaseMathObject_Prepare_ForHash(self) == -1)
+ if (BaseMathObject_Prepare_ForHash(self) == -1) {
return -1;
+ }
return mathutils_array_hash(self->quat, QUAT_SIZE);
}
@@ -589,7 +621,9 @@ static int Quaternion_len(QuaternionObject *UNUSED(self))
/* sequence accessor (get) */
static PyObject *Quaternion_item(QuaternionObject *self, int i)
{
- if (i < 0) i = QUAT_SIZE - i;
+ if (i < 0) {
+ i = QUAT_SIZE - i;
+ }
if (i < 0 || i >= QUAT_SIZE) {
PyErr_SetString(PyExc_IndexError,
@@ -598,8 +632,9 @@ static PyObject *Quaternion_item(QuaternionObject *self, int i)
return NULL;
}
- if (BaseMath_ReadIndexCallback(self, i) == -1)
+ if (BaseMath_ReadIndexCallback(self, i) == -1) {
return NULL;
+ }
return PyFloat_FromDouble(self->quat[i]);
@@ -610,8 +645,9 @@ static int Quaternion_ass_item(QuaternionObject *self, int i, PyObject *ob)
{
float f;
- if (BaseMath_Prepare_ForWrite(self) == -1)
+ if (BaseMath_Prepare_ForWrite(self) == -1) {
return -1;
+ }
f = (float)PyFloat_AsDouble(ob);
@@ -622,7 +658,9 @@ static int Quaternion_ass_item(QuaternionObject *self, int i, PyObject *ob)
return -1;
}
- if (i < 0) i = QUAT_SIZE - i;
+ if (i < 0) {
+ i = QUAT_SIZE - i;
+ }
if (i < 0 || i >= QUAT_SIZE) {
PyErr_SetString(PyExc_IndexError,
@@ -632,8 +670,9 @@ static int Quaternion_ass_item(QuaternionObject *self, int i, PyObject *ob)
}
self->quat[i] = f;
- if (BaseMath_WriteIndexCallback(self, i) == -1)
+ if (BaseMath_WriteIndexCallback(self, i) == -1) {
return -1;
+ }
return 0;
}
@@ -644,11 +683,14 @@ static PyObject *Quaternion_slice(QuaternionObject *self, int begin, int end)
PyObject *tuple;
int count;
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
CLAMP(begin, 0, QUAT_SIZE);
- if (end < 0) end = (QUAT_SIZE + 1) + end;
+ if (end < 0) {
+ end = (QUAT_SIZE + 1) + end;
+ }
CLAMP(end, 0, QUAT_SIZE);
begin = MIN2(begin, end);
@@ -666,16 +708,20 @@ static int Quaternion_ass_slice(QuaternionObject *self, int begin, int end, PyOb
int i, size;
float quat[QUAT_SIZE];
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return -1;
+ }
CLAMP(begin, 0, QUAT_SIZE);
- if (end < 0) end = (QUAT_SIZE + 1) + end;
+ if (end < 0) {
+ end = (QUAT_SIZE + 1) + end;
+ }
CLAMP(end, 0, QUAT_SIZE);
begin = MIN2(begin, end);
- if ((size = mathutils_array_parse(quat, 0, QUAT_SIZE, seq, "mathutils.Quaternion[begin:end] = []")) == -1)
+ if ((size = mathutils_array_parse(quat, 0, QUAT_SIZE, seq, "mathutils.Quaternion[begin:end] = []")) == -1) {
return -1;
+ }
if (size != (end - begin)) {
PyErr_SetString(PyExc_ValueError,
@@ -685,8 +731,9 @@ static int Quaternion_ass_slice(QuaternionObject *self, int begin, int end, PyOb
}
/* parsed well - now set in vector */
- for (i = 0; i < size; i++)
+ for (i = 0; i < size; i++) {
self->quat[begin + i] = quat[i];
+ }
(void)BaseMath_WriteCallback(self);
return 0;
@@ -698,17 +745,20 @@ static PyObject *Quaternion_subscript(QuaternionObject *self, PyObject *item)
if (PyIndex_Check(item)) {
Py_ssize_t i;
i = PyNumber_AsSsize_t(item, PyExc_IndexError);
- if (i == -1 && PyErr_Occurred())
+ if (i == -1 && PyErr_Occurred()) {
return NULL;
- if (i < 0)
+ }
+ if (i < 0) {
i += QUAT_SIZE;
+ }
return Quaternion_item(self, i);
}
else if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelength;
- if (PySlice_GetIndicesEx(item, QUAT_SIZE, &start, &stop, &step, &slicelength) < 0)
+ if (PySlice_GetIndicesEx(item, QUAT_SIZE, &start, &stop, &step, &slicelength) < 0) {
return NULL;
+ }
if (slicelength <= 0) {
return PyTuple_New(0);
@@ -735,20 +785,24 @@ static int Quaternion_ass_subscript(QuaternionObject *self, PyObject *item, PyOb
{
if (PyIndex_Check(item)) {
Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
- if (i == -1 && PyErr_Occurred())
+ if (i == -1 && PyErr_Occurred()) {
return -1;
- if (i < 0)
+ }
+ if (i < 0) {
i += QUAT_SIZE;
+ }
return Quaternion_ass_item(self, i, value);
}
else if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelength;
- if (PySlice_GetIndicesEx(item, QUAT_SIZE, &start, &stop, &step, &slicelength) < 0)
+ if (PySlice_GetIndicesEx(item, QUAT_SIZE, &start, &stop, &step, &slicelength) < 0) {
return -1;
+ }
- if (step == 1)
+ if (step == 1) {
return Quaternion_ass_slice(self, start, stop, value);
+ }
else {
PyErr_SetString(PyExc_IndexError,
"slice steps not supported with quaternion");
@@ -781,8 +835,9 @@ static PyObject *Quaternion_add(PyObject *q1, PyObject *q2)
quat1 = (QuaternionObject *)q1;
quat2 = (QuaternionObject *)q2;
- if (BaseMath_ReadCallback(quat1) == -1 || BaseMath_ReadCallback(quat2) == -1)
+ if (BaseMath_ReadCallback(quat1) == -1 || BaseMath_ReadCallback(quat2) == -1) {
return NULL;
+ }
add_qt_qtqt(quat, quat1->quat, quat2->quat, 1.0f);
return Quaternion_CreatePyObject(quat, Py_TYPE(q1));
@@ -806,8 +861,9 @@ static PyObject *Quaternion_sub(PyObject *q1, PyObject *q2)
quat1 = (QuaternionObject *)q1;
quat2 = (QuaternionObject *)q2;
- if (BaseMath_ReadCallback(quat1) == -1 || BaseMath_ReadCallback(quat2) == -1)
+ if (BaseMath_ReadCallback(quat1) == -1 || BaseMath_ReadCallback(quat2) == -1) {
return NULL;
+ }
for (x = 0; x < QUAT_SIZE; x++) {
quat[x] = quat1->quat[x] - quat2->quat[x];
@@ -833,13 +889,15 @@ static PyObject *Quaternion_mul(PyObject *q1, PyObject *q2)
if (QuaternionObject_Check(q1)) {
quat1 = (QuaternionObject *)q1;
- if (BaseMath_ReadCallback(quat1) == -1)
+ if (BaseMath_ReadCallback(quat1) == -1) {
return NULL;
+ }
}
if (QuaternionObject_Check(q2)) {
quat2 = (QuaternionObject *)q2;
- if (BaseMath_ReadCallback(quat2) == -1)
+ if (BaseMath_ReadCallback(quat2) == -1) {
return NULL;
+ }
}
if (quat1 && quat2) { /* QUAT * QUAT (element-wise product) */
@@ -876,13 +934,15 @@ static PyObject *Quaternion_imul(PyObject *q1, PyObject *q2)
if (QuaternionObject_Check(q1)) {
quat1 = (QuaternionObject *)q1;
- if (BaseMath_ReadCallback(quat1) == -1)
+ if (BaseMath_ReadCallback(quat1) == -1) {
return NULL;
+ }
}
if (QuaternionObject_Check(q2)) {
quat2 = (QuaternionObject *)q2;
- if (BaseMath_ReadCallback(quat2) == -1)
+ if (BaseMath_ReadCallback(quat2) == -1) {
return NULL;
+ }
}
if (quat1 && quat2) { /* QUAT *= QUAT (inplace element-wise product) */
@@ -921,13 +981,15 @@ static PyObject *Quaternion_matmul(PyObject *q1, PyObject *q2)
if (QuaternionObject_Check(q1)) {
quat1 = (QuaternionObject *)q1;
- if (BaseMath_ReadCallback(quat1) == -1)
+ if (BaseMath_ReadCallback(quat1) == -1) {
return NULL;
+ }
}
if (QuaternionObject_Check(q2)) {
quat2 = (QuaternionObject *)q2;
- if (BaseMath_ReadCallback(quat2) == -1)
+ if (BaseMath_ReadCallback(quat2) == -1) {
return NULL;
+ }
}
if (quat1 && quat2) { /* QUAT @ QUAT (cross product) */
@@ -973,13 +1035,15 @@ static PyObject *Quaternion_imatmul(PyObject *q1, PyObject *q2)
if (QuaternionObject_Check(q1)) {
quat1 = (QuaternionObject *)q1;
- if (BaseMath_ReadCallback(quat1) == -1)
+ if (BaseMath_ReadCallback(quat1) == -1) {
return NULL;
+ }
}
if (QuaternionObject_Check(q2)) {
quat2 = (QuaternionObject *)q2;
- if (BaseMath_ReadCallback(quat2) == -1)
+ if (BaseMath_ReadCallback(quat2) == -1) {
return NULL;
+ }
}
if (quat1 && quat2) { /* QUAT @ QUAT (cross product) */
@@ -1005,8 +1069,9 @@ static PyObject *Quaternion_neg(QuaternionObject *self)
{
float tquat[QUAT_SIZE];
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
negate_v4_v4(tquat, self->quat);
return Quaternion_CreatePyObject(tquat, Py_TYPE(self));
@@ -1090,8 +1155,9 @@ PyDoc_STRVAR(Quaternion_magnitude_doc,
);
static PyObject *Quaternion_magnitude_get(QuaternionObject *self, void *UNUSED(closure))
{
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
return PyFloat_FromDouble(sqrtf(dot_qtqt(self->quat, self->quat)));
}
@@ -1104,8 +1170,9 @@ static PyObject *Quaternion_angle_get(QuaternionObject *self, void *UNUSED(closu
float tquat[4];
float angle;
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
normalize_qt_qt(tquat, self->quat);
@@ -1124,8 +1191,9 @@ static int Quaternion_angle_set(QuaternionObject *self, PyObject *value, void *U
float axis[3], angle_dummy;
float angle;
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return -1;
+ }
len = normalize_qt_qt(tquat, self->quat);
quat_to_axis_angle(axis, &angle_dummy, tquat);
@@ -1145,8 +1213,9 @@ static int Quaternion_angle_set(QuaternionObject *self, PyObject *value, void *U
axis_angle_to_quat(self->quat, axis, angle);
mul_qt_fl(self->quat, len);
- if (BaseMath_WriteCallback(self) == -1)
+ if (BaseMath_WriteCallback(self) == -1) {
return -1;
+ }
return 0;
}
@@ -1161,8 +1230,9 @@ static PyObject *Quaternion_axis_vector_get(QuaternionObject *self, void *UNUSED
float axis[3];
float angle_dummy;
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
normalize_qt_qt(tquat, self->quat);
quat_to_axis_angle(axis, &angle_dummy, tquat);
@@ -1180,22 +1250,25 @@ static int Quaternion_axis_vector_set(QuaternionObject *self, PyObject *value, v
float axis[3];
float angle;
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return -1;
+ }
len = normalize_qt_qt(tquat, self->quat);
quat_to_axis_angle(axis, &angle, tquat); /* axis value is unused */
- if (mathutils_array_parse(axis, 3, 3, value, "quat.axis = other") == -1)
+ if (mathutils_array_parse(axis, 3, 3, value, "quat.axis = other") == -1) {
return -1;
+ }
quat__axis_angle_sanitize(axis, &angle);
axis_angle_to_quat(self->quat, axis, angle);
mul_qt_fl(self->quat, len);
- if (BaseMath_WriteCallback(self) == -1)
+ if (BaseMath_WriteCallback(self) == -1) {
return -1;
+ }
return 0;
}
@@ -1215,8 +1288,9 @@ static PyObject *Quaternion_new(PyTypeObject *type, PyObject *args, PyObject *kw
return NULL;
}
- if (!PyArg_ParseTuple(args, "|Od:mathutils.Quaternion", &seq, &angle))
+ if (!PyArg_ParseTuple(args, "|Od:mathutils.Quaternion", &seq, &angle)) {
return NULL;
+ }
switch (PyTuple_GET_SIZE(args)) {
case 0:
@@ -1243,8 +1317,9 @@ static PyObject *Quaternion_new(PyTypeObject *type, PyObject *args, PyObject *kw
case 2:
{
float axis[3];
- if (mathutils_array_parse(axis, 3, 3, seq, "mathutils.Quaternion()") == -1)
+ if (mathutils_array_parse(axis, 3, 3, seq, "mathutils.Quaternion()") == -1) {
return NULL;
+ }
angle = angle_wrap_rad(angle); /* clamp because of precision issues */
axis_angle_to_quat(quat, axis, angle);
break;
diff --git a/source/blender/python/mathutils/mathutils_Vector.c b/source/blender/python/mathutils/mathutils_Vector.c
index 11b8eff85f6..1dd578096f9 100644
--- a/source/blender/python/mathutils/mathutils_Vector.c
+++ b/source/blender/python/mathutils/mathutils_Vector.c
@@ -197,8 +197,9 @@ static PyObject *C_Vector_Range(PyObject *cls, PyObject *args)
size = (stop - start);
- if ((size % step) != 0)
+ if ((size % step) != 0) {
size += step;
+ }
size /= step;
@@ -338,13 +339,15 @@ PyDoc_STRVAR(Vector_zero_doc,
);
static PyObject *Vector_zero(VectorObject *self)
{
- if (BaseMath_Prepare_ForWrite(self) == -1)
+ if (BaseMath_Prepare_ForWrite(self) == -1) {
return NULL;
+ }
copy_vn_fl(self->vec, self->size, 0.0f);
- if (BaseMath_WriteCallback(self) == -1)
+ if (BaseMath_WriteCallback(self) == -1) {
return NULL;
+ }
Py_RETURN_NONE;
}
@@ -362,8 +365,9 @@ PyDoc_STRVAR(Vector_normalize_doc,
static PyObject *Vector_normalize(VectorObject *self)
{
int size = (self->size == 4 ? 3 : self->size);
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return NULL;
+ }
normalize_vn(self->vec, size);
@@ -533,8 +537,9 @@ static PyObject *Vector_resize_3d(VectorObject *self)
return NULL;
}
- if (self->size == 2)
+ if (self->size == 2) {
self->vec[2] = 0.0f;
+ }
self->size = 3;
Py_RETURN_NONE;
@@ -588,8 +593,9 @@ PyDoc_STRVAR(Vector_to_2d_doc,
);
static PyObject *Vector_to_2d(VectorObject *self)
{
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
return Vector_CreatePyObject(self->vec, 2, Py_TYPE(self));
}
@@ -605,8 +611,9 @@ static PyObject *Vector_to_3d(VectorObject *self)
{
float tvec[3] = {0.0f};
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
memcpy(tvec, self->vec, sizeof(float) * MIN2(self->size, 3));
return Vector_CreatePyObject(tvec, 3, Py_TYPE(self));
@@ -623,8 +630,9 @@ static PyObject *Vector_to_4d(VectorObject *self)
{
float tvec[4] = {0.0f, 0.0f, 0.0f, 1.0f};
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
memcpy(tvec, self->vec, sizeof(float) * MIN2(self->size, 4));
return Vector_CreatePyObject(tvec, 4, Py_TYPE(self));
@@ -666,8 +674,9 @@ static PyObject *Vector_to_tuple(VectorObject *self, PyObject *args)
{
int ndigits = 0;
- if (!PyArg_ParseTuple(args, "|i:to_tuple", &ndigits))
+ if (!PyArg_ParseTuple(args, "|i:to_tuple", &ndigits)) {
return NULL;
+ }
if (ndigits > 22 || ndigits < 0) {
PyErr_SetString(PyExc_ValueError,
@@ -676,11 +685,13 @@ static PyObject *Vector_to_tuple(VectorObject *self, PyObject *args)
return NULL;
}
- if (PyTuple_GET_SIZE(args) == 0)
+ if (PyTuple_GET_SIZE(args) == 0) {
ndigits = -1;
+ }
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
return Vector_to_tuple_ext(self, ndigits);
}
@@ -703,8 +714,9 @@ static PyObject *Vector_to_track_quat(VectorObject *self, PyObject *args)
const char *strack, *sup;
short track = 2, up = 1;
- if (!PyArg_ParseTuple(args, "|ss:to_track_quat", &strack, &sup))
+ if (!PyArg_ParseTuple(args, "|ss:to_track_quat", &strack, &sup)) {
return NULL;
+ }
if (self->size != 3) {
PyErr_SetString(PyExc_TypeError,
@@ -713,8 +725,9 @@ static PyObject *Vector_to_track_quat(VectorObject *self, PyObject *args)
return NULL;
}
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
if (strack) {
const char *axis_err_msg = "only X, -X, Y, -Y, Z or -Z for track axis";
@@ -826,13 +839,16 @@ static PyObject *Vector_orthogonal(VectorObject *self)
return NULL;
}
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
- if (self->size == 3)
+ if (self->size == 3) {
ortho_v3_v3(vec, self->vec);
- else
+ }
+ else {
ortho_v2_v2(vec, self->vec);
+ }
return Vector_CreatePyObject(vec, self->size, Py_TYPE(self));
}
@@ -861,11 +877,13 @@ static PyObject *Vector_reflect(VectorObject *self, PyObject *value)
float reflect[3] = {0.0f};
float tvec[MAX_DIMENSIONS];
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
- if ((value_size = mathutils_array_parse(tvec, 2, 4, value, "Vector.reflect(other), invalid 'other' arg")) == -1)
+ if ((value_size = mathutils_array_parse(tvec, 2, 4, value, "Vector.reflect(other), invalid 'other' arg")) == -1) {
return NULL;
+ }
if (self->size < 2 || self->size > 4) {
PyErr_SetString(PyExc_ValueError,
@@ -904,8 +922,9 @@ static PyObject *Vector_cross(VectorObject *self, PyObject *value)
PyObject *ret;
float tvec[3];
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
if (self->size > 3) {
PyErr_SetString(PyExc_ValueError,
@@ -913,8 +932,9 @@ static PyObject *Vector_cross(VectorObject *self, PyObject *value)
return NULL;
}
- if (mathutils_array_parse(tvec, self->size, self->size, value, "Vector.cross(other), invalid 'other' arg") == -1)
+ if (mathutils_array_parse(tvec, self->size, self->size, value, "Vector.cross(other), invalid 'other' arg") == -1) {
return NULL;
+ }
if (self->size == 3) {
ret = Vector_CreatePyObject(NULL, 3, Py_TYPE(self));
@@ -942,8 +962,9 @@ static PyObject *Vector_dot(VectorObject *self, PyObject *value)
float *tvec;
PyObject *ret;
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
if (mathutils_array_parse_alloc(&tvec, self->size, value, "Vector.dot(other), invalid 'other' arg") == -1) {
return NULL;
@@ -976,16 +997,19 @@ static PyObject *Vector_angle(VectorObject *self, PyObject *args)
int x;
PyObject *fallback = NULL;
- if (!PyArg_ParseTuple(args, "O|O:angle", &value, &fallback))
+ if (!PyArg_ParseTuple(args, "O|O:angle", &value, &fallback)) {
return NULL;
+ }
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
/* don't use clamped size, rule of thumb is vector sizes must match,
* even though n this case 'w' is ignored */
- if (mathutils_array_parse(tvec, self->size, self->size, value, "Vector.angle(other), invalid 'other' arg") == -1)
+ if (mathutils_array_parse(tvec, self->size, self->size, value, "Vector.angle(other), invalid 'other' arg") == -1) {
return NULL;
+ }
if (self->size > 4) {
PyErr_SetString(PyExc_ValueError,
@@ -1036,14 +1060,17 @@ static PyObject *Vector_angle_signed(VectorObject *self, PyObject *args)
PyObject *value;
PyObject *fallback = NULL;
- if (!PyArg_ParseTuple(args, "O|O:angle_signed", &value, &fallback))
+ if (!PyArg_ParseTuple(args, "O|O:angle_signed", &value, &fallback)) {
return NULL;
+ }
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
- if (mathutils_array_parse(tvec, 2, 2, value, "Vector.angle_signed(other), invalid 'other' arg") == -1)
+ if (mathutils_array_parse(tvec, 2, 2, value, "Vector.angle_signed(other), invalid 'other' arg") == -1) {
return NULL;
+ }
if (self->size != 2) {
PyErr_SetString(PyExc_ValueError,
@@ -1094,11 +1121,13 @@ static PyObject *Vector_rotation_difference(VectorObject *self, PyObject *value)
return NULL;
}
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
- if (mathutils_array_parse(vec_b, 3, MAX_DIMENSIONS, value, "Vector.difference(other), invalid 'other' arg") == -1)
+ if (mathutils_array_parse(vec_b, 3, MAX_DIMENSIONS, value, "Vector.difference(other), invalid 'other' arg") == -1) {
return NULL;
+ }
normalize_v3_v3(vec_a, self->vec);
normalize_v3(vec_b);
@@ -1125,8 +1154,9 @@ static PyObject *Vector_project(VectorObject *self, PyObject *value)
double dot = 0.0f, dot2 = 0.0f;
int x;
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
if (mathutils_array_parse_alloc(&tvec, size, value, "Vector.project(other), invalid 'other' arg") == -1) {
return NULL;
@@ -1164,8 +1194,9 @@ static PyObject *Vector_lerp(VectorObject *self, PyObject *args)
float fac;
float *tvec;
- if (!PyArg_ParseTuple(args, "Of:lerp", &value, &fac))
+ if (!PyArg_ParseTuple(args, "Of:lerp", &value, &fac)) {
return NULL;
+ }
if (BaseMath_ReadCallback(self) == -1) {
return NULL;
@@ -1205,8 +1236,9 @@ static PyObject *Vector_slerp(VectorObject *self, PyObject *args)
int x;
PyObject *fallback = NULL;
- if (!PyArg_ParseTuple(args, "Of|O:slerp", &value, &fac, &fallback))
+ if (!PyArg_ParseTuple(args, "Of|O:slerp", &value, &fac, &fallback)) {
return NULL;
+ }
if (BaseMath_ReadCallback(self) == -1) {
return NULL;
@@ -1281,11 +1313,13 @@ static PyObject *Vector_rotate(VectorObject *self, PyObject *value)
{
float other_rmat[3][3];
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return NULL;
+ }
- if (mathutils_any_to_rotmat(other_rmat, value, "Vector.rotate(value)") == -1)
+ if (mathutils_any_to_rotmat(other_rmat, value, "Vector.rotate(value)") == -1) {
return NULL;
+ }
if (self->size < 3 || self->size > 4) {
PyErr_SetString(PyExc_ValueError,
@@ -1312,8 +1346,9 @@ PyDoc_STRVAR(Vector_copy_doc,
);
static PyObject *Vector_copy(VectorObject *self)
{
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
return Vector_CreatePyObject(self->vec, self->size, Py_TYPE(self));
}
@@ -1329,8 +1364,9 @@ static PyObject *Vector_repr(VectorObject *self)
{
PyObject *ret, *tuple;
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
tuple = Vector_to_tuple_ext(self, -1);
ret = PyUnicode_FromFormat("Vector(%R)", tuple);
@@ -1345,8 +1381,9 @@ static PyObject *Vector_str(VectorObject *self)
DynStr *ds;
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
ds = BLI_dynstr_new();
@@ -1371,7 +1408,9 @@ static int Vector_len(VectorObject *self)
/* sequence accessor (get): vector[index] */
static PyObject *vector_item_internal(VectorObject *self, int i, const bool is_attr)
{
- if (i < 0) i = self->size - i;
+ if (i < 0) {
+ i = self->size - i;
+ }
if (i < 0 || i >= self->size) {
if (is_attr) {
@@ -1386,8 +1425,9 @@ static PyObject *vector_item_internal(VectorObject *self, int i, const bool is_a
return NULL;
}
- if (BaseMath_ReadIndexCallback(self, i) == -1)
+ if (BaseMath_ReadIndexCallback(self, i) == -1) {
return NULL;
+ }
return PyFloat_FromDouble(self->vec[i]);
}
@@ -1401,8 +1441,9 @@ static int vector_ass_item_internal(VectorObject *self, int i, PyObject *value,
{
float scalar;
- if (BaseMath_Prepare_ForWrite(self) == -1)
+ if (BaseMath_Prepare_ForWrite(self) == -1) {
return -1;
+ }
if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) { /* parsed item not a number */
PyErr_SetString(PyExc_TypeError,
@@ -1411,7 +1452,9 @@ static int vector_ass_item_internal(VectorObject *self, int i, PyObject *value,
return -1;
}
- if (i < 0) i = self->size - i;
+ if (i < 0) {
+ i = self->size - i;
+ }
if (i < 0 || i >= self->size) {
if (is_attr) {
@@ -1428,8 +1471,9 @@ static int vector_ass_item_internal(VectorObject *self, int i, PyObject *value,
}
self->vec[i] = scalar;
- if (BaseMath_WriteIndexCallback(self, i) == -1)
+ if (BaseMath_WriteIndexCallback(self, i) == -1) {
return -1;
+ }
return 0;
}
@@ -1444,11 +1488,14 @@ static PyObject *Vector_slice(VectorObject *self, int begin, int end)
PyObject *tuple;
int count;
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
CLAMP(begin, 0, self->size);
- if (end < 0) end = self->size + end + 1;
+ if (end < 0) {
+ end = self->size + end + 1;
+ }
CLAMP(end, 0, self->size);
begin = MIN2(begin, end);
@@ -1465,8 +1512,9 @@ static int Vector_ass_slice(VectorObject *self, int begin, int end, PyObject *se
int size = 0;
float *vec = NULL;
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return -1;
+ }
CLAMP(begin, 0, self->size);
CLAMP(end, 0, self->size);
@@ -1489,8 +1537,9 @@ static int Vector_ass_slice(VectorObject *self, int begin, int end, PyObject *se
PyMem_Free(vec);
- if (BaseMath_WriteCallback(self) == -1)
+ if (BaseMath_WriteCallback(self) == -1) {
return -1;
+ }
return 0;
}
@@ -1512,8 +1561,9 @@ static PyObject *Vector_add(PyObject *v1, PyObject *v2)
vec1 = (VectorObject *)v1;
vec2 = (VectorObject *)v2;
- if (BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1)
+ if (BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1) {
return NULL;
+ }
/*VECTOR + VECTOR*/
if (vec1->size != vec2->size) {
@@ -1558,8 +1608,9 @@ static PyObject *Vector_iadd(PyObject *v1, PyObject *v2)
return NULL;
}
- if (BaseMath_ReadCallback_ForWrite(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1)
+ if (BaseMath_ReadCallback_ForWrite(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1) {
return NULL;
+ }
add_vn_vn(vec1->vec, vec2->vec, vec1->size);
@@ -1584,8 +1635,9 @@ static PyObject *Vector_sub(PyObject *v1, PyObject *v2)
vec1 = (VectorObject *)v1;
vec2 = (VectorObject *)v2;
- if (BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1)
+ if (BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1) {
return NULL;
+ }
if (vec1->size != vec2->size) {
PyErr_SetString(PyExc_AttributeError,
@@ -1629,8 +1681,9 @@ static PyObject *Vector_isub(PyObject *v1, PyObject *v2)
return NULL;
}
- if (BaseMath_ReadCallback_ForWrite(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1)
+ if (BaseMath_ReadCallback_ForWrite(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1) {
return NULL;
+ }
sub_vn_vn(vec1->vec, vec2->vec, vec1->size);
@@ -1722,13 +1775,15 @@ static PyObject *Vector_mul(PyObject *v1, PyObject *v2)
if (VectorObject_Check(v1)) {
vec1 = (VectorObject *)v1;
- if (BaseMath_ReadCallback(vec1) == -1)
+ if (BaseMath_ReadCallback(vec1) == -1) {
return NULL;
+ }
}
if (VectorObject_Check(v2)) {
vec2 = (VectorObject *)v2;
- if (BaseMath_ReadCallback(vec2) == -1)
+ if (BaseMath_ReadCallback(vec2) == -1) {
return NULL;
+ }
}
@@ -1774,17 +1829,20 @@ static PyObject *Vector_imul(PyObject *v1, PyObject *v2)
if (VectorObject_Check(v1)) {
vec1 = (VectorObject *)v1;
- if (BaseMath_ReadCallback(vec1) == -1)
+ if (BaseMath_ReadCallback(vec1) == -1) {
return NULL;
+ }
}
if (VectorObject_Check(v2)) {
vec2 = (VectorObject *)v2;
- if (BaseMath_ReadCallback(vec2) == -1)
+ if (BaseMath_ReadCallback(vec2) == -1) {
return NULL;
+ }
}
- if (BaseMath_ReadCallback_ForWrite(vec1) == -1)
+ if (BaseMath_ReadCallback_ForWrite(vec1) == -1) {
return NULL;
+ }
/* Intentionally don't support (Quaternion, Matrix) here, uses reverse order instead. */
@@ -1830,13 +1888,15 @@ static PyObject *Vector_matmul(PyObject *v1, PyObject *v2)
if (VectorObject_Check(v1)) {
vec1 = (VectorObject *)v1;
- if (BaseMath_ReadCallback(vec1) == -1)
+ if (BaseMath_ReadCallback(vec1) == -1) {
return NULL;
+ }
}
if (VectorObject_Check(v2)) {
vec2 = (VectorObject *)v2;
- if (BaseMath_ReadCallback(vec2) == -1)
+ if (BaseMath_ReadCallback(vec2) == -1) {
return NULL;
+ }
}
@@ -1859,8 +1919,9 @@ static PyObject *Vector_matmul(PyObject *v1, PyObject *v2)
/* VEC @ MATRIX */
float tvec[MAX_DIMENSIONS];
- if (BaseMath_ReadCallback((MatrixObject *)v2) == -1)
+ if (BaseMath_ReadCallback((MatrixObject *)v2) == -1) {
return NULL;
+ }
if (row_vector_multiplication(tvec, vec1, (MatrixObject *)v2) == -1) {
return NULL;
}
@@ -1906,8 +1967,9 @@ static PyObject *Vector_div(PyObject *v1, PyObject *v2)
}
vec1 = (VectorObject *)v1; /* vector */
- if (BaseMath_ReadCallback(vec1) == -1)
+ if (BaseMath_ReadCallback(vec1) == -1) {
return NULL;
+ }
if ((scalar = PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred()) { /* parsed item not a number */
PyErr_SetString(PyExc_TypeError,
@@ -1943,8 +2005,9 @@ static PyObject *Vector_idiv(PyObject *v1, PyObject *v2)
float scalar;
VectorObject *vec1 = (VectorObject *)v1;
- if (BaseMath_ReadCallback_ForWrite(vec1) == -1)
+ if (BaseMath_ReadCallback_ForWrite(vec1) == -1) {
return NULL;
+ }
if ((scalar = PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred()) { /* parsed item not a number */
PyErr_SetString(PyExc_TypeError,
@@ -1974,8 +2037,9 @@ static PyObject *Vector_neg(VectorObject *self)
{
float *tvec;
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
tvec = PyMem_Malloc(self->size * sizeof(float));
negate_vn_vn(tvec, self->vec, self->size);
@@ -2002,8 +2066,9 @@ static PyObject *Vector_richcmpr(PyObject *objectA, PyObject *objectB, int compa
vecA = (VectorObject *)objectA;
vecB = (VectorObject *)objectB;
- if (BaseMath_ReadCallback(vecA) == -1 || BaseMath_ReadCallback(vecB) == -1)
+ if (BaseMath_ReadCallback(vecA) == -1 || BaseMath_ReadCallback(vecB) == -1) {
return NULL;
+ }
if (vecA->size != vecB->size) {
if (comparison_type == Py_NE) {
@@ -2069,11 +2134,13 @@ static PyObject *Vector_richcmpr(PyObject *objectA, PyObject *objectB, int compa
static Py_hash_t Vector_hash(VectorObject *self)
{
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return -1;
+ }
- if (BaseMathObject_Prepare_ForHash(self) == -1)
+ if (BaseMathObject_Prepare_ForHash(self) == -1) {
return -1;
+ }
return mathutils_array_hash(self->vec, self->size);
}
@@ -2097,17 +2164,20 @@ static PyObject *Vector_subscript(VectorObject *self, PyObject *item)
if (PyIndex_Check(item)) {
Py_ssize_t i;
i = PyNumber_AsSsize_t(item, PyExc_IndexError);
- if (i == -1 && PyErr_Occurred())
+ if (i == -1 && PyErr_Occurred()) {
return NULL;
- if (i < 0)
+ }
+ if (i < 0) {
i += self->size;
+ }
return Vector_item(self, i);
}
else if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelength;
- if (PySlice_GetIndicesEx(item, self->size, &start, &stop, &step, &slicelength) < 0)
+ if (PySlice_GetIndicesEx(item, self->size, &start, &stop, &step, &slicelength) < 0) {
return NULL;
+ }
if (slicelength <= 0) {
return PyTuple_New(0);
@@ -2133,20 +2203,24 @@ static int Vector_ass_subscript(VectorObject *self, PyObject *item, PyObject *va
{
if (PyIndex_Check(item)) {
Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
- if (i == -1 && PyErr_Occurred())
+ if (i == -1 && PyErr_Occurred()) {
return -1;
- if (i < 0)
+ }
+ if (i < 0) {
i += self->size;
+ }
return Vector_ass_item(self, i, value);
}
else if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelength;
- if (PySlice_GetIndicesEx(item, self->size, &start, &stop, &step, &slicelength) < 0)
+ if (PySlice_GetIndicesEx(item, self->size, &start, &stop, &step, &slicelength) < 0) {
return -1;
+ }
- if (step == 1)
+ if (step == 1) {
return Vector_ass_slice(self, start, stop, value);
+ }
else {
PyErr_SetString(PyExc_IndexError,
"slice steps not supported with vectors");
@@ -2233,8 +2307,9 @@ PyDoc_STRVAR(Vector_length_doc,
);
static PyObject *Vector_length_get(VectorObject *self, void *UNUSED(closure))
{
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
return PyFloat_FromDouble(sqrt(dot_vn_vn(self->vec, self->vec, self->size)));
}
@@ -2243,8 +2318,9 @@ static int Vector_length_set(VectorObject *self, PyObject *value)
{
double dot = 0.0f, param;
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return -1;
+ }
if ((param = PyFloat_AsDouble(value)) == -1.0 && PyErr_Occurred()) {
PyErr_SetString(PyExc_TypeError,
@@ -2264,13 +2340,16 @@ static int Vector_length_set(VectorObject *self, PyObject *value)
dot = dot_vn_vn(self->vec, self->vec, self->size);
- if (!dot) /* cant sqrt zero */
+ if (!dot) {
+ /* cant sqrt zero */
return 0;
+ }
dot = sqrt(dot);
- if (dot == param)
+ if (dot == param) {
return 0;
+ }
dot = dot / param;
@@ -2287,8 +2366,9 @@ PyDoc_STRVAR(Vector_length_squared_doc,
);
static PyObject *Vector_length_squared_get(VectorObject *self, void *UNUSED(closure))
{
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
return PyFloat_FromDouble(dot_vn_vn(self->vec, self->vec, self->size));
}
@@ -2359,8 +2439,9 @@ static PyObject *Vector_swizzle_get(VectorObject *self, void *closure)
float vec[MAX_DIMENSIONS];
unsigned int swizzleClosure;
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
/* Unpack the axes from the closure into an array. */
axis_to = 0;
@@ -2406,8 +2487,9 @@ static int Vector_swizzle_set(VectorObject *self, PyObject *value, void *closure
float tvec[MAX_DIMENSIONS];
float vec_assign[MAX_DIMENSIONS];
- if (BaseMath_ReadCallback_ForWrite(self) == -1)
+ if (BaseMath_ReadCallback_ForWrite(self) == -1) {
return -1;
+ }
/* Check that the closure can be used with this vector: even 2D vectors have
* swizzles defined for axes z and w, but they would be invalid. */
@@ -2469,10 +2551,12 @@ static int Vector_swizzle_set(VectorObject *self, PyObject *value, void *closure
memcpy(self->vec, tvec, self->size * sizeof(float));
/* continue with BaseMathObject_WriteCallback at the end */
- if (BaseMath_WriteCallback(self) == -1)
+ if (BaseMath_WriteCallback(self) == -1) {
return -1;
- else
+ }
+ else {
return 0;
+ }
}
#define _SWIZZLE1(a) ((a) | SWIZZLE_VALID_AXIS)
@@ -2876,8 +2960,9 @@ static int row_vector_multiplication(float r_vec[MAX_DIMENSIONS], VectorObject *
}
}
- if (BaseMath_ReadCallback(vec) == -1 || BaseMath_ReadCallback(mat) == -1)
+ if (BaseMath_ReadCallback(vec) == -1 || BaseMath_ReadCallback(mat) == -1) {
return -1;
+ }
memcpy(vec_cpy, vec->vec, vec_size * sizeof(float));
@@ -2901,8 +2986,9 @@ PyDoc_STRVAR(Vector_negate_doc,
);
static PyObject *Vector_negate(VectorObject *self)
{
- if (BaseMath_ReadCallback(self) == -1)
+ if (BaseMath_ReadCallback(self) == -1) {
return NULL;
+ }
negate_vn(self->vec, self->size);
diff --git a/source/blender/python/mathutils/mathutils_bvhtree.c b/source/blender/python/mathutils/mathutils_bvhtree.c
index 4ed4b0e3abb..b99b39ac998 100644
--- a/source/blender/python/mathutils/mathutils_bvhtree.c
+++ b/source/blender/python/mathutils/mathutils_bvhtree.c
@@ -924,10 +924,12 @@ static PyObject *C_BVHTree_FromPolygons(PyObject *UNUSED(cls), PyObject *args, P
orig_index, orig_normal);
}
else {
- if (coords)
+ if (coords) {
MEM_freeN(coords);
- if (tris)
+ }
+ if (tris) {
MEM_freeN(tris);
+ }
return NULL;
}
diff --git a/source/blender/python/mathutils/mathutils_geometry.c b/source/blender/python/mathutils/mathutils_geometry.c
index 6106b01fd41..05ec57a004a 100644
--- a/source/blender/python/mathutils/mathutils_geometry.c
+++ b/source/blender/python/mathutils/mathutils_geometry.c
@@ -621,12 +621,12 @@ static PyObject *M_Geometry_intersect_line_sphere(PyObject *UNUSED(self), PyObje
switch (isect_line_sphere_v3(line_a, line_b, sphere_co, sphere_radius, isect_a, isect_b)) {
case 1:
- if (!(!clip || (((lambda = line_point_factor_v3(isect_a, line_a, line_b)) >= 0.0f) && (lambda <= 1.0f)))) use_a = false;
+ if (!(!clip || (((lambda = line_point_factor_v3(isect_a, line_a, line_b)) >= 0.0f) && (lambda <= 1.0f)))) { use_a = false; }
use_b = false;
break;
case 2:
- if (!(!clip || (((lambda = line_point_factor_v3(isect_a, line_a, line_b)) >= 0.0f) && (lambda <= 1.0f)))) use_a = false;
- if (!(!clip || (((lambda = line_point_factor_v3(isect_b, line_a, line_b)) >= 0.0f) && (lambda <= 1.0f)))) use_b = false;
+ if (!(!clip || (((lambda = line_point_factor_v3(isect_a, line_a, line_b)) >= 0.0f) && (lambda <= 1.0f)))) { use_a = false; }
+ if (!(!clip || (((lambda = line_point_factor_v3(isect_b, line_a, line_b)) >= 0.0f) && (lambda <= 1.0f)))) { use_b = false; }
break;
default:
use_a = false;
@@ -694,12 +694,12 @@ static PyObject *M_Geometry_intersect_line_sphere_2d(PyObject *UNUSED(self), PyO
switch (isect_line_sphere_v2(line_a, line_b, sphere_co, sphere_radius, isect_a, isect_b)) {
case 1:
- if (!(!clip || (((lambda = line_point_factor_v2(isect_a, line_a, line_b)) >= 0.0f) && (lambda <= 1.0f)))) use_a = false;
+ if (!(!clip || (((lambda = line_point_factor_v2(isect_a, line_a, line_b)) >= 0.0f) && (lambda <= 1.0f)))) { use_a = false; }
use_b = false;
break;
case 2:
- if (!(!clip || (((lambda = line_point_factor_v2(isect_a, line_a, line_b)) >= 0.0f) && (lambda <= 1.0f)))) use_a = false;
- if (!(!clip || (((lambda = line_point_factor_v2(isect_b, line_a, line_b)) >= 0.0f) && (lambda <= 1.0f)))) use_b = false;
+ if (!(!clip || (((lambda = line_point_factor_v2(isect_a, line_a, line_b)) >= 0.0f) && (lambda <= 1.0f)))) { use_a = false; }
+ if (!(!clip || (((lambda = line_point_factor_v2(isect_b, line_a, line_b)) >= 0.0f) && (lambda <= 1.0f)))) { use_b = false; }
break;
default:
use_a = false;
@@ -1225,15 +1225,19 @@ static PyObject *M_Geometry_tessellate_polygon(PyObject *UNUSED(self), PyObject
polyVec = PySequence_GetItem(polyLine, index);
if (VectorObject_Check(polyVec)) {
- if (BaseMath_ReadCallback((VectorObject *)polyVec) == -1)
+ if (BaseMath_ReadCallback((VectorObject *)polyVec) == -1) {
ls_error = 1;
+ }
fp[0] = ((VectorObject *)polyVec)->vec[0];
fp[1] = ((VectorObject *)polyVec)->vec[1];
- if (((VectorObject *)polyVec)->size > 2)
+ if (((VectorObject *)polyVec)->size > 2) {
fp[2] = ((VectorObject *)polyVec)->vec[2];
- else
- fp[2] = 0.0f; /* if its a 2d vector then set the z to be zero */
+ }
+ else {
+ /* if its a 2d vector then set the z to be zero */
+ fp[2] = 0.0f;
+ }
}
else {
ls_error = 1;
diff --git a/source/blender/python/mathutils/mathutils_interpolate.c b/source/blender/python/mathutils/mathutils_interpolate.c
index da2ed0ced7e..792f8b1f065 100644
--- a/source/blender/python/mathutils/mathutils_interpolate.c
+++ b/source/blender/python/mathutils/mathutils_interpolate.c
@@ -66,15 +66,19 @@ static PyObject *M_Interpolate_poly_3d_calc(PyObject *UNUSED(self), PyObject *ar
return NULL;
}
- if (BaseMath_ReadCallback((VectorObject *)point) == -1)
+ if (BaseMath_ReadCallback((VectorObject *)point) == -1) {
return NULL;
+ }
fp[0] = ((VectorObject *)point)->vec[0];
fp[1] = ((VectorObject *)point)->vec[1];
- if (((VectorObject *)point)->size > 2)
+ if (((VectorObject *)point)->size > 2) {
fp[2] = ((VectorObject *)point)->vec[2];
- else
- fp[2] = 0.0f; /* if its a 2d vector then set the z to be zero */
+ }
+ else {
+ /* if its a 2d vector then set the z to be zero */
+ fp[2] = 0.0f;
+ }
len = mathutils_array_parse_alloc_v(((float **)&vecs), 3, veclist, __func__);
if (len == -1) {
diff --git a/source/blender/python/mathutils/mathutils_kdtree.c b/source/blender/python/mathutils/mathutils_kdtree.c
index f9cc99551bb..7228ac41bd6 100644
--- a/source/blender/python/mathutils/mathutils_kdtree.c
+++ b/source/blender/python/mathutils/mathutils_kdtree.c
@@ -148,8 +148,9 @@ static PyObject *py_kdtree_insert(PyKDTree *self, PyObject *args, PyObject *kwar
return NULL;
}
- if (mathutils_array_parse(co, 3, 3, py_co, "insert: invalid 'co' arg") == -1)
+ if (mathutils_array_parse(co, 3, 3, py_co, "insert: invalid 'co' arg") == -1) {
return NULL;
+ }
if (index < 0) {
PyErr_SetString(PyExc_ValueError, "negative index given");
@@ -238,8 +239,9 @@ static PyObject *py_kdtree_find(PyKDTree *self, PyObject *args, PyObject *kwargs
return NULL;
}
- if (mathutils_array_parse(co, 3, 3, py_co, "find: invalid 'co' arg") == -1)
+ if (mathutils_array_parse(co, 3, 3, py_co, "find: invalid 'co' arg") == -1) {
return NULL;
+ }
if (self->count != self->count_balance) {
PyErr_SetString(PyExc_RuntimeError, "KDTree must be balanced before calling find()");
@@ -299,8 +301,9 @@ static PyObject *py_kdtree_find_n(PyKDTree *self, PyObject *args, PyObject *kwar
return NULL;
}
- if (mathutils_array_parse(co, 3, 3, py_co, "find_n: invalid 'co' arg") == -1)
+ if (mathutils_array_parse(co, 3, 3, py_co, "find_n: invalid 'co' arg") == -1) {
return NULL;
+ }
if (UINT_IS_NEG(n)) {
PyErr_SetString(PyExc_RuntimeError, "negative 'n' given");
@@ -357,8 +360,9 @@ static PyObject *py_kdtree_find_range(PyKDTree *self, PyObject *args, PyObject *
return NULL;
}
- if (mathutils_array_parse(co, 3, 3, py_co, "find_range: invalid 'co' arg") == -1)
+ if (mathutils_array_parse(co, 3, 3, py_co, "find_range: invalid 'co' arg") == -1) {
return NULL;
+ }
if (radius < 0.0f) {
PyErr_SetString(PyExc_RuntimeError, "negative radius given");
diff --git a/source/blender/python/mathutils/mathutils_noise.c b/source/blender/python/mathutils/mathutils_noise.c
index 364690c43eb..04cadb9b592 100644
--- a/source/blender/python/mathutils/mathutils_noise.c
+++ b/source/blender/python/mathutils/mathutils_noise.c
@@ -136,17 +136,20 @@ static void next_state(void)
/* if init_genrand() has not been called, */
/* a default initial seed is used */
- if (initf == 0)
+ if (initf == 0) {
init_genrand(5489UL);
+ }
left = N;
next = state;
- for (j = N - M + 1; --j; p++)
+ for (j = N - M + 1; --j; p++) {
*p = p[M] ^ TWIST(p[0], p[1]);
+ }
- for (j = M; --j; p++)
+ for (j = M; --j; p++) {
*p = p[M - N] ^ TWIST(p[0], p[1]);
+ }
*p = p[M - N] ^ TWIST(p[0], state[0]);
}
@@ -155,10 +158,12 @@ static void next_state(void)
static void setRndSeed(int seed)
{
- if (seed == 0)
+ if (seed == 0) {
init_genrand(time(NULL));
- else
+ }
+ else {
init_genrand(seed);
+ }
}
/* float number in range [0, 1) using the mersenne twister rng */
@@ -166,8 +171,9 @@ static float frand(void)
{
unsigned long y;
- if (--left == 0)
+ if (--left == 0) {
next_state();
+ }
y = *next++;
/* Tempering */
@@ -253,16 +259,18 @@ static float turb(
int i;
amp = 1.f;
out = (float)(2.0f * BLI_gNoise(1.f, x, y, z, 0, nb) - 1.0f);
- if (hard)
+ if (hard) {
out = fabsf(out);
+ }
for (i = 1; i < oct; i++) {
amp *= ampscale;
x *= freqscale;
y *= freqscale;
z *= freqscale;
t = (float)(amp * (2.0f * BLI_gNoise(1.f, x, y, z, 0, nb) - 1.0f));
- if (hard)
+ if (hard) {
t = fabsf(t);
+ }
out += t;
}
return out;
@@ -406,8 +414,9 @@ PyDoc_STRVAR(M_Noise_seed_set_doc,
static PyObject *M_Noise_seed_set(PyObject *UNUSED(self), PyObject *args)
{
int s;
- if (!PyArg_ParseTuple(args, "i:seed_set", &s))
+ if (!PyArg_ParseTuple(args, "i:seed_set", &s)) {
return NULL;
+ }
setRndSeed(s);
Py_RETURN_NONE;
}
@@ -447,8 +456,9 @@ static PyObject *M_Noise_noise(PyObject *UNUSED(self), PyObject *args, PyObject
return NULL;
}
- if (mathutils_array_parse(vec, 3, 3, value, "noise: invalid 'position' arg") == -1)
+ if (mathutils_array_parse(vec, 3, 3, value, "noise: invalid 'position' arg") == -1) {
return NULL;
+ }
return PyFloat_FromDouble((2.0f * BLI_gNoise(1.0f, vec[0], vec[1], vec[2], 0, noise_basis_enum) - 1.0f));
}
@@ -488,8 +498,9 @@ static PyObject *M_Noise_noise_vector(PyObject *UNUSED(self), PyObject *args, Py
return NULL;
}
- if (mathutils_array_parse(vec, 3, 3, value, "noise_vector: invalid 'position' arg") == -1)
+ if (mathutils_array_parse(vec, 3, 3, value, "noise_vector: invalid 'position' arg") == -1) {
return NULL;
+ }
noise_vector(vec[0], vec[1], vec[2], noise_basis_enum, r_vec);
@@ -540,8 +551,9 @@ static PyObject *M_Noise_turbulence(PyObject *UNUSED(self), PyObject *args, PyOb
return NULL;
}
- if (mathutils_array_parse(vec, 3, 3, value, "turbulence: invalid 'position' arg") == -1)
+ if (mathutils_array_parse(vec, 3, 3, value, "turbulence: invalid 'position' arg") == -1) {
return NULL;
+ }
return PyFloat_FromDouble(turb(vec[0], vec[1], vec[2], oct, hd, noise_basis_enum, as, fs));
}
@@ -590,8 +602,9 @@ static PyObject *M_Noise_turbulence_vector(PyObject *UNUSED(self), PyObject *arg
return NULL;
}
- if (mathutils_array_parse(vec, 3, 3, value, "turbulence_vector: invalid 'position' arg") == -1)
+ if (mathutils_array_parse(vec, 3, 3, value, "turbulence_vector: invalid 'position' arg") == -1) {
return NULL;
+ }
vTurb(vec[0], vec[1], vec[2], oct, hd, noise_basis_enum, as, fs, r_vec);
@@ -641,8 +654,9 @@ static PyObject *M_Noise_fractal(PyObject *UNUSED(self), PyObject *args, PyObjec
return NULL;
}
- if (mathutils_array_parse(vec, 3, 3, value, "fractal: invalid 'position' arg") == -1)
+ if (mathutils_array_parse(vec, 3, 3, value, "fractal: invalid 'position' arg") == -1) {
return NULL;
+ }
return PyFloat_FromDouble(mg_fBm(vec[0], vec[1], vec[2], H, lac, oct, noise_basis_enum));
}
@@ -689,8 +703,9 @@ static PyObject *M_Noise_multi_fractal(PyObject *UNUSED(self), PyObject *args, P
return NULL;
}
- if (mathutils_array_parse(vec, 3, 3, value, "multi_fractal: invalid 'position' arg") == -1)
+ if (mathutils_array_parse(vec, 3, 3, value, "multi_fractal: invalid 'position' arg") == -1) {
return NULL;
+ }
return PyFloat_FromDouble(mg_MultiFractal(vec[0], vec[1], vec[2], H, lac, oct, noise_basis_enum));
}
@@ -749,8 +764,9 @@ static PyObject *M_Noise_variable_lacunarity(PyObject *UNUSED(self), PyObject *a
return NULL;
}
- if (mathutils_array_parse(vec, 3, 3, value, "variable_lacunarity: invalid 'position' arg") == -1)
+ if (mathutils_array_parse(vec, 3, 3, value, "variable_lacunarity: invalid 'position' arg") == -1) {
return NULL;
+ }
return PyFloat_FromDouble(mg_VLNoise(vec[0], vec[1], vec[2], d, noise_type1_enum, noise_type2_enum));
}
@@ -799,8 +815,9 @@ static PyObject *M_Noise_hetero_terrain(PyObject *UNUSED(self), PyObject *args,
return NULL;
}
- if (mathutils_array_parse(vec, 3, 3, value, "hetero_terrain: invalid 'position' arg") == -1)
+ if (mathutils_array_parse(vec, 3, 3, value, "hetero_terrain: invalid 'position' arg") == -1) {
return NULL;
+ }
return PyFloat_FromDouble(mg_HeteroTerrain(vec[0], vec[1], vec[2], H, lac, oct, ofs, noise_basis_enum));
}
@@ -851,8 +868,9 @@ static PyObject *M_Noise_hybrid_multi_fractal(PyObject *UNUSED(self), PyObject *
return NULL;
}
- if (mathutils_array_parse(vec, 3, 3, value, "hybrid_multi_fractal: invalid 'position' arg") == -1)
+ if (mathutils_array_parse(vec, 3, 3, value, "hybrid_multi_fractal: invalid 'position' arg") == -1) {
return NULL;
+ }
return PyFloat_FromDouble(mg_HybridMultiFractal(vec[0], vec[1], vec[2], H, lac, oct, ofs, gn, noise_basis_enum));
}
@@ -903,8 +921,9 @@ static PyObject *M_Noise_ridged_multi_fractal(PyObject *UNUSED(self), PyObject *
return NULL;
}
- if (mathutils_array_parse(vec, 3, 3, value, "ridged_multi_fractal: invalid 'position' arg") == -1)
+ if (mathutils_array_parse(vec, 3, 3, value, "ridged_multi_fractal: invalid 'position' arg") == -1) {
return NULL;
+ }
return PyFloat_FromDouble(mg_RidgedMultiFractal(vec[0], vec[1], vec[2], H, lac, oct, ofs, gn, noise_basis_enum));
}
@@ -952,8 +971,9 @@ static PyObject *M_Noise_voronoi(PyObject *UNUSED(self), PyObject *args, PyObjec
return NULL;
}
- if (mathutils_array_parse(vec, 3, 3, value, "voronoi: invalid 'position' arg") == -1)
+ if (mathutils_array_parse(vec, 3, 3, value, "voronoi: invalid 'position' arg") == -1) {
return NULL;
+ }
list = PyList_New(4);
@@ -984,11 +1004,13 @@ static PyObject *M_Noise_cell(PyObject *UNUSED(self), PyObject *args)
PyObject *value;
float vec[3];
- if (!PyArg_ParseTuple(args, "O:cell", &value))
+ if (!PyArg_ParseTuple(args, "O:cell", &value)) {
return NULL;
+ }
- if (mathutils_array_parse(vec, 3, 3, value, "cell: invalid 'position' arg") == -1)
+ if (mathutils_array_parse(vec, 3, 3, value, "cell: invalid 'position' arg") == -1) {
return NULL;
+ }
return PyFloat_FromDouble(cellNoise(vec[0], vec[1], vec[2]));
}
@@ -1008,11 +1030,13 @@ static PyObject *M_Noise_cell_vector(PyObject *UNUSED(self), PyObject *args)
PyObject *value;
float vec[3], r_vec[3];
- if (!PyArg_ParseTuple(args, "O:cell_vector", &value))
+ if (!PyArg_ParseTuple(args, "O:cell_vector", &value)) {
return NULL;
+ }
- if (mathutils_array_parse(vec, 3, 3, value, "cell_vector: invalid 'position' arg") == -1)
+ if (mathutils_array_parse(vec, 3, 3, value, "cell_vector: invalid 'position' arg") == -1) {
return NULL;
+ }
cellNoiseV(vec[0], vec[1], vec[2], r_vec);
return Vector_CreatePyObject(r_vec, 3, NULL);