[Bf-blender-cvs] [e182d43] master: cleanup: avoid ref-counting None for a new matrix

Campbell Barton noreply at git.blender.org
Sun Dec 28 05:15:52 CET 2014


Commit: e182d43d3e695a5086e8167b1ed4fc04ef43dbec
Author: Campbell Barton
Date:   Sun Dec 28 15:13:01 2014 +1100
Branches: master
https://developer.blender.org/rBe182d43d3e695a5086e8167b1ed4fc04ef43dbec

cleanup: avoid ref-counting None for a new matrix

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

M	source/blender/python/mathutils/mathutils_Matrix.c

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

diff --git a/source/blender/python/mathutils/mathutils_Matrix.c b/source/blender/python/mathutils/mathutils_Matrix.c
index b773d60..23e8305 100644
--- a/source/blender/python/mathutils/mathutils_Matrix.c
+++ b/source/blender/python/mathutils/mathutils_Matrix.c
@@ -1846,8 +1846,24 @@ static PyObject *Matrix_zero(MatrixObject *self)
 		return NULL;
 
 	Py_RETURN_NONE;
+
 }
 /*---------------------------matrix.identity(() ------------------*/
+static void matrix_identity_internal(MatrixObject *self)
+{
+	BLI_assert((self->num_col == self->num_row) && (self->num_row <= 4));
+
+	if (self->num_col == 2) {
+		unit_m2((float (*)[2])self->matrix);
+	}
+	else if (self->num_col == 3) {
+		unit_m3((float (*)[3])self->matrix);
+	}
+	else {
+		unit_m4((float (*)[4])self->matrix);
+	}
+}
+
 PyDoc_STRVAR(Matrix_identity_doc,
 ".. method:: identity()\n"
 "\n"
@@ -1870,15 +1886,7 @@ static PyObject *Matrix_identity(MatrixObject *self)
 		return NULL;
 	}
 
-	if (self->num_col == 2) {
-		unit_m2((float (*)[2])self->matrix);
-	}
-	else if (self->num_col == 3) {
-		unit_m3((float (*)[3])self->matrix);
-	}
-	else {
-		unit_m4((float (*)[4])self->matrix);
-	}
+	matrix_identity_internal(self);
 
 	if (BaseMath_WriteCallback(self) == -1)
 		return NULL;
@@ -2808,8 +2816,7 @@ PyObject *Matrix_CreatePyObject(float *mat,
 			}
 			else if (num_col == num_row) {
 				/* or if no arguments are passed return identity matrix for square matrices */
-				PyObject *ret_dummy = Matrix_identity(self);
-				Py_DECREF(ret_dummy);
+				matrix_identity_internal(self);
 			}
 			else {
 				/* otherwise zero everything */




More information about the Bf-blender-cvs mailing list