PyNumberMethods needed ifdefs for python3.x and some other corrections.
authorCampbell Barton <ideasman42@gmail.com>
Sun, 28 Jun 2009 13:27:06 +0000 (13:27 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 28 Jun 2009 13:27:06 +0000 (13:27 +0000)
source/blender/python/generic/BGL.c
source/blender/python/generic/Mathutils.c
source/blender/python/generic/euler.c
source/blender/python/generic/matrix.c
source/blender/python/generic/quat.c
source/blender/python/generic/vector.c

index a90fabd35866ecee8534ac36d76d68f1d1219361..de82781cf3a2fc449360d41526f3c618a3c8f5cd 100644 (file)
@@ -83,8 +83,13 @@ static PyObject *Buffer_getattr( PyObject * self, char *name );
 static PyObject *Buffer_repr( PyObject * self );
 
 PyTypeObject buffer_Type = {
-       PyObject_HEAD_INIT( NULL )      /* required python macro */
-       0,      /*ob_size */
+#if (PY_VERSION_HEX >= 0x02060000)
+       PyVarObject_HEAD_INIT(NULL, 0)
+#else
+       /* python 2.5 and below */
+       PyObject_HEAD_INIT( NULL )  /* required py macro */
+       0,                          /* ob_size */
+#endif
        "buffer",               /*tp_name */
        sizeof( Buffer ),       /*tp_basicsize */
        0,                      /*tp_itemsize */
index ec94a48ddbd4e57bfc1c9fee248bdb1f16534324..ffb110376b05185746f640a7315c3480fb6141af 100644 (file)
@@ -1244,7 +1244,7 @@ PyObject *BaseMathObject_getOwner( BaseMathObject * self, void *type )
 
 PyObject *BaseMathObject_getWrapped( BaseMathObject *self, void *type )
 {
-       PyBool_FromLong((self->wrapped == Py_WRAP) ? 1:0);
+       return PyBool_FromLong((self->wrapped == Py_WRAP) ? 1:0);
 }
 
 void BaseMathObject_dealloc(BaseMathObject * self)
index 9041eb84a3d05c9040044c0a3334a0bac2ae66c0..769c82ed03429800b611610d84f391ac282eb06a 100644 (file)
@@ -65,7 +65,7 @@ static struct PyMethodDef Euler_methods[] = {
 
 //----------------------------------Mathutils.Euler() -------------------
 //makes a new euler for you to play with
-static PyObject *Euler_new(PyObject * self, PyObject * args)
+static PyObject *Euler_new(PyObject * self, PyObject * args, PyObject * kwargs)
 {
 
        PyObject *listObject = NULL;
@@ -173,8 +173,13 @@ static PyObject *Euler_Unique(EulerObject * self)
        heading = self->eul[0] * (float)Py_PI / 180;
        pitch = self->eul[1] * (float)Py_PI / 180;
        bank = self->eul[2] * (float)Py_PI / 180;
+#else
+       heading = self->eul[0];
+       pitch = self->eul[1];
+       bank = self->eul[2];
 #endif
 
+
        //wrap heading in +180 / -180
        pitch += Py_PI;
        pitch -= floor(pitch * Opi2) * pi2;
@@ -271,8 +276,10 @@ static PyObject *Euler_Rotate(EulerObject * self, PyObject *args)
 
 static PyObject *Euler_MakeCompatible(EulerObject * self, EulerObject *value)
 {
+#ifdef USE_MATHUTILS_DEG
        float eul_from_rad[3];
        int x;
+#endif
        
        if(!EulerObject_Check(value)) {
                PyErr_SetString(PyExc_TypeError, "euler.makeCompatible(euler):expected a single euler argument.");
@@ -460,7 +467,7 @@ static int Euler_ass_slice(EulerObject * self, int begin, int end,
        PyObject *e;
 
        if(!BaseMath_ReadCallback(self))
-               return NULL;
+               return -1;
 
        CLAMP(begin, 0, 3);
        if (end<0) end= 4+end;
@@ -636,5 +643,5 @@ PyObject *newEulerObject_cb(PyObject *cb_user, int cb_type, int cb_subtype)
                self->cb_subtype=               (unsigned char)cb_subtype;
        }
 
-       return self;
+       return (PyObject *)self;
 }
index b546aa1226c5ec76e0c3a545bc5668c3f18594cf..311a14fbb0a2f4db9d832a315161dc5e5bd3e6a0 100644 (file)
@@ -1012,6 +1012,46 @@ static PySequenceMethods Matrix_SeqMethods = {
        (ssizeobjargproc) Matrix_ass_item,              /* sq_ass_item */
        (ssizessizeobjargproc) Matrix_ass_slice,        /* sq_ass_slice */
 };
+
+
+#if (PY_VERSION_HEX >= 0x03000000)
+static PyNumberMethods Matrix_NumMethods = {
+               (binaryfunc)    Matrix_add,     /*nb_add*/
+               (binaryfunc)    Matrix_sub,     /*nb_subtract*/
+               (binaryfunc)    Matrix_mul,     /*nb_multiply*/
+               0,                                                      /*nb_remainder*/
+               0,                                                      /*nb_divmod*/
+               0,                                                      /*nb_power*/
+               (unaryfunc)     0,      /*nb_negative*/
+               (unaryfunc)     0,      /*tp_positive*/
+               (unaryfunc)     0,      /*tp_absolute*/
+               (inquiry)       0,      /*tp_bool*/
+               (unaryfunc)     Matrix_inv,     /*nb_invert*/
+               0,                              /*nb_lshift*/
+               (binaryfunc)0,  /*nb_rshift*/
+               0,                              /*nb_and*/
+               0,                              /*nb_xor*/
+               0,                              /*nb_or*/
+               0,                              /*nb_int*/
+               0,                              /*nb_reserved*/
+               0,                              /*nb_float*/
+               0,                              /* nb_inplace_add */
+               0,                              /* nb_inplace_subtract */
+               0,                              /* nb_inplace_multiply */
+               0,                              /* nb_inplace_remainder */
+               0,                              /* nb_inplace_power */
+               0,                              /* nb_inplace_lshift */
+               0,                              /* nb_inplace_rshift */
+               0,                              /* nb_inplace_and */
+               0,                              /* nb_inplace_xor */
+               0,                              /* nb_inplace_or */
+               0,                              /* nb_floor_divide */
+               0,                              /* nb_true_divide */
+               0,                              /* nb_inplace_floor_divide */
+               0,                              /* nb_inplace_true_divide */
+               0,                              /* nb_index */
+};
+#else
 static PyNumberMethods Matrix_NumMethods = {
        (binaryfunc) Matrix_add,                                /* __add__ */
        (binaryfunc) Matrix_sub,                                /* __sub__ */
@@ -1037,6 +1077,7 @@ static PyNumberMethods Matrix_NumMethods = {
        (unaryfunc) 0,                                                  /* __oct__ */
        (unaryfunc) 0,                                                  /* __hex__ */
 };
+#endif
 
 static PyObject *Matrix_getRowSize( MatrixObject * self, void *type )
 {
index e7413d38ee5a424b33dbca1fefcde35e19118c97..7cd3cf738dd86f47e118c3e5cbb18efb7b2e3894 100644 (file)
@@ -622,6 +622,45 @@ static PySequenceMethods Quaternion_SeqMethods = {
        (ssizeobjargproc) Quaternion_ass_item,          /* sq_ass_item */
        (ssizessizeobjargproc) Quaternion_ass_slice,    /* sq_ass_slice */
 };
+
+#if (PY_VERSION_HEX >= 0x03000000)
+static PyNumberMethods Quaternion_NumMethods = {
+               (binaryfunc)    Quaternion_add, /*nb_add*/
+               (binaryfunc)    Quaternion_sub, /*nb_subtract*/
+               (binaryfunc)    Quaternion_mul, /*nb_multiply*/
+               0,                                                      /*nb_remainder*/
+               0,                                                      /*nb_divmod*/
+               0,                                                      /*nb_power*/
+               (unaryfunc)     0,      /*nb_negative*/
+               (unaryfunc)     0,      /*tp_positive*/
+               (unaryfunc)     0,      /*tp_absolute*/
+               (inquiry)       0,      /*tp_bool*/
+               (unaryfunc)     0,      /*nb_invert*/
+               0,                              /*nb_lshift*/
+               (binaryfunc)0,  /*nb_rshift*/
+               0,                              /*nb_and*/
+               0,                              /*nb_xor*/
+               0,                              /*nb_or*/
+               0,                              /*nb_int*/
+               0,                              /*nb_reserved*/
+               0,                              /*nb_float*/
+               0,                              /* nb_inplace_add */
+               0,                              /* nb_inplace_subtract */
+               0,                              /* nb_inplace_multiply */
+               0,                              /* nb_inplace_remainder */
+               0,                              /* nb_inplace_power */
+               0,                              /* nb_inplace_lshift */
+               0,                              /* nb_inplace_rshift */
+               0,                              /* nb_inplace_and */
+               0,                              /* nb_inplace_xor */
+               0,                              /* nb_inplace_or */
+               0,                              /* nb_floor_divide */
+               0,                              /* nb_true_divide */
+               0,                              /* nb_inplace_floor_divide */
+               0,                              /* nb_inplace_true_divide */
+               0,                              /* nb_index */
+};
+#else
 static PyNumberMethods Quaternion_NumMethods = {
        (binaryfunc) Quaternion_add,                            /* __add__ */
        (binaryfunc) Quaternion_sub,                            /* __sub__ */
@@ -646,9 +685,8 @@ static PyNumberMethods Quaternion_NumMethods = {
        (unaryfunc) 0,                                                          /* __float__ */
        (unaryfunc) 0,                                                          /* __oct__ */
        (unaryfunc) 0,                                                          /* __hex__ */
-
 };
-
+#endif
 
 static PyObject *Quaternion_getAxis( QuaternionObject * self, void *type )
 {
index 9ce0a7ca2f9ee329808f95fc7df11e15c7e1a739..d8d4c33b6f81a039ecb75a1db0a45da10f47d089 100644 (file)
@@ -1077,6 +1077,44 @@ static PySequenceMethods Vector_SeqMethods = {
        (ssizessizeobjargproc) Vector_ass_slice,                /* sq_ass_slice */
 };
  
+#if (PY_VERSION_HEX >= 0x03000000)
+static PyNumberMethods Vector_NumMethods = {
+               (binaryfunc)    Vector_add,     /*nb_add*/
+               (binaryfunc)    Vector_sub,     /*nb_subtract*/
+               (binaryfunc)    Vector_mul,     /*nb_multiply*/
+               0,                                                      /*nb_remainder*/
+               0,                                                      /*nb_divmod*/
+               0,                                                      /*nb_power*/
+               (unaryfunc)     Vector_neg,     /*nb_negative*/
+               (unaryfunc)     0,      /*tp_positive*/
+               (unaryfunc)     0,      /*tp_absolute*/
+               (inquiry)       0,      /*tp_bool*/
+               (unaryfunc)     0,      /*nb_invert*/
+               0,                              /*nb_lshift*/
+               (binaryfunc)0,  /*nb_rshift*/
+               0,                              /*nb_and*/
+               0,                              /*nb_xor*/
+               0,                              /*nb_or*/
+               0,                              /*nb_int*/
+               0,                              /*nb_reserved*/
+               0,                              /*nb_float*/
+               Vector_iadd,    /* nb_inplace_add */
+               Vector_isub,    /* nb_inplace_subtract */
+               Vector_imul,    /* nb_inplace_multiply */
+               0,                              /* nb_inplace_remainder */
+               0,                              /* nb_inplace_power */
+               0,                              /* nb_inplace_lshift */
+               0,                              /* nb_inplace_rshift */
+               0,                              /* nb_inplace_and */
+               0,                              /* nb_inplace_xor */
+               0,                              /* nb_inplace_or */
+               0,                              /* nb_floor_divide */
+               Vector_div,             /* nb_true_divide */
+               0,                              /* nb_inplace_floor_divide */
+               Vector_idiv,    /* nb_inplace_true_divide */
+               0,                      /* nb_index */
+};
+#else
 static PyNumberMethods Vector_NumMethods = {
        (binaryfunc) Vector_add,                                        /* __add__ */
        (binaryfunc) Vector_sub,                                        /* __sub__ */
@@ -1122,6 +1160,8 @@ static PyNumberMethods Vector_NumMethods = {
        (binaryfunc) NULL,                                                      /*__ifloordiv__*/
        (binaryfunc) NULL,                                                      /*__itruediv__*/
 };
+#endif
+
 /*------------------PY_OBECT DEFINITION--------------------------*/
 
 /*