[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34033] trunk/blender/source/blender/ python: fix for own error with mathutils.geometry argument parsing.

Campbell Barton ideasman42 at gmail.com
Mon Jan 3 13:11:05 CET 2011


Revision: 34033
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=34033
Author:   campbellbarton
Date:     2011-01-03 13:11:05 +0100 (Mon, 03 Jan 2011)

Log Message:
-----------
fix for own error with mathutils.geometry argument parsing.
also raise ValueError when the vector size is incorrect rather then type error.

Modified Paths:
--------------
    trunk/blender/source/blender/python/generic/mathutils_geometry.c
    trunk/blender/source/blender/python/intern/bpy_driver.c

Modified: trunk/blender/source/blender/python/generic/mathutils_geometry.c
===================================================================
--- trunk/blender/source/blender/python/generic/mathutils_geometry.c	2011-01-03 11:58:19 UTC (rev 34032)
+++ trunk/blender/source/blender/python/generic/mathutils_geometry.c	2011-01-03 12:11:05 UTC (rev 34033)
@@ -75,11 +75,11 @@
 	float det, inv_det, u, v, t;
 	int clip= 1;
 
-	if(!PyArg_ParseTuple(args, "intersect_ray_tri:O!O!O!O!O!|i", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3, &vector_Type, &ray, &vector_Type, &ray_off , &clip)) {
+	if(!PyArg_ParseTuple(args, "O!O!O!O!O!|i:intersect_ray_tri", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3, &vector_Type, &ray, &vector_Type, &ray_off , &clip)) {
 		return NULL;
 	}
 	if(vec1->size != 3 || vec2->size != 3 || vec3->size != 3 || ray->size != 3 || ray_off->size != 3) {
-		PyErr_SetString(PyExc_TypeError, "only 3D vectors for all parameters");
+		PyErr_SetString(PyExc_ValueError, "only 3D vectors for all parameters");
 		return NULL;
 	}
 
@@ -162,11 +162,11 @@
 	VectorObject *vec1, *vec2, *vec3, *vec4;
 	float v1[3], v2[3], v3[3], v4[3], i1[3], i2[3];
 
-	if(!PyArg_ParseTuple(args, "intersect_line_line:O!O!O!O!", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3, &vector_Type, &vec4)) {
+	if(!PyArg_ParseTuple(args, "O!O!O!O!:intersect_line_line", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3, &vector_Type, &vec4)) {
 		return NULL;
 	}
 	if(vec1->size != vec2->size || vec1->size != vec3->size || vec3->size != vec2->size) {
-		PyErr_SetString(PyExc_TypeError,"vectors must be of the same size");
+		PyErr_SetString(PyExc_ValueError,"vectors must be of the same size");
 		return NULL;
 	}
 
@@ -214,7 +214,7 @@
 		}
 	}
 	else {
-		PyErr_SetString(PyExc_TypeError, "2D/3D vectors only");
+		PyErr_SetString(PyExc_ValueError, "2D/3D vectors only");
 		return NULL;
 	}
 }
@@ -244,15 +244,15 @@
 	float n[3];
 
 	if(PyTuple_GET_SIZE(args) == 3) {
-		if(!PyArg_ParseTuple(args, "normal:O!O!O!", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3)) {
+		if(!PyArg_ParseTuple(args, "O!O!O!:normal", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3)) {
 			return NULL;
 		}
 		if(vec1->size != vec2->size || vec1->size != vec3->size) {
-			PyErr_SetString(PyExc_TypeError, "vectors must be of the same size");
+			PyErr_SetString(PyExc_ValueError, "vectors must be of the same size");
 			return NULL;
 		}
 		if(vec1->size < 3) {
-			PyErr_SetString(PyExc_TypeError, "2D vectors unsupported");
+			PyErr_SetString(PyExc_ValueError, "2D vectors unsupported");
 			return NULL;
 		}
 
@@ -262,15 +262,15 @@
 		normal_tri_v3(n, vec1->vec, vec2->vec, vec3->vec);
 	}
 	else {
-		if(!PyArg_ParseTuple(args, "normal:O!O!O!O!", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3, &vector_Type, &vec4)) {
+		if(!PyArg_ParseTuple(args, "O!O!O!O!:normal", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3, &vector_Type, &vec4)) {
 			return NULL;
 		}
 		if(vec1->size != vec2->size || vec1->size != vec3->size || vec1->size != vec4->size) {
-			PyErr_SetString(PyExc_TypeError,"vectors must be of the same size");
+			PyErr_SetString(PyExc_ValueError,"vectors must be of the same size");
 			return NULL;
 		}
 		if(vec1->size < 3) {
-			PyErr_SetString(PyExc_TypeError, "2D vectors unsupported");
+			PyErr_SetString(PyExc_ValueError, "2D vectors unsupported");
 			return NULL;
 		}
 
@@ -302,12 +302,12 @@
 {
 	VectorObject *vec1, *vec2, *vec3;
 
-	if(!PyArg_ParseTuple(args, "area_tri:O!O!O!", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3)) {
+	if(!PyArg_ParseTuple(args, "O!O!O!:area_tri", &vector_Type, &vec1, &vector_Type, &vec2, &vector_Type, &vec3)) {
 		return NULL;
 	}
 
 	if(vec1->size != vec2->size || vec1->size != vec3->size) {
-		PyErr_SetString(PyExc_TypeError, "vectors must be of the same size");
+		PyErr_SetString(PyExc_ValueError, "vectors must be of the same size");
 		return NULL;
 	}
 
@@ -321,7 +321,7 @@
 		return PyFloat_FromDouble(area_tri_v2(vec1->vec, vec2->vec, vec3->vec));
 	}
 	else {
-		PyErr_SetString(PyExc_TypeError, "only 2D,3D vectors are supported");
+		PyErr_SetString(PyExc_ValueError, "only 2D,3D vectors are supported");
 		return NULL;
 	}
 }
@@ -466,7 +466,7 @@
 {
 	VectorObject *line_a1, *line_a2, *line_b1, *line_b2;
 	float vi[2];
-	if(!PyArg_ParseTuple (args, "intersect_line_line_2d:O!O!O!O!",
+	if(!PyArg_ParseTuple(args, "O!O!O!O!:intersect_line_line_2d",
 	  &vector_Type, &line_a1,
 	  &vector_Type, &line_a2,
 	  &vector_Type, &line_b1,
@@ -506,7 +506,7 @@
 	float lambda;
 	PyObject *ret;
 	
-	if(!PyArg_ParseTuple (args, "intersect_point_line:O!O!O!",
+	if(!PyArg_ParseTuple(args, "O!O!O!:intersect_point_line",
 		&vector_Type, &pt,
 		&vector_Type, &line_1,
 		&vector_Type, &line_2)
@@ -555,7 +555,7 @@
 {
 	VectorObject *pt_vec, *tri_p1, *tri_p2, *tri_p3;
 	
-	if(!PyArg_ParseTuple (args, "intersect_point_tri_2d:O!O!O!O!",
+	if(!PyArg_ParseTuple(args, "O!O!O!O!:intersect_point_tri_2d",
 		  &vector_Type, &pt_vec,
 		  &vector_Type, &tri_p1,
 		  &vector_Type, &tri_p2,
@@ -591,7 +591,7 @@
 {
 	VectorObject *pt_vec, *quad_p1, *quad_p2, *quad_p3, *quad_p4;
 	
-	if(!PyArg_ParseTuple (args, "intersect_point_quad_2d:O!O!O!O!O!",
+	if(!PyArg_ParseTuple(args, "O!O!O!O!O!:intersect_point_quad_2d",
 		  &vector_Type, &pt_vec,
 		  &vector_Type, &quad_p1,
 		  &vector_Type, &quad_p2,
@@ -616,7 +616,7 @@
 	
 	/* Error checking must already be done */
 	if(!PyList_Check(value)) {
-		PyErr_SetString(PyExc_TypeError, "can only back a list of [x,y,x,w]");
+		PyErr_SetString(PyExc_TypeError, "can only back a list of [x, y, w, h]");
 		return -1;
 	}
 	
@@ -629,7 +629,7 @@
 		list_item= PyList_GET_ITEM(value, i);
 		if(!PyList_Check(list_item) || PyList_Size(list_item) < 4) {
 			MEM_freeN(*boxarray);
-			PyErr_SetString(PyExc_TypeError, "can only back a list of [x,y,x,w]");
+			PyErr_SetString(PyExc_TypeError, "can only pack a list of [x, y, w, h]");
 			return -1;
 		}
 		
@@ -638,15 +638,16 @@
 		item_1= PyList_GET_ITEM(list_item, 2);
 		item_2= PyList_GET_ITEM(list_item, 3);
 		
-		if (!PyNumber_Check(item_1) || !PyNumber_Check(item_2)) {
+		box->w=  (float)PyFloat_AsDouble(item_1);
+		box->h=  (float)PyFloat_AsDouble(item_2);
+		box->index= i;
+
+		if (box->w < 0.0f || box->h < 0.0f) {
 			MEM_freeN(*boxarray);
-			PyErr_SetString(PyExc_TypeError, "can only back a list of 2d boxes [x,y,x,w]");
+			PyErr_SetString(PyExc_TypeError, "error parsing width and height values from list: [x, y, w, h], not numbers or below zero");
 			return -1;
 		}
-		
-		box->w=  (float)PyFloat_AsDouble(item_1);
-		box->h=  (float)PyFloat_AsDouble(item_2);
-		box->index= i;
+
 		/* verts will be added later */
 	}
 	return 0;
@@ -743,19 +744,23 @@
 	float h2[4]= {0.0, 0.0, 0.0, 0.0};
 	
 	
-	if(!PyArg_ParseTuple (args, "O!O!O!O!i",
+	if(!PyArg_ParseTuple(args, "O!O!O!O!i:interpolate_bezier",
 	  &vector_Type, &vec_k1,
 	  &vector_Type, &vec_h1,
 	  &vector_Type, &vec_h2,
-	  &vector_Type, &vec_k2, &resolu) || (resolu<=1)
+	  &vector_Type, &vec_k2, &resolu)
 	) {
-		PyErr_SetString(PyExc_TypeError, "expected 4 vector types and an int greater then 1");
 		return NULL;
 	}
-	
+
+	if(resolu <= 1) {
+		PyErr_SetString(PyExc_ValueError, "resolution must be 2 or over");
+		return NULL;
+	}
+
 	if(!BaseMath_ReadCallback(vec_k1) || !BaseMath_ReadCallback(vec_h1) || !BaseMath_ReadCallback(vec_k2) || !BaseMath_ReadCallback(vec_h2))
 		return NULL;
-	
+
 	dims= MAX4(vec_k1->size, vec_h1->size, vec_h2->size, vec_k2->size);
 	
 	for(i=0; i < vec_k1->size; i++) k1[i]= vec_k1->vec[i];
@@ -806,25 +811,30 @@
 	VectorObject *vec_t1_src, *vec_t2_src, *vec_t3_src;
 	float vec[3];
 
-	if(!PyArg_ParseTuple (args, "O!O!O!O!O!O!O!",
+	if(!PyArg_ParseTuple(args, "O!O!O!O!O!O!O!:barycentric_transform",
 		  &vector_Type, &vec_pt,
 		  &vector_Type, &vec_t1_src,
 		  &vector_Type, &vec_t2_src,
 		  &vector_Type, &vec_t3_src,
 		  &vector_Type, &vec_t1_tar,
 		  &vector_Type, &vec_t2_tar,
-		  &vector_Type, &vec_t3_tar) ||(vec_pt->size != 3 ||
-										vec_t1_src->size != 3 ||
-										vec_t2_src->size != 3 ||
-										vec_t3_src->size != 3 ||
-										vec_t1_tar->size != 3 ||
-										vec_t2_tar->size != 3 ||
-										vec_t3_tar->size != 3)
+		  &vector_Type, &vec_t3_tar)
 	) {
-		PyErr_SetString(PyExc_TypeError, "expected 7, 3D vector types");
 		return NULL;
 	}
 
+	if(	vec_pt->size != 3 ||
+		vec_t1_src->size != 3 ||
+		vec_t2_src->size != 3 ||
+		vec_t3_src->size != 3 ||
+		vec_t1_tar->size != 3 ||
+		vec_t2_tar->size != 3 ||
+		vec_t3_tar->size != 3)
+	 {
+		 PyErr_SetString(PyExc_ValueError, "One of more of the vector arguments wasnt a 3D vector");
+		 return NULL;
+	 }
+
 	barycentric_transform(vec, vec_pt->vec,
 			vec_t1_tar->vec, vec_t2_tar->vec, vec_t3_tar->vec,
 			vec_t1_src->vec, vec_t2_src->vec, vec_t3_src->vec);

Modified: trunk/blender/source/blender/python/intern/bpy_driver.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_driver.c	2011-01-03 11:58:19 UTC (rev 34032)
+++ trunk/blender/source/blender/python/intern/bpy_driver.c	2011-01-03 12:11:05 UTC (rev 34033)
@@ -124,7 +124,7 @@
 }
 
 /* error return function for BPY_eval_pydriver */
-static float pydriver_error(ChannelDriver *driver)
+static void pydriver_error(ChannelDriver *driver)
 {
 	driver->flag |= DRIVER_FLAG_INVALID; /* py expression failed */
 	fprintf(stderr, "\nError in Driver: The following Python expression failed:\n\t'%s'\n\n", driver->expression);
@@ -132,8 +132,6 @@
 	// BPy_errors_to_report(NULL); // TODO - reports
 	PyErr_Print();
 	PyErr_Clear();
-
-	return 0.0f;
 }
 
 /* This evals py driver expressions, 'expr' is a Python expression that
@@ -232,7 +230,7 @@
 		
 		/* try to add to dictionary */
 		/* if (PyDict_SetItemString(driver_vars, dvar->name, driver_arg)) { */
-		if (PyDict_SetItem(driver_vars, PyTuple_GET_ITEM(expr_vars, i++), driver_arg)) { /* use string interning for faster namespace creation */
+		if (PyDict_SetItem(driver_vars, PyTuple_GET_ITEM(expr_vars, i++), driver_arg) < 0) { /* use string interning for faster namespace creation */
 			/* this target failed - bad name */
 			if (targets_ok) {
 				/* first one - print some extra info for easier identification */





More information about the Bf-blender-cvs mailing list