2.5: warning fixes
[blender.git] / source / blender / python / generic / matrix.c
index b546aa1226c5ec76e0c3a545bc5668c3f18594cf..be3e704460a40393210e34bd34e89c633aa22181 100644 (file)
@@ -37,14 +37,17 @@ static PyObject *column_vector_multiplication(MatrixObject * mat, VectorObject*
 /* matrix vector callbacks */
 int mathutils_matrix_vector_cb_index= -1;
 
-static int mathutils_matrix_vector_check(MatrixObject *self)
+static int mathutils_matrix_vector_check(PyObject *self_p)
 {
+       MatrixObject *self= (MatrixObject*)self_p;
        return BaseMath_ReadCallback(self);
 }
 
-static int mathutils_matrix_vector_get(MatrixObject *self, int subtype, float *vec_from)
+static int mathutils_matrix_vector_get(PyObject *self_p, int subtype, float *vec_from)
 {
+       MatrixObject *self= (MatrixObject*)self_p;
        int i;
+
        if(!BaseMath_ReadCallback(self))
                return 0;
 
@@ -54,9 +57,11 @@ static int mathutils_matrix_vector_get(MatrixObject *self, int subtype, float *v
        return 1;
 }
 
-static int mathutils_matrix_vector_set(MatrixObject *self, int subtype, float *vec_to)
+static int mathutils_matrix_vector_set(PyObject *self_p, int subtype, float *vec_to)
 {
+       MatrixObject *self= (MatrixObject*)self_p;
        int i;
+
        if(!BaseMath_ReadCallback(self))
                return 0;
 
@@ -67,8 +72,10 @@ static int mathutils_matrix_vector_set(MatrixObject *self, int subtype, float *v
        return 1;
 }
 
-static int mathutils_matrix_vector_get_index(MatrixObject *self, int subtype, float *vec_from, int index)
+static int mathutils_matrix_vector_get_index(PyObject *self_p, int subtype, float *vec_from, int index)
 {
+       MatrixObject *self= (MatrixObject*)self_p;
+
        if(!BaseMath_ReadCallback(self))
                return 0;
 
@@ -76,8 +83,10 @@ static int mathutils_matrix_vector_get_index(MatrixObject *self, int subtype, fl
        return 1;
 }
 
-static int mathutils_matrix_vector_set_index(MatrixObject *self, int subtype, float *vec_to, int index)
+static int mathutils_matrix_vector_set_index(PyObject *self_p, int subtype, float *vec_to, int index)
 {
+       MatrixObject *self= (MatrixObject*)self_p;
+
        if(!BaseMath_ReadCallback(self))
                return 0;
 
@@ -97,18 +106,6 @@ Mathutils_Callback mathutils_matrix_vector_cb = {
 /* matrix vector callbacks, this is so you can do matrix[i][j] = val  */
 
 /*-------------------------DOC STRINGS ---------------------------*/
-static char Matrix_Zero_doc[] = "() - set all values in the matrix to 0";
-static char Matrix_Identity_doc[] = "() - set the square matrix to it's identity matrix";
-static char Matrix_Transpose_doc[] = "() - set the matrix to it's transpose";
-static char Matrix_Determinant_doc[] = "() - return the determinant of the matrix";
-static char Matrix_Invert_doc[] =  "() - set the matrix to it's inverse if an inverse is possible";
-static char Matrix_TranslationPart_doc[] = "() - return a vector encompassing the translation of the matrix";
-static char Matrix_RotationPart_doc[] = "() - return a vector encompassing the rotation of the matrix";
-static char Matrix_scalePart_doc[] = "() - convert matrix to a 3D vector";
-static char Matrix_Resize4x4_doc[] = "() - resize the matrix to a 4x4 square matrix";
-static char Matrix_toEuler_doc[] = "(eul_compat) - convert matrix to a euler angle rotation, optional euler argument that the new euler will be made compatible with.";
-static char Matrix_toQuat_doc[] = "() - convert matrix to a quaternion rotation";
-static char Matrix_copy_doc[] = "() - return a copy of the matrix";
 
 static PyObject *Matrix_Zero( MatrixObject * self );
 static PyObject *Matrix_Identity( MatrixObject * self );
@@ -125,19 +122,19 @@ static PyObject *Matrix_copy( MatrixObject * self );
 
 /*-----------------------METHOD DEFINITIONS ----------------------*/
 static struct PyMethodDef Matrix_methods[] = {
-       {"zero", (PyCFunction) Matrix_Zero, METH_NOARGS, Matrix_Zero_doc},
-       {"identity", (PyCFunction) Matrix_Identity, METH_NOARGS, Matrix_Identity_doc},
-       {"transpose", (PyCFunction) Matrix_Transpose, METH_NOARGS, Matrix_Transpose_doc},
-       {"determinant", (PyCFunction) Matrix_Determinant, METH_NOARGS, Matrix_Determinant_doc},
-       {"invert", (PyCFunction) Matrix_Invert, METH_NOARGS, Matrix_Invert_doc},
-       {"translationPart", (PyCFunction) Matrix_TranslationPart, METH_NOARGS, Matrix_TranslationPart_doc},
-       {"rotationPart", (PyCFunction) Matrix_RotationPart, METH_NOARGS, Matrix_RotationPart_doc},
-       {"scalePart", (PyCFunction) Matrix_scalePart, METH_NOARGS, Matrix_scalePart_doc},
-       {"resize4x4", (PyCFunction) Matrix_Resize4x4, METH_NOARGS, Matrix_Resize4x4_doc},
-       {"toEuler", (PyCFunction) Matrix_toEuler, METH_VARARGS, Matrix_toEuler_doc},
-       {"toQuat", (PyCFunction) Matrix_toQuat, METH_NOARGS, Matrix_toQuat_doc},
-       {"copy", (PyCFunction) Matrix_copy, METH_NOARGS, Matrix_copy_doc},
-       {"__copy__", (PyCFunction) Matrix_copy, METH_NOARGS, Matrix_copy_doc},
+       {"zero", (PyCFunction) Matrix_Zero, METH_NOARGS, NULL},
+       {"identity", (PyCFunction) Matrix_Identity, METH_NOARGS, NULL},
+       {"transpose", (PyCFunction) Matrix_Transpose, METH_NOARGS, NULL},
+       {"determinant", (PyCFunction) Matrix_Determinant, METH_NOARGS, NULL},
+       {"invert", (PyCFunction) Matrix_Invert, METH_NOARGS, NULL},
+       {"translationPart", (PyCFunction) Matrix_TranslationPart, METH_NOARGS, NULL},
+       {"rotationPart", (PyCFunction) Matrix_RotationPart, METH_NOARGS, NULL},
+       {"scalePart", (PyCFunction) Matrix_scalePart, METH_NOARGS, NULL},
+       {"resize4x4", (PyCFunction) Matrix_Resize4x4, METH_NOARGS, NULL},
+       {"toEuler", (PyCFunction) Matrix_toEuler, METH_VARARGS, NULL},
+       {"toQuat", (PyCFunction) Matrix_toQuat, METH_NOARGS, NULL},
+       {"copy", (PyCFunction) Matrix_copy, METH_NOARGS, NULL},
+       {"__copy__", (PyCFunction) Matrix_copy, METH_NOARGS, NULL},
        {NULL, NULL, 0, NULL}
 };
 
@@ -158,7 +155,7 @@ static PyObject *Matrix_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
                PyErr_SetString(PyExc_AttributeError, "Mathutils.Matrix(): expects 0-4 numeric sequences of the same size\n");
                return NULL;
        } else if (argSize == 0) { //return empty 4D matrix
-               return (PyObject *) newMatrixObject(NULL, 4, 4, Py_NEW);
+               return (PyObject *) newMatrixObject(NULL, 4, 4, Py_NEW, NULL);
        }else if (argSize == 1){
                //copy constructor for matrix objects
                argObject = PyTuple_GET_ITEM(args, 0);
@@ -167,11 +164,7 @@ static PyObject *Matrix_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
                        if(!BaseMath_ReadCallback(mat))
                                return NULL;
 
-                       argSize = mat->rowSize; //rows
-                       seqSize = mat->colSize; //col
-                       for(i = 0; i < (seqSize * argSize); i++){
-                               matrix[i] = mat->contigPtr[i];
-                       }
+                       memcpy(matrix, mat->contigPtr, sizeof(float) * mat->rowSize * mat->colSize);
                }
        }else{ //2-4 arguments (all seqs? all same size?)
                for(i =0; i < argSize; i++){
@@ -216,7 +209,7 @@ static PyObject *Matrix_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
                        }
                }
        }
-       return newMatrixObject(matrix, argSize, seqSize, Py_NEW);
+       return newMatrixObject(matrix, argSize, seqSize, Py_NEW, NULL);
 }
 
 /*-----------------------------METHODS----------------------------*/
@@ -239,14 +232,16 @@ static PyObject *Matrix_toQuat(MatrixObject * self)
                Mat4ToQuat((float (*)[4])*self->matrix, quat);
        }
        
-       return newQuaternionObject(quat, Py_NEW);
+       return newQuaternionObject(quat, Py_NEW, NULL);
 }
 /*---------------------------Matrix.toEuler() --------------------*/
 PyObject *Matrix_toEuler(MatrixObject * self, PyObject *args)
 {
        float eul[3], eul_compatf[3];
        EulerObject *eul_compat = NULL;
+#ifdef USE_MATHUTILS_DEG
        int x;
+#endif
        
        if(!BaseMath_ReadCallback(self))
                return NULL;
@@ -288,7 +283,7 @@ PyObject *Matrix_toEuler(MatrixObject * self, PyObject *args)
                eul[x] *= (float) (180 / Py_PI);
        }
 #endif
-       return newEulerObject(eul, Py_NEW);
+       return newEulerObject(eul, Py_NEW, NULL);
 }
 /*---------------------------Matrix.resize4x4() ------------------*/
 PyObject *Matrix_Resize4x4(MatrixObject * self)
@@ -364,7 +359,7 @@ PyObject *Matrix_TranslationPart(MatrixObject * self)
        vec[1] = self->matrix[3][1];
        vec[2] = self->matrix[3][2];
 
-       return newVectorObject(vec, 3, Py_NEW);
+       return newVectorObject(vec, 3, Py_NEW, NULL);
 }
 /*---------------------------Matrix.rotationPart() ---------------*/
 PyObject *Matrix_RotationPart(MatrixObject * self)
@@ -390,7 +385,7 @@ PyObject *Matrix_RotationPart(MatrixObject * self)
        mat[7] = self->matrix[2][1];
        mat[8] = self->matrix[2][2];
 
-       return newMatrixObject(mat, 3, 3, Py_NEW);
+       return newMatrixObject(mat, 3, 3, Py_NEW, Py_TYPE(self));
 }
 /*---------------------------Matrix.scalePart() --------------------*/
 PyObject *Matrix_scalePart(MatrixObject * self)
@@ -419,7 +414,7 @@ PyObject *Matrix_scalePart(MatrixObject * self)
        scale[0]= tmat[0][0];
        scale[1]= tmat[1][1];
        scale[2]= tmat[2][2];
-       return newVectorObject(scale, 3, Py_NEW);
+       return newVectorObject(scale, 3, Py_NEW, NULL);
 }
 /*---------------------------Matrix.invert() ---------------------*/
 PyObject *Matrix_Invert(MatrixObject * self)
@@ -589,7 +584,7 @@ PyObject *Matrix_copy(MatrixObject * self)
        if(!BaseMath_ReadCallback(self))
                return NULL;
        
-       return (PyObject*)(MatrixObject*)newMatrixObject((float (*))*self->matrix, self->rowSize, self->colSize, Py_NEW);
+       return (PyObject*)newMatrixObject((float (*))*self->matrix, self->rowSize, self->colSize, Py_NEW, Py_TYPE(self));
 }
 
 /*----------------------------print object (internal)-------------*/
@@ -674,8 +669,7 @@ static PyObject* Matrix_richcmpr(PyObject *objectA, PyObject *objectB, int compa
                Py_RETURN_FALSE;
        }
 }
-/*------------------------tp_doc*/
-static char MatrixObject_doc[] = "This is a wrapper for matrix objects.";
+
 /*---------------------SEQUENCE PROTOCOLS------------------------
   ----------------------------len(object)------------------------
   sequence length*/
@@ -775,8 +769,7 @@ static PyObject *Matrix_slice(MatrixObject * self, int begin, int end)
 }
 /*----------------------------object[z:y]------------------------
   sequence slice (set)*/
-static int Matrix_ass_slice(MatrixObject * self, int begin, int end,
-                            PyObject * seq)
+static int Matrix_ass_slice(MatrixObject * self, int begin, int end, PyObject * seq)
 {
        int i, x, y, size, sub_size = 0;
        float mat[16], f;
@@ -882,7 +875,7 @@ static PyObject *Matrix_add(PyObject * m1, PyObject * m2)
                }
        }
 
-       return newMatrixObject(mat, mat1->rowSize, mat1->colSize, Py_NEW);
+       return newMatrixObject(mat, mat1->rowSize, mat1->colSize, Py_NEW, NULL);
 }
 /*------------------------obj - obj------------------------------
   subtraction*/
@@ -915,7 +908,7 @@ static PyObject *Matrix_sub(PyObject * m1, PyObject * m2)
                }
        }
 
-       return newMatrixObject(mat, mat1->rowSize, mat1->colSize, Py_NEW);
+       return newMatrixObject(mat, mat1->rowSize, mat1->colSize, Py_NEW, NULL);
 }
 /*------------------------obj * obj------------------------------
   mulplication*/
@@ -954,7 +947,7 @@ static PyObject *Matrix_mul(PyObject * m1, PyObject * m2)
                        }
                }
                
-               return newMatrixObject(mat, mat1->rowSize, mat2->colSize, Py_NEW);
+               return newMatrixObject(mat, mat1->rowSize, mat2->colSize, Py_NEW, NULL);
        }
        
        if(mat1==NULL){
@@ -965,7 +958,7 @@ static PyObject *Matrix_mul(PyObject * m1, PyObject * m2)
                                        mat[((x * mat2->colSize) + y)] = scalar * mat2->matrix[x][y];
                                }
                        }
-                       return newMatrixObject(mat, mat2->rowSize, mat2->colSize, Py_NEW);
+                       return newMatrixObject(mat, mat2->rowSize, mat2->colSize, Py_NEW, NULL);
                }
                
                PyErr_SetString(PyExc_TypeError, "Matrix multiplication: arguments not acceptable for this operation");
@@ -984,7 +977,7 @@ static PyObject *Matrix_mul(PyObject * m1, PyObject * m2)
                                                mat[((x * mat1->colSize) + y)] = scalar * mat1->matrix[x][y];
                                        }
                                }
-                               return newMatrixObject(mat, mat1->rowSize, mat1->colSize, Py_NEW);
+                               return newMatrixObject(mat, mat1->rowSize, mat1->colSize, Py_NEW, NULL);
                        }
                }
                PyErr_SetString(PyExc_TypeError, "Matrix multiplication: arguments not acceptable for this operation");
@@ -1004,7 +997,7 @@ static PyObject* Matrix_inv(MatrixObject *self)
 
 /*-----------------PROTOCOL DECLARATIONS--------------------------*/
 static PySequenceMethods Matrix_SeqMethods = {
-       (inquiry) Matrix_len,                                   /* sq_length */
+       (lenfunc) Matrix_len,                                   /* sq_length */
        (binaryfunc) 0,                                                 /* sq_concat */
        (ssizeargfunc) 0,                                                       /* sq_repeat */
        (ssizeargfunc) Matrix_item,                             /* sq_item */
@@ -1012,30 +1005,116 @@ static PySequenceMethods Matrix_SeqMethods = {
        (ssizeobjargproc) Matrix_ass_item,              /* sq_ass_item */
        (ssizessizeobjargproc) Matrix_ass_slice,        /* sq_ass_slice */
 };
+
+
+static PyObject *Matrix_subscript(MatrixObject* self, PyObject* item)
+{
+       if (PyIndex_Check(item)) {
+               Py_ssize_t i;
+               i = PyNumber_AsSsize_t(item, PyExc_IndexError);
+               if (i == -1 && PyErr_Occurred())
+                       return NULL;
+               if (i < 0)
+                       i += self->rowSize;
+               return Matrix_item(self, i);
+       } else if (PySlice_Check(item)) {
+               Py_ssize_t start, stop, step, slicelength;
+
+               if (PySlice_GetIndicesEx((PySliceObject*)item, self->rowSize, &start, &stop, &step, &slicelength) < 0)
+                       return NULL;
+
+               if (slicelength <= 0) {
+                       return PyList_New(0);
+               }
+               else if (step == 1) {
+                       return Matrix_slice(self, start, stop);
+               }
+               else {
+                       PyErr_SetString(PyExc_TypeError, "slice steps not supported with matricies");
+                       return NULL;
+               }
+       }
+       else {
+               PyErr_Format(PyExc_TypeError,
+                            "vector indices must be integers, not %.200s",
+                            item->ob_type->tp_name);
+               return NULL;
+       }
+}
+
+static int Matrix_ass_subscript(MatrixObject* self, PyObject* item, PyObject* value)
+{
+       if (PyIndex_Check(item)) {
+               Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
+               if (i == -1 && PyErr_Occurred())
+                       return -1;
+               if (i < 0)
+                       i += self->rowSize;
+               return Matrix_ass_item(self, i, value);
+       }
+       else if (PySlice_Check(item)) {
+               Py_ssize_t start, stop, step, slicelength;
+
+               if (PySlice_GetIndicesEx((PySliceObject*)item, self->rowSize, &start, &stop, &step, &slicelength) < 0)
+                       return -1;
+
+               if (step == 1)
+                       return Matrix_ass_slice(self, start, stop, value);
+               else {
+                       PyErr_SetString(PyExc_TypeError, "slice steps not supported with matricies");
+                       return -1;
+               }
+       }
+       else {
+               PyErr_Format(PyExc_TypeError,
+                            "matrix indices must be integers, not %.200s",
+                            item->ob_type->tp_name);
+               return -1;
+       }
+}
+
+static PyMappingMethods Matrix_AsMapping = {
+       (lenfunc)Matrix_len,
+       (binaryfunc)Matrix_subscript,
+       (objobjargproc)Matrix_ass_subscript
+};
+
+
 static PyNumberMethods Matrix_NumMethods = {
-       (binaryfunc) Matrix_add,                                /* __add__ */
-       (binaryfunc) Matrix_sub,                                /* __sub__ */
-       (binaryfunc) Matrix_mul,                                /* __mul__ */
-       (binaryfunc) 0,                                                 /* __div__ */
-       (binaryfunc) 0,                                                 /* __mod__ */
-       (binaryfunc) 0,                                                 /* __divmod__ */
-       (ternaryfunc) 0,                                                /* __pow__ */
-       (unaryfunc) 0,                                                  /* __neg__ */
-       (unaryfunc) 0,                                                  /* __pos__ */
-       (unaryfunc) 0,                                                  /* __abs__ */
-       (inquiry) 0,                                                    /* __nonzero__ */
-       (unaryfunc) Matrix_inv,                                 /* __invert__ */
-       (binaryfunc) 0,                                                 /* __lshift__ */
-       (binaryfunc) 0,                                                 /* __rshift__ */
-       (binaryfunc) 0,                                                 /* __and__ */
-       (binaryfunc) 0,                                                 /* __xor__ */
-       (binaryfunc) 0,                                                 /* __or__ */
-       /*(coercion)*/ 0,                                                       /* __coerce__ */
-       (unaryfunc) 0,                                                  /* __int__ */
-       (unaryfunc) 0,                                                  /* __long__ */
-       (unaryfunc) 0,                                                  /* __float__ */
-       (unaryfunc) 0,                                                  /* __oct__ */
-       (unaryfunc) 0,                                                  /* __hex__ */
+               (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 */
 };
 
 static PyObject *Matrix_getRowSize( MatrixObject * self, void *type )
@@ -1062,13 +1141,7 @@ static PyGetSetDef Matrix_getseters[] = {
 
 /*------------------PY_OBECT DEFINITION--------------------------*/
 PyTypeObject matrix_Type = {
-#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
        "matrix",                                               /*tp_name*/
        sizeof(MatrixObject),                   /*tp_basicsize*/
        0,                                                              /*tp_itemsize*/
@@ -1080,15 +1153,15 @@ PyTypeObject matrix_Type = {
        (reprfunc) Matrix_repr,                 /*tp_repr*/
        &Matrix_NumMethods,                             /*tp_as_number*/
        &Matrix_SeqMethods,                             /*tp_as_sequence*/
-       0,                                                              /*tp_as_mapping*/
+       &Matrix_AsMapping,                              /*tp_as_mapping*/
        0,                                                              /*tp_hash*/
        0,                                                              /*tp_call*/
        0,                                                              /*tp_str*/
        0,                                                              /*tp_getattro*/
        0,                                                              /*tp_setattro*/
        0,                                                              /*tp_as_buffer*/
-       Py_TPFLAGS_DEFAULT,                             /*tp_flags*/
-       MatrixObject_doc,                               /*tp_doc*/
+       Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
+       0,                                                              /*tp_doc*/
        0,                                                              /*tp_traverse*/
        0,                                                              /*tp_clear*/
        (richcmpfunc)Matrix_richcmpr,   /*tp_richcompare*/
@@ -1132,7 +1205,7 @@ self->matrix[1][1] = self->contigPtr[4] */
  (i.e. it was allocated elsewhere by MEM_mallocN())
   pass Py_NEW - if vector is not a WRAPPER and managed by PYTHON
  (i.e. it must be created here with PyMEM_malloc())*/
-PyObject *newMatrixObject(float *mat, int rowSize, int colSize, int type)
+PyObject *newMatrixObject(float *mat, int rowSize, int colSize, int type, PyTypeObject *base_type)
 {
        MatrixObject *self;
        int x, row, col;
@@ -1143,7 +1216,9 @@ PyObject *newMatrixObject(float *mat, int rowSize, int colSize, int type)
                return NULL;
        }
 
-       self = PyObject_NEW(MatrixObject, &matrix_Type);
+       if(base_type)   self = (MatrixObject *)base_type->tp_alloc(base_type, 0);
+       else                    self = PyObject_NEW(MatrixObject, &matrix_Type);
+
        self->rowSize = rowSize;
        self->colSize = colSize;
        
@@ -1201,7 +1276,7 @@ PyObject *newMatrixObject(float *mat, int rowSize, int colSize, int type)
 
 PyObject *newMatrixObject_cb(PyObject *cb_user, int rowSize, int colSize, int cb_type, int cb_subtype)
 {
-       MatrixObject *self= (MatrixObject *)newMatrixObject(NULL, rowSize, colSize, Py_NEW);
+       MatrixObject *self= (MatrixObject *)newMatrixObject(NULL, rowSize, colSize, Py_NEW, NULL);
        if(self) {
                Py_INCREF(cb_user);
                self->cb_user=                  cb_user;
@@ -1246,5 +1321,5 @@ static PyObject *column_vector_multiplication(MatrixObject * mat, VectorObject*
                vecNew[z++] = (float)dot;
                dot = 0.0f;
        }
-       return newVectorObject(vecNew, vec->size, Py_NEW);
+       return newVectorObject(vecNew, vec->size, Py_NEW, NULL);
 }