-- Bugfix 3453: coercion operations were doing an extra incref on coerced
objects. Also found extra increfs on some newly-created quat and matrix objects, from calls to Matrix_Identity() and Quaternion_Identity().
This commit is contained in:
@@ -733,22 +733,19 @@ PyObject* Matrix_inv(MatrixObject *self)
|
||||
then call vector.multiply(vector, scalar_cast_as_vector)*/
|
||||
static int Matrix_coerce(PyObject ** m1, PyObject ** m2)
|
||||
{
|
||||
PyObject *coerced = NULL;
|
||||
if(!MatrixObject_Check(*m2)) {
|
||||
if(VectorObject_Check(*m2) || PyFloat_Check(*m2) || PyInt_Check(*m2) ||
|
||||
if(VectorObject_Check(*m2) || PyFloat_Check(*m2) || PyInt_Check(*m2) ||
|
||||
PointObject_Check(*m2)) {
|
||||
coerced = EXPP_incr_ret(*m2);
|
||||
*m2 = newMatrixObject(NULL,3,3,Py_NEW);
|
||||
((MatrixObject*)*m2)->coerced_object = coerced;
|
||||
}else{
|
||||
return EXPP_ReturnIntError(PyExc_TypeError,
|
||||
"matrix.coerce(): unknown operand - can't coerce for numeric protocols\n");
|
||||
}
|
||||
PyObject *coerced = EXPP_incr_ret(*m2);
|
||||
*m2 = newMatrixObject(NULL,3,3,Py_NEW);
|
||||
((MatrixObject*)*m2)->coerced_object = coerced;
|
||||
Py_INCREF (*m1);
|
||||
return 0;
|
||||
}
|
||||
EXPP_incr2(*m1, *m2);
|
||||
return 0;
|
||||
|
||||
return EXPP_ReturnIntError(PyExc_TypeError,
|
||||
"matrix.coerce(): unknown operand - can't coerce for numeric protocols");
|
||||
}
|
||||
//-----------------PROTCOL DECLARATIONS--------------------------
|
||||
//-----------------PROTOCOL DECLARATIONS--------------------------
|
||||
static PySequenceMethods Matrix_SeqMethods = {
|
||||
(inquiry) Matrix_len, /* sq_length */
|
||||
(binaryfunc) 0, /* sq_concat */
|
||||
@@ -908,6 +905,7 @@ PyObject *newMatrixObject(float *mat, int rowSize, int colSize, int type)
|
||||
}
|
||||
} else { //or if no arguments are passed return identity matrix
|
||||
Matrix_Identity(self);
|
||||
Py_DECREF(self);
|
||||
}
|
||||
self->wrapped = Py_NEW;
|
||||
}else{ //bad type
|
||||
|
||||
@@ -416,23 +416,19 @@ static PyObject *Point_neg(PointObject *self)
|
||||
then call vector.multiply(vector, scalar_cast_as_vector)*/
|
||||
static int Point_coerce(PyObject ** p1, PyObject ** p2)
|
||||
{
|
||||
PyObject *coerced = NULL;
|
||||
|
||||
if(!PointObject_Check(*p2)) {
|
||||
if(VectorObject_Check(*p2) || PyFloat_Check(*p2) || PyInt_Check(*p2) ||
|
||||
if(VectorObject_Check(*p2) || PyFloat_Check(*p2) || PyInt_Check(*p2) ||
|
||||
MatrixObject_Check(*p2) || QuaternionObject_Check(*p2)) {
|
||||
coerced = EXPP_incr_ret(*p2);
|
||||
*p2 = newPointObject(NULL,3,Py_NEW);
|
||||
((PointObject*)*p2)->coerced_object = coerced;
|
||||
}else{
|
||||
return EXPP_ReturnIntError(PyExc_TypeError,
|
||||
"point.coerce(): unknown operand - can't coerce for numeric protocols\n");
|
||||
}
|
||||
PyObject *coerced = EXPP_incr_ret(*p2);
|
||||
*p2 = newPointObject(NULL,3,Py_NEW);
|
||||
((PointObject*)*p2)->coerced_object = coerced;
|
||||
Py_INCREF (*p1);
|
||||
return 0;
|
||||
}
|
||||
EXPP_incr2(*p1, *p2);
|
||||
return 0;
|
||||
|
||||
return EXPP_ReturnIntError(PyExc_TypeError,
|
||||
"point.coerce(): unknown operand - can't coerce for numeric protocols");
|
||||
}
|
||||
//-----------------PROTCOL DECLARATIONS--------------------------
|
||||
//-----------------PROTOCOL DECLARATIONS--------------------------
|
||||
static PySequenceMethods Point_SeqMethods = {
|
||||
(inquiry) Point_len, /* sq_length */
|
||||
(binaryfunc) 0, /* sq_concat */
|
||||
|
||||
@@ -518,23 +518,19 @@ static PyObject *Quaternion_mul(PyObject * q1, PyObject * q2)
|
||||
then call vector.multiply(vector, scalar_cast_as_vector)*/
|
||||
static int Quaternion_coerce(PyObject ** q1, PyObject ** q2)
|
||||
{
|
||||
PyObject *coerced = NULL;
|
||||
|
||||
if(!QuaternionObject_Check(*q2)) {
|
||||
if(VectorObject_Check(*q2) || PyFloat_Check(*q2) || PyInt_Check(*q2) ||
|
||||
if(VectorObject_Check(*q2) || PyFloat_Check(*q2) || PyInt_Check(*q2) ||
|
||||
PointObject_Check(*q2)) {
|
||||
coerced = EXPP_incr_ret(*q2);
|
||||
*q2 = newQuaternionObject(NULL,Py_NEW);
|
||||
((QuaternionObject*)*q2)->coerced_object = coerced;
|
||||
}else{
|
||||
return EXPP_ReturnIntError(PyExc_TypeError,
|
||||
"quaternion.coerce(): unknown operand - can't coerce for numeric protocols\n");
|
||||
}
|
||||
PyObject *coerced = EXPP_incr_ret(*q2);
|
||||
*q2 = newQuaternionObject(NULL,Py_NEW);
|
||||
((QuaternionObject*)*q2)->coerced_object = coerced;
|
||||
Py_INCREF (*q1);
|
||||
return 0;
|
||||
}
|
||||
EXPP_incr2(*q1, *q2);
|
||||
return 0;
|
||||
|
||||
return EXPP_ReturnIntError(PyExc_TypeError,
|
||||
"quaternion.coerce(): unknown operand - can't coerce for numeric protocols");
|
||||
}
|
||||
//-----------------PROTCOL DECLARATIONS--------------------------
|
||||
//-----------------PROTOCOL DECLARATIONS--------------------------
|
||||
static PySequenceMethods Quaternion_SeqMethods = {
|
||||
(inquiry) Quaternion_len, /* sq_length */
|
||||
(binaryfunc) 0, /* sq_concat */
|
||||
@@ -646,6 +642,7 @@ PyObject *newQuaternionObject(float *quat, int type)
|
||||
self->quat = self->data.py_data;
|
||||
if(!quat) { //new empty
|
||||
Quaternion_Identity(self);
|
||||
Py_DECREF(self);
|
||||
}else{
|
||||
for(x = 0; x < 4; x++){
|
||||
self->quat[x] = quat[x];
|
||||
|
||||
@@ -658,21 +658,17 @@ static PyObject *Vector_neg(VectorObject *self)
|
||||
then call vector.multiply(vector, scalar_cast_as_vector)*/
|
||||
static int Vector_coerce(PyObject ** v1, PyObject ** v2)
|
||||
{
|
||||
PyObject *coerced = NULL;
|
||||
|
||||
if(!VectorObject_Check(*v2)) {
|
||||
if(MatrixObject_Check(*v2) || PyFloat_Check(*v2) || PyInt_Check(*v2) ||
|
||||
if(MatrixObject_Check(*v2) || PyFloat_Check(*v2) || PyInt_Check(*v2) ||
|
||||
QuaternionObject_Check(*v2) || PointObject_Check(*v2)) {
|
||||
coerced = EXPP_incr_ret(*v2);
|
||||
*v2 = newVectorObject(NULL,3,Py_NEW);
|
||||
((VectorObject*)*v2)->coerced_object = coerced;
|
||||
}else{
|
||||
return EXPP_ReturnIntError(PyExc_TypeError,
|
||||
"vector.coerce(): unknown operand - can't coerce for numeric protocols\n");
|
||||
}
|
||||
PyObject *coerced = EXPP_incr_ret(*v2);
|
||||
*v2 = newVectorObject(NULL,3,Py_NEW);
|
||||
((VectorObject*)*v2)->coerced_object = coerced;
|
||||
Py_INCREF (*v1);
|
||||
return 0;
|
||||
}
|
||||
EXPP_incr2(*v1, *v2);
|
||||
return 0;
|
||||
|
||||
return EXPP_ReturnIntError(PyExc_TypeError,
|
||||
"vector.coerce(): unknown operand - can't coerce for numeric protocols");
|
||||
}
|
||||
//------------------------tp_doc
|
||||
static char VectorObject_doc[] = "This is a wrapper for vector objects.";
|
||||
|
||||
Reference in New Issue
Block a user