[Bf-python] Curve.getControlPoint() patch
Stephen Swaney
sswaney at swbell.net
Fri Aug 22 07:00:52 CEST 2003
Greetings:
Here is an improved version of the patch for Curves.c
that I sent to Jacques the other day. It adds some
checking to the Curve_getControlPoint method to throw
an AttributeError exception instead of segfaulting when
input params are out of range.
Stephen
--
Stephen Swaney
sswaney at swbell.net
------------------------------------------------------------------------
Index: Curve.c
===================================================================
RCS file:
/cvsroot/bf-blender/blender/source/blender/python/api2_2x/Curve.c,v
retrieving revision 1.12
diff -u -r1.12 Curve.c
--- Curve.c 9 Jul 2003 21:18:34 -0000 1.12
+++ Curve.c 22 Aug 2003 04:32:19 -0000
@@ -458,41 +458,59 @@
return Py_None;
}
+
static PyObject *Curve_getControlPoint(BPy_Curve *self, PyObject *args)
{
- PyObject* liste = PyList_New(0);
+ PyObject* liste = PyList_New(0); /* return values */
Nurb*ptrnurb;
- int numcourbe,numpoint,i,j;
-
+ int i,j;
+ /* input args: requested curve and point number on curve */
+ int numcourbe, numpoint;
+
+ /* parse input args */
if (!PyArg_ParseTuple(args, "ii", &numcourbe,&numpoint))
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
- "expected int int arguments"));
- //check args ???
- if (!self->curve->nurb.first)return liste;
+ "expected int int arguments"));
+ /* validate input args */
+ if( (numcourbe < 0) || (numpoint < 0) )
+ return (EXPP_ReturnPyObjError (PyExc_AttributeError,
+ " arguments must be non-negative"));
+
+ /* if no nurbs in this curve obj */
+ if (!self->curve->nurb.first) return liste;
+
+ /* walk the list of nurbs to find requested numcourbe */
ptrnurb = self->curve->nurb.first;
- for(i = 0;i< numcourbe;i++)//selection of the first point of the
curve
- ptrnurb=ptrnurb->next;
-
- if (ptrnurb->bp)
+ for(i = 0; i < numcourbe; i++)
{
- for(i = 0;i< 4;i++)
+ ptrnurb=ptrnurb->next;
+ if( !ptrnurb ) /* if zero, we ran just ran out of curves */
+ return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
+ "curve index out of range"));
+ }
+
+ /* check numpoint param against pntsu */
+ if( numpoint >= ptrnurb->pntsu )
+ return (EXPP_ReturnPyObjError( PyExc_AttributeError,
+ "point index out of range"));
+
+ if (ptrnurb->bp) /* if we are a nurb curve, you get 4 values */
+ {
+ for(i = 0; i< 4; i++)
PyList_Append(liste, PyFloat_FromDouble(
ptrnurb->bp[numpoint].vec[i]));
}
- if (ptrnurb->bezt)
+ if (ptrnurb->bezt) /* if we are a bezier, you get 9 values */
{
- liste = PyList_New(9);
- for(i = 0;i< 3;i++)
- for(j = 0;j< 3;j++)
+ for(i = 0; i< 3; i++)
+ for(j = 0; j< 3; j++)
PyList_Append(liste,
- PyFloat_FromDouble( ptrnurb->bezt[numpoint].vec[i][j]));
+ PyFloat_FromDouble( ptrnurb->bezt[numpoint].vec[i][j]));
}
return liste;
}
-
-
static PyObject *Curve_getLoc(BPy_Curve *self)
{
More information about the Bf-python
mailing list