[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [42857] trunk/blender/source/blender/ python/mathutils: fix for error with matrix access and negative indices with recent row/ col swap.

Campbell Barton ideasman42 at gmail.com
Sat Dec 24 07:14:09 CET 2011


Revision: 42857
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42857
Author:   campbellbarton
Date:     2011-12-24 06:13:58 +0000 (Sat, 24 Dec 2011)
Log Message:
-----------
fix for error with matrix access and negative indices with recent row/col swap.

Modified Paths:
--------------
    trunk/blender/source/blender/python/mathutils/mathutils.c
    trunk/blender/source/blender/python/mathutils/mathutils_Matrix.c
    trunk/blender/source/blender/python/mathutils/mathutils_Matrix.h

Modified: trunk/blender/source/blender/python/mathutils/mathutils.c
===================================================================
--- trunk/blender/source/blender/python/mathutils/mathutils.c	2011-12-24 04:58:01 UTC (rev 42856)
+++ trunk/blender/source/blender/python/mathutils/mathutils.c	2011-12-24 06:13:58 UTC (rev 42857)
@@ -455,8 +455,8 @@
 	PyDict_SetItemString(sys_modules, "mathutils.noise", item);
 	Py_INCREF(item);
 
-	mathutils_matrix_vector_cb_index= Mathutils_RegisterCallback(&mathutils_matrix_vector_cb);
-	mathutils_matrix_column_cb_index= Mathutils_RegisterCallback(&mathutils_matrix_column_cb);
+	mathutils_matrix_row_cb_index= Mathutils_RegisterCallback(&mathutils_matrix_row_cb);
+	mathutils_matrix_col_cb_index= Mathutils_RegisterCallback(&mathutils_matrix_col_cb);
 
 	return submodule;
 }

Modified: trunk/blender/source/blender/python/mathutils/mathutils_Matrix.c
===================================================================
--- trunk/blender/source/blender/python/mathutils/mathutils_Matrix.c	2011-12-24 04:58:01 UTC (rev 42856)
+++ trunk/blender/source/blender/python/mathutils/mathutils_Matrix.c	2011-12-24 06:13:58 UTC (rev 42857)
@@ -43,7 +43,7 @@
 static PyObject *matrix__apply_to_copy(PyNoArgsFunction matrix_func, MatrixObject *self);
 
 /* matrix row callbacks */
-int mathutils_matrix_vector_cb_index= -1;
+int mathutils_matrix_row_cb_index= -1;
 
 static int mathutils_matrix_vector_check(BaseMathObject *bmo)
 {
@@ -106,7 +106,7 @@
 	return 0;
 }
 
-Mathutils_Callback mathutils_matrix_vector_cb = {
+Mathutils_Callback mathutils_matrix_row_cb = {
 	mathutils_matrix_vector_check,
 	mathutils_matrix_vector_get,
 	mathutils_matrix_vector_set,
@@ -116,7 +116,7 @@
 /* matrix vector callbacks, this is so you can do matrix[i][j] = val  */
 
 /* matrix row callbacks */
-int mathutils_matrix_column_cb_index= -1;
+int mathutils_matrix_col_cb_index= -1;
 
 static int mathutils_matrix_column_check(BaseMathObject *bmo)
 {
@@ -187,7 +187,7 @@
 	return 0;
 }
 
-Mathutils_Callback mathutils_matrix_column_cb = {
+Mathutils_Callback mathutils_matrix_col_cb = {
 	mathutils_matrix_column_check,
 	mathutils_matrix_column_get,
 	mathutils_matrix_column_set,
@@ -1483,7 +1483,7 @@
 		                "array index out of range");
 		return NULL;
 	}
-	return Vector_CreatePyObject_cb((PyObject *)self, self->num_col, mathutils_matrix_vector_cb_index, row);
+	return Vector_CreatePyObject_cb((PyObject *)self, self->num_col, mathutils_matrix_row_cb_index, row);
 }
 /*----------------------------object[]-------------------------
   sequence accessor (set) */
@@ -1532,7 +1532,7 @@
 	tuple= PyTuple_New(end - begin);
 	for (count= begin; count < end; count++) {
 		PyTuple_SET_ITEM(tuple, count - begin,
-				Vector_CreatePyObject_cb((PyObject *)self, self->num_col, mathutils_matrix_vector_cb_index, count));
+				Vector_CreatePyObject_cb((PyObject *)self, self->num_col, mathutils_matrix_row_cb_index, count));
 
 	}
 
@@ -1786,13 +1786,13 @@
 		if (i == -1 && PyErr_Occurred())
 			return NULL;
 		if (i < 0)
-			i += self->num_col;
+			i += self->num_row;
 		return Matrix_item(self, i);
 	}
 	else if (PySlice_Check(item)) {
 		Py_ssize_t start, stop, step, slicelength;
 
-		if (PySlice_GetIndicesEx((void *)item, self->num_col, &start, &stop, &step, &slicelength) < 0)
+		if (PySlice_GetIndicesEx((void *)item, self->num_row, &start, &stop, &step, &slicelength) < 0)
 			return NULL;
 
 		if (slicelength <= 0) {
@@ -1822,13 +1822,13 @@
 		if (i == -1 && PyErr_Occurred())
 			return -1;
 		if (i < 0)
-			i += self->num_col;
+			i += self->num_row;
 		return Matrix_ass_item(self, i, value);
 	}
 	else if (PySlice_Check(item)) {
 		Py_ssize_t start, stop, step, slicelength;
 
-		if (PySlice_GetIndicesEx((void *)item, self->num_col, &start, &stop, &step, &slicelength) < 0)
+		if (PySlice_GetIndicesEx((void *)item, self->num_row, &start, &stop, &step, &slicelength) < 0)
 			return -1;
 
 		if (step == 1)
@@ -1916,7 +1916,7 @@
 		return NULL;
 	}
 
-	ret = (PyObject *)Vector_CreatePyObject_cb((PyObject *)self, 3, mathutils_matrix_column_cb_index, 3);
+	ret = (PyObject *)Vector_CreatePyObject_cb((PyObject *)self, 3, mathutils_matrix_col_cb_index, 3);
 
 	return ret;
 }

Modified: trunk/blender/source/blender/python/mathutils/mathutils_Matrix.h
===================================================================
--- trunk/blender/source/blender/python/mathutils/mathutils_Matrix.h	2011-12-24 04:58:01 UTC (rev 42856)
+++ trunk/blender/source/blender/python/mathutils/mathutils_Matrix.h	2011-12-24 06:13:58 UTC (rev 42857)
@@ -72,10 +72,10 @@
                                    const unsigned short num_col, const unsigned short num_row,
                                    int cb_type, int cb_subtype);
 
-extern int mathutils_matrix_vector_cb_index;
-extern int mathutils_matrix_column_cb_index;
-extern struct Mathutils_Callback mathutils_matrix_vector_cb;
-extern struct Mathutils_Callback mathutils_matrix_column_cb;
+extern int mathutils_matrix_row_cb_index; /* default */
+extern int mathutils_matrix_col_cb_index;
+extern struct Mathutils_Callback mathutils_matrix_row_cb; /* default */
+extern struct Mathutils_Callback mathutils_matrix_col_cb;
 
 void matrix_as_3x3(float mat[3][3], MatrixObject *self);
 




More information about the Bf-blender-cvs mailing list