[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11330] trunk/blender/source/blender/ python/api2_2x: fixed some bugs in Draw.c
Campbell Barton
cbarton at metavr.com
Sun Jul 22 01:24:43 CEST 2007
Revision: 11330
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11330
Author: campbellbarton
Date: 2007-07-22 01:24:08 +0200 (Sun, 22 Jul 2007)
Log Message:
-----------
fixed some bugs in Draw.c
* incorrect args to Draw.Create() would crash blender because it wasnt deallocating the value properly.
* deallocation of an uninitialized button could also try and free uninitialized memory if the type happened to be a STRING.
* removed the unused tooltip pointer from teh Draw.h's Button struct.
Modified Paths:
--------------
trunk/blender/source/blender/python/api2_2x/Draw.c
trunk/blender/source/blender/python/api2_2x/Draw.h
Modified: trunk/blender/source/blender/python/api2_2x/Draw.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Draw.c 2007-07-21 16:56:53 UTC (rev 11329)
+++ trunk/blender/source/blender/python/api2_2x/Draw.c 2007-07-21 23:24:08 UTC (rev 11330)
@@ -588,11 +588,15 @@
static PyObject *Button_richcmpr(PyObject *objectA, PyObject *objectB, int comparison_type)
{
+ PyObject *ret, *valA=NULL, *valB=NULL;
if (ButtonObject_Check(objectA))
- objectA = Button_getattr( objectA, "val" );
+ objectA = valA = Button_getattr( objectA, "val" );
if (ButtonObject_Check(objectB))
- objectB = Button_getattr( objectB, "val" );
- return PyObject_RichCompare(objectA, objectB, comparison_type);
+ objectB = valB = Button_getattr( objectB, "val" );
+ ret = PyObject_RichCompare(objectA, objectB, comparison_type);
+ Py_XDECREF(valA); /* Button_getattr created with 1 ref, we dont care about them now */
+ Py_XDECREF(valB);
+ return ret;
}
@@ -1003,21 +1007,24 @@
char *newstr;
but = newbutton();
-
+ /* If this function dosnt sucseed this will need to be deallocated,
+ * make sure the type is NOT BSTRING_TYPE before deallocing -1 is ok.
+ * so we dont dealloc with an uninitialized value wich would be bad! */
if ( PyArg_ParseTuple( args, "fff", but->val.asvec, but->val.asvec+1, but->val.asvec+2 ) ) {
but->type = BVECTOR_TYPE;
- }
- else if ( PyArg_ParseTuple( args, "O!", &PyFloat_Type, &val ) ) {
+
+ } else if ( PyArg_ParseTuple( args, "O!", &PyFloat_Type, &val ) ) {
but->val.asfloat = (float)PyFloat_AS_DOUBLE(val);
but->type = BFLOAT_TYPE;
- }
- else if ( PyArg_ParseTuple( args, "O!", &PyInt_Type, &val ) ) {
+
+ } else if ( PyArg_ParseTuple( args, "O!", &PyInt_Type, &val ) ) {
but->val.asint = (int)PyInt_AS_LONG(val);
but->type = BINT_TYPE;
- }
- else if ( PyArg_ParseTuple( args, "s#", &newstr, &but->slen ) ) {
+
+ } else if ( PyArg_ParseTuple( args, "s#", &newstr, &but->slen ) ) {
if (but->slen + 1 > UI_MAX_DRAW_STR) {
- PyObject_DEL( (PyObject *) but );
+ but->type = -1;
+ Py_DECREF((PyObject *)but); /* will remove */
but = NULL;
PyErr_SetString( PyExc_TypeError, "string is longer then 399 chars");
} else {
@@ -1025,9 +1032,10 @@
but->val.asstr = MEM_mallocN( but->slen + 1, "button string" );
BLI_strncpy( but->val.asstr, newstr, but->slen+1 );
}
- }
- else {
- PyObject_DEL( (PyObject *) but );
+
+ } else {
+ but->type = -1;
+ Py_DECREF((PyObject *)but); /* will remove */
but = NULL;
PyErr_SetString( PyExc_TypeError, "expected string, float, int or 3-float tuple argument" );
}
Modified: trunk/blender/source/blender/python/api2_2x/Draw.h
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Draw.h 2007-07-21 16:56:53 UTC (rev 11329)
+++ trunk/blender/source/blender/python/api2_2x/Draw.h 2007-07-21 23:24:08 UTC (rev 11330)
@@ -57,7 +57,7 @@
char *asstr;
float asvec[3];
} val;
- char *tooltip;
+ /*char *tooltip;*/
} Button;
#define BINT_TYPE 1
More information about the Bf-blender-cvs
mailing list