[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34381] trunk/blender/source/blender: bgl. Buffer()

Campbell Barton ideasman42 at gmail.com
Tue Jan 18 04:49:29 CET 2011


Revision: 34381
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=34381
Author:   campbellbarton
Date:     2011-01-18 03:49:28 +0000 (Tue, 18 Jan 2011)
Log Message:
-----------
bgl.Buffer()
 - invalid dimension type could be passed without raising an error.
 - negative dimensions could crash blender, now they raise errors.
 - zero length dimension arg was not detected.
 - floating point lengths were accepted, now only allow ints.

 also comment unused vars.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/gpencil/gpencil_paint.c
    trunk/blender/source/blender/python/generic/bgl.c

Modified: trunk/blender/source/blender/editors/gpencil/gpencil_paint.c
===================================================================
--- trunk/blender/source/blender/editors/gpencil/gpencil_paint.c	2011-01-18 01:58:19 UTC (rev 34380)
+++ trunk/blender/source/blender/editors/gpencil/gpencil_paint.c	2011-01-18 03:49:28 UTC (rev 34381)
@@ -899,8 +899,8 @@
 		/* supported views first */
 		case SPACE_VIEW3D:
 		{
-			View3D *v3d= curarea->spacedata.first;
-			RegionView3D *rv3d= ar->regiondata;
+			// View3D *v3d= curarea->spacedata.first;
+			// RegionView3D *rv3d= ar->regiondata;
 			
 			/* set current area 
 			 *	- must verify that region data is 3D-view (and not something else)

Modified: trunk/blender/source/blender/python/generic/bgl.c
===================================================================
--- trunk/blender/source/blender/python/generic/bgl.c	2011-01-18 01:58:19 UTC (rev 34380)
+++ trunk/blender/source/blender/python/generic/bgl.c	2011-01-18 03:49:28 UTC (rev 34381)
@@ -187,43 +187,60 @@
 #define MAX_DIMENSIONS	256
 static PyObject *Method_Buffer (PyObject *UNUSED(self), PyObject *args)
 {
-	PyObject *length_ob= NULL, *template= NULL;
+	PyObject *length_ob= NULL, *init= NULL;
 	Buffer *buffer;
 	int dimensions[MAX_DIMENSIONS];
 	
 	int i, type;
 	int ndimensions = 0;
 	
-	if (!PyArg_ParseTuple(args, "iO|O", &type, &length_ob, &template)) {
+	if (!PyArg_ParseTuple(args, "iO|O", &type, &length_ob, &init)) {
 		PyErr_SetString(PyExc_AttributeError, "expected an int and one or two PyObjects");
 		return NULL;
 	}
-	if (type!=GL_BYTE && type!=GL_SHORT && type!=GL_INT && type!=GL_FLOAT && type!=GL_DOUBLE) {
+	if (!ELEM5(type, GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT, GL_DOUBLE)) {
 		PyErr_SetString(PyExc_AttributeError, "invalid first argument type, should be one of GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT or GL_DOUBLE");
 		return NULL;
 	}
 
-	if (PyNumber_Check(length_ob)) {
+	if (PyLong_Check(length_ob)) {
 		ndimensions= 1;
-		dimensions[0]= PyLong_AsLong(length_ob);
-	} else if (PySequence_Check(length_ob)) {
+		if(((dimensions[0]= PyLong_AsLong(length_ob)) < 1)) {
+			PyErr_SetString(PyExc_AttributeError, "dimensions must be between 1 and "STRINGIFY(MAX_DIMENSIONS));
+			return NULL;
+		}
+	}
+	else if (PySequence_Check(length_ob)) {
 		ndimensions= PySequence_Size(length_ob);
 		if (ndimensions > MAX_DIMENSIONS) {
-			PyErr_SetString(PyExc_AttributeError, "too many dimensions, max is 256");
+			PyErr_SetString(PyExc_AttributeError, "too many dimensions, max is "STRINGIFY(MAX_DIMENSIONS));
 			return NULL;
 		}
+		else if (ndimensions < 1) {
+			PyErr_SetString(PyExc_AttributeError, "sequence must have at least one dimension");
+			return NULL;
+		}
 		for (i=0; i<ndimensions; i++) {
 			PyObject *ob= PySequence_GetItem(length_ob, i);
 
-			if (!PyNumber_Check(ob)) dimensions[i]= 1;
+			if (!PyLong_Check(ob)) dimensions[i]= 1;
 			else dimensions[i]= PyLong_AsLong(ob);
 			Py_DECREF(ob);
+
+			if(dimensions[i] < 1) {
+				PyErr_SetString(PyExc_AttributeError, "dimensions must be between 1 and "STRINGIFY(MAX_DIMENSIONS));
+				return NULL;
+			}
 		}
 	}
+	else {
+		PyErr_Format(PyExc_TypeError, "invalid second argument argument expected a sequence or an int, not a %.200s", Py_TYPE(length_ob)->tp_name);
+		return NULL;
+	}
 	
 	buffer= BGL_MakeBuffer(type, ndimensions, dimensions, NULL);
-	if (template && ndimensions) {
-		if (Buffer_ass_slice((PyObject *) buffer, 0, dimensions[0], template)) {
+	if (init && ndimensions) {
+		if (Buffer_ass_slice((PyObject *) buffer, 0, dimensions[0], init)) {
 			Py_DECREF(buffer);
 			return NULL;
 		}




More information about the Bf-blender-cvs mailing list