Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Hughes <khughes@pacific.edu>2005-12-05 22:02:30 +0300
committerKen Hughes <khughes@pacific.edu>2005-12-05 22:02:30 +0300
commite209676d3d55c3d6a4e2fffd97cbd448a7bb556b (patch)
treea18cba90c2855c29eef1c4e7895a8b95793e8b65
parentf98a5a80366c5307e3a286c102a6dc804b778a42 (diff)
-- 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().
-rw-r--r--source/blender/python/api2_2x/matrix.c24
-rw-r--r--source/blender/python/api2_2x/point.c24
-rw-r--r--source/blender/python/api2_2x/quat.c25
-rw-r--r--source/blender/python/api2_2x/vector.c22
4 files changed, 41 insertions, 54 deletions
diff --git a/source/blender/python/api2_2x/matrix.c b/source/blender/python/api2_2x/matrix.c
index 6b90a3a6494..894643c5362 100644
--- a/source/blender/python/api2_2x/matrix.c
+++ b/source/blender/python/api2_2x/matrix.c
@@ -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
diff --git a/source/blender/python/api2_2x/point.c b/source/blender/python/api2_2x/point.c
index 2246f49b6ef..56e1eae5904 100644
--- a/source/blender/python/api2_2x/point.c
+++ b/source/blender/python/api2_2x/point.c
@@ -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 */
diff --git a/source/blender/python/api2_2x/quat.c b/source/blender/python/api2_2x/quat.c
index 3c7cb4b839a..1cd07b0f588 100644
--- a/source/blender/python/api2_2x/quat.c
+++ b/source/blender/python/api2_2x/quat.c
@@ -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];
diff --git a/source/blender/python/api2_2x/vector.c b/source/blender/python/api2_2x/vector.c
index a0afaf60c1e..bb862fe42f7 100644
--- a/source/blender/python/api2_2x/vector.c
+++ b/source/blender/python/api2_2x/vector.c
@@ -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.";