[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11082] branches/pyapi_devel/source/ blender/python/api2_2x: fixed some bugs with vector ID user checking

Campbell Barton cbarton at metavr.com
Wed Jun 27 01:06:43 CEST 2007


Revision: 11082
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11082
Author:   campbellbarton
Date:     2007-06-27 01:06:43 +0200 (Wed, 27 Jun 2007)

Log Message:
-----------
fixed some bugs with vector ID user checking
removed 2 pointers from the python Matrix struct and made 3 ints into chars since they are only ever used to store values between 2 and 4

Modified Paths:
--------------
    branches/pyapi_devel/source/blender/python/api2_2x/matrix.c
    branches/pyapi_devel/source/blender/python/api2_2x/matrix.h
    branches/pyapi_devel/source/blender/python/api2_2x/vector.c

Modified: branches/pyapi_devel/source/blender/python/api2_2x/matrix.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/matrix.c	2007-06-26 20:00:36 UTC (rev 11081)
+++ branches/pyapi_devel/source/blender/python/api2_2x/matrix.c	2007-06-26 23:06:43 UTC (rev 11082)
@@ -114,17 +114,16 @@
 {
 	int x, first_row_elem, curr_pos, new_pos, blank_columns, blank_rows, index;
 
-	if(self->data.blend_data){
+	if(self->wrapped == Py_WRAP){
 		return EXPP_ReturnPyObjError(PyExc_TypeError,
 			"cannot resize wrapped data - only python matrices\n");
 	}
 
-	self->data.py_data = PyMem_Realloc(self->data.py_data, (sizeof(float) * 16));
-	if(self->data.py_data == NULL) {
+	self->contigPtr = PyMem_Realloc(self->contigPtr, (sizeof(float) * 16));
+	if(self->contigPtr == NULL) {
 		return EXPP_ReturnPyObjError(PyExc_MemoryError,
 			"matrix.resize4x4(): problem allocating pointer space\n\n");
 	}
-	self->contigPtr = self->data.py_data;  /*force*/
 	self->matrix = PyMem_Realloc(self->matrix, (sizeof(float *) * 4));
 	if(self->matrix == NULL) {
 		return EXPP_ReturnPyObjError(PyExc_MemoryError,
@@ -364,8 +363,8 @@
 	Py_XDECREF(self->coerced_object);
 	PyMem_Free(self->matrix);
 	/*only free py_data*/
-	if(self->data.py_data){
-		PyMem_Free(self->data.py_data);
+	if(self->wrapped == Py_WRAP){
+		PyMem_Free(self->contigPtr);
 	}
 	PyObject_DEL(self);
 }
@@ -487,7 +486,7 @@
 		return EXPP_ReturnPyObjError(PyExc_IndexError,
 		"matrix[attribute]: array index out of range\n");
 
-	return newVectorObject(self->matrix[i], self->colSize, Py_WRAP, (BPy_GenericLib *)NULL);
+	return newVectorObject(self->matrix[i], self->colSize, Py_WRAP, (BPy_GenericLib *)self);
 }
 /*----------------------------object[]-------------------------
   sequence accessor (set)*/
@@ -908,15 +907,15 @@
 	}
 
 	self = PyObject_NEW(MatrixObject, &matrix_Type);
-	self->data.blend_data = NULL;
-	self->data.py_data = NULL;
+	
+	
 	self->rowSize = rowSize;
 	self->colSize = colSize;
 	self->coerced_object = NULL;
 
 	if(type == Py_WRAP){
-		self->data.blend_data = mat;
-		self->contigPtr = self->data.blend_data;
+
+		self->contigPtr = mat;
 		/*create pointer array*/
 		self->matrix = PyMem_Malloc(rowSize * sizeof(float *));
 		if(self->matrix == NULL) { /*allocation failure*/
@@ -929,16 +928,16 @@
 		}
 		self->wrapped = Py_WRAP;
 	}else if (type == Py_NEW){
-		self->data.py_data = PyMem_Malloc(rowSize * colSize * sizeof(float));
-		if(self->data.py_data == NULL) { /*allocation failure*/
+		self->contigPtr = PyMem_Malloc(rowSize * colSize * sizeof(float));
+		if(self->contigPtr == NULL) { /*allocation failure*/
 			return EXPP_ReturnPyObjError( PyExc_MemoryError,
 				"matrix(): problem allocating pointer space\n");
 		}
-		self->contigPtr = self->data.py_data;
+		
 		/*create pointer array*/
 		self->matrix = PyMem_Malloc(rowSize * sizeof(float *));
 		if(self->matrix == NULL) { /*allocation failure*/
-			PyMem_Free(self->data.py_data);
+			PyMem_Free(self->contigPtr);
 			return EXPP_ReturnPyObjError( PyExc_MemoryError,
 				"matrix(): problem allocating pointer space\n");
 		}

Modified: branches/pyapi_devel/source/blender/python/api2_2x/matrix.h
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/matrix.h	2007-06-26 20:00:36 UTC (rev 11081)
+++ branches/pyapi_devel/source/blender/python/api2_2x/matrix.h	2007-06-26 23:06:43 UTC (rev 11082)
@@ -42,15 +42,11 @@
 typedef float **ptRow;
 typedef struct _Matrix {
 	PyObject_VAR_HEAD 
-	struct{
-		float *py_data;		/*python managed*/
-		float *blend_data;	/*blender managed*/
-	}data;
 	ptRow matrix;			/*ptr to the contigPtr (accessor)*/
 	float *contigPtr;		/*1D array of data (alias)*/
-	int rowSize;
-	int colSize;
-	int wrapped;			/*is wrapped data?*/
+	char rowSize;
+	char colSize;
+	char wrapped;			/*is wrapped data?*/
 	PyObject *coerced_object;
 } MatrixObject;
 /*coerced_object is a pointer to the object that it was

Modified: branches/pyapi_devel/source/blender/python/api2_2x/vector.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/vector.c	2007-06-26 20:00:36 UTC (rev 11081)
+++ branches/pyapi_devel/source/blender/python/api2_2x/vector.c	2007-06-26 23:06:43 UTC (rev 11082)
@@ -1305,6 +1305,8 @@
 		if (genlib) {
 			Py_INCREF(genlib);
 			self->genlib = genlib;
+		} else {
+			self->genlib = NULL;
 		}
 	} else if (type == Py_NEW) {
 		self->vec = PyMem_Malloc(size * sizeof(float));
@@ -1320,6 +1322,7 @@
 			}
 		}
 		self->wrapped = Py_NEW;
+		self->genlib = NULL;
 	}else{ /*bad type*/
 		return NULL;
 	}
@@ -1335,6 +1338,7 @@
 		}
 	}
 	/* TODO - check for and impliment null matrix */
+	return 1;
 }
 
 /* make this vector use its own memory */





More information about the Bf-blender-cvs mailing list