Mathutils
- fix own mistake with matrix slicing that would crash blender (from recent commit). - fix 3 memory leaks from ascotan r4717 in the Mathutils.Quaternion(...) function.
This commit is contained in:
@@ -309,8 +309,8 @@ PyObject *M_Mathutils_Vector(PyObject * self, PyObject * args)
|
||||
{
|
||||
PyObject *listObject = NULL;
|
||||
int size, i;
|
||||
float vec[4];
|
||||
PyObject *v, *f;
|
||||
float vec[4], f;
|
||||
PyObject *v;
|
||||
|
||||
size = PySequence_Length(args);
|
||||
if (size == 1) {
|
||||
@@ -344,16 +344,15 @@ PyObject *M_Mathutils_Vector(PyObject * self, PyObject * args)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
f=PyNumber_Float(v);
|
||||
if(f==NULL) { // parsed item not a number
|
||||
f= PyFloat_AsDouble(v);
|
||||
if(f==-1 && PyErr_Occurred()) { // parsed item not a number
|
||||
Py_DECREF(v);
|
||||
Py_XDECREF(listObject);
|
||||
PyErr_SetString(PyExc_TypeError, "Mathutils.Vector(): 2-4 floats or ints expected (optionally in a sequence)\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vec[i]=(float)PyFloat_AS_DOUBLE(f);
|
||||
Py_DECREF(f);
|
||||
vec[i]= f;
|
||||
Py_DECREF(v);
|
||||
}
|
||||
Py_DECREF(listObject);
|
||||
@@ -999,16 +998,24 @@ PyObject *M_Mathutils_Quaternion(PyObject * self, PyObject * args)
|
||||
return NULL;
|
||||
}
|
||||
if(size == 3){ //get angle in axis/angle
|
||||
n = PyNumber_Float(PySequence_GetItem(args, 1));
|
||||
n = PySequence_GetItem(args, 1);
|
||||
if(n == NULL) { // parsed item not a number or getItem fail
|
||||
Py_DECREF(listObject);
|
||||
PyErr_SetString(PyExc_TypeError, "Mathutils.Quaternion(): 4d numeric sequence expected or 3d vector and number\n");
|
||||
return NULL;
|
||||
}
|
||||
angle = PyFloat_AS_DOUBLE(n);
|
||||
|
||||
angle = PyFloat_AsDouble(n);
|
||||
Py_DECREF(n);
|
||||
|
||||
if (angle==-1 && PyErr_Occurred()) {
|
||||
Py_DECREF(listObject);
|
||||
PyErr_SetString(PyExc_TypeError, "Mathutils.Quaternion(): 4d numeric sequence expected or 3d vector and number\n");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
Py_DECREF(listObject); /* assume the list is teh second arg */
|
||||
listObject = PySequence_GetItem(args, 1);
|
||||
if (size>1 && PySequence_Check(listObject)) {
|
||||
size = PySequence_Length(listObject);
|
||||
@@ -1018,14 +1025,20 @@ PyObject *M_Mathutils_Quaternion(PyObject * self, PyObject * args)
|
||||
PyErr_SetString(PyExc_AttributeError, "Mathutils.Quaternion(): 4d numeric sequence expected or 3d vector and number\n");
|
||||
return NULL;
|
||||
}
|
||||
n = PyNumber_Float(PySequence_GetItem(args, 0));
|
||||
n = PySequence_GetItem(args, 0);
|
||||
if(n == NULL) { // parsed item not a number or getItem fail
|
||||
Py_DECREF(listObject);
|
||||
PyErr_SetString(PyExc_TypeError, "Mathutils.Quaternion(): 4d numeric sequence expected or 3d vector and number\n");
|
||||
return NULL;
|
||||
}
|
||||
angle = PyFloat_AS_DOUBLE(n);
|
||||
angle = PyFloat_AsDouble(n);
|
||||
Py_DECREF(n);
|
||||
|
||||
if (angle==-1 && PyErr_Occurred()) {
|
||||
Py_DECREF(listObject);
|
||||
PyErr_SetString(PyExc_TypeError, "Mathutils.Quaternion(): 4d numeric sequence expected or 3d vector and number\n");
|
||||
return NULL;
|
||||
}
|
||||
} else { // argument was not a sequence
|
||||
Py_XDECREF(listObject);
|
||||
PyErr_SetString(PyExc_TypeError, "Mathutils.Quaternion(): 4d numeric sequence expected or 3d vector and number\n");
|
||||
|
||||
@@ -575,9 +575,9 @@ static int Matrix_ass_slice(MatrixObject * self, int begin, int end,
|
||||
PyObject * seq)
|
||||
{
|
||||
int i, x, y, size, sub_size = 0;
|
||||
float mat[16];
|
||||
float mat[16], f;
|
||||
PyObject *subseq;
|
||||
PyObject *m, *f;
|
||||
PyObject *m;
|
||||
|
||||
CLAMP(begin, 0, self->rowSize);
|
||||
CLAMP(end, 0, self->rowSize);
|
||||
@@ -613,18 +613,17 @@ static int Matrix_ass_slice(MatrixObject * self, int begin, int end,
|
||||
PyErr_SetString(PyExc_RuntimeError, "matrix[begin:end] = []: unable to read sequence\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
f = PyNumber_Float(m);
|
||||
if(f == NULL) { /*parsed item not a number*/
|
||||
|
||||
f = PyFloat_AsDouble(m); /* faster to assume a float and raise an error after */
|
||||
if(f == -1 && PyErr_Occurred()) { /*parsed item not a number*/
|
||||
Py_DECREF(m);
|
||||
Py_DECREF(subseq);
|
||||
PyErr_SetString(PyExc_TypeError, "matrix[begin:end] = []: sequence argument not a number\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
mat[(i * self->colSize) + y] = (float)PyFloat_AS_DOUBLE(f);
|
||||
mat[(i * self->colSize) + y] = f;
|
||||
Py_DECREF(m);
|
||||
Py_DECREF(subseq);
|
||||
}
|
||||
}else{
|
||||
Py_DECREF(subseq);
|
||||
|
||||
Reference in New Issue
Block a user