forked from bartvdbraak/blender
revert part of own commit r35117 which modified mathutils initialization functions, found this could be done in a better way which doesnt have to deal with partly initialize instances being freed.
This commit is contained in:
parent
b357033f5e
commit
fbd9364944
@ -341,11 +341,8 @@ void BaseMathObject_dealloc(BaseMathObject *self)
|
|||||||
{
|
{
|
||||||
/* only free non wrapped */
|
/* only free non wrapped */
|
||||||
if(self->wrapped != Py_WRAP) {
|
if(self->wrapped != Py_WRAP) {
|
||||||
/* the ONLY time this should be NULL is when the value failed to initialize */
|
|
||||||
if(self->data) {
|
|
||||||
PyMem_Free(self->data);
|
PyMem_Free(self->data);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
BaseMathObject_clear(self);
|
BaseMathObject_clear(self);
|
||||||
|
|
||||||
|
@ -58,7 +58,6 @@ typedef struct {
|
|||||||
PyObject *BaseMathObject_getOwner( BaseMathObject * self, void * );
|
PyObject *BaseMathObject_getOwner( BaseMathObject * self, void * );
|
||||||
PyObject *BaseMathObject_getWrapped( BaseMathObject *self, void * );
|
PyObject *BaseMathObject_getWrapped( BaseMathObject *self, void * );
|
||||||
|
|
||||||
|
|
||||||
int BaseMathObject_traverse(BaseMathObject *self, visitproc visit, void *arg);
|
int BaseMathObject_traverse(BaseMathObject *self, visitproc visit, void *arg);
|
||||||
int BaseMathObject_clear(BaseMathObject *self);
|
int BaseMathObject_clear(BaseMathObject *self);
|
||||||
void BaseMathObject_dealloc(BaseMathObject * self);
|
void BaseMathObject_dealloc(BaseMathObject * self);
|
||||||
|
@ -509,31 +509,6 @@ PyTypeObject color_Type = {
|
|||||||
(i.e. it was allocated elsewhere by MEM_mallocN())
|
(i.e. it was allocated elsewhere by MEM_mallocN())
|
||||||
pass Py_NEW - if vector is not a WRAPPER and managed by PYTHON
|
pass Py_NEW - if vector is not a WRAPPER and managed by PYTHON
|
||||||
(i.e. it must be created here with PyMEM_malloc())*/
|
(i.e. it must be created here with PyMEM_malloc())*/
|
||||||
static int newColorObject_init(ColorObject *self, float *col, int type)
|
|
||||||
{
|
|
||||||
if(type == Py_WRAP) {
|
|
||||||
self->col = col;
|
|
||||||
self->wrapped = Py_WRAP;
|
|
||||||
}
|
|
||||||
else if (type == Py_NEW) {
|
|
||||||
self->col = PyMem_Malloc(COLOR_SIZE * sizeof(float));
|
|
||||||
if(col) {
|
|
||||||
copy_v3_v3(self->col, col);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
zero_v3(self->col);
|
|
||||||
}
|
|
||||||
|
|
||||||
self->wrapped = Py_NEW;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PyObject *newColorObject(float *col, int type, PyTypeObject *base_type)
|
PyObject *newColorObject(float *col, int type, PyTypeObject *base_type)
|
||||||
{
|
{
|
||||||
ColorObject *self;
|
ColorObject *self;
|
||||||
@ -541,34 +516,41 @@ PyObject *newColorObject(float *col, int type, PyTypeObject *base_type)
|
|||||||
self= base_type ? (ColorObject *)base_type->tp_alloc(base_type, 0) :
|
self= base_type ? (ColorObject *)base_type->tp_alloc(base_type, 0) :
|
||||||
(ColorObject *)PyObject_GC_New(ColorObject, &color_Type);
|
(ColorObject *)PyObject_GC_New(ColorObject, &color_Type);
|
||||||
|
|
||||||
|
if(self) {
|
||||||
/* init callbacks as NULL */
|
/* init callbacks as NULL */
|
||||||
self->cb_user= NULL;
|
self->cb_user= NULL;
|
||||||
self->cb_type= self->cb_subtype= 0;
|
self->cb_type= self->cb_subtype= 0;
|
||||||
((BaseMathObject *)self)->data= NULL; /* incase of error */
|
|
||||||
|
|
||||||
if(newColorObject_init(self, col, type) == -1) {
|
if(type == Py_WRAP){
|
||||||
Py_DECREF(self);
|
self->col = col;
|
||||||
|
self->wrapped = Py_WRAP;
|
||||||
|
}
|
||||||
|
else if (type == Py_NEW){
|
||||||
|
self->col = PyMem_Malloc(COLOR_SIZE * sizeof(float));
|
||||||
|
if(col)
|
||||||
|
copy_v3_v3(self->col, col);
|
||||||
|
else
|
||||||
|
zero_v3(self->col);
|
||||||
|
|
||||||
|
self->wrapped = Py_NEW;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PyErr_SetString(PyExc_RuntimeError, "Color(): invalid type");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *newColorObject_cb(PyObject *cb_user, int cb_type, int cb_subtype)
|
PyObject *newColorObject_cb(PyObject *cb_user, int cb_type, int cb_subtype)
|
||||||
{
|
{
|
||||||
ColorObject *self;
|
ColorObject *self= (ColorObject *)newColorObject(NULL, Py_NEW, NULL);
|
||||||
|
if(self) {
|
||||||
self= (ColorObject *)PyObject_GC_New(ColorObject, &color_Type);
|
|
||||||
|
|
||||||
Py_INCREF(cb_user);
|
Py_INCREF(cb_user);
|
||||||
self->cb_user= cb_user;
|
self->cb_user= cb_user;
|
||||||
self->cb_type= (unsigned char)cb_type;
|
self->cb_type= (unsigned char)cb_type;
|
||||||
self->cb_subtype= (unsigned char)cb_subtype;
|
self->cb_subtype= (unsigned char)cb_subtype;
|
||||||
((BaseMathObject *)self)->data= NULL; /* incase of error */
|
|
||||||
|
|
||||||
if(newColorObject_init(self, NULL, Py_NEW) == -1) {
|
|
||||||
Py_DECREF(self);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
|
@ -642,8 +642,18 @@ PyTypeObject euler_Type = {
|
|||||||
(i.e. it was allocated elsewhere by MEM_mallocN())
|
(i.e. it was allocated elsewhere by MEM_mallocN())
|
||||||
pass Py_NEW - if vector is not a WRAPPER and managed by PYTHON
|
pass Py_NEW - if vector is not a WRAPPER and managed by PYTHON
|
||||||
(i.e. it must be created here with PyMEM_malloc())*/
|
(i.e. it must be created here with PyMEM_malloc())*/
|
||||||
static int newEulerObject_init(EulerObject *self, float *eul, short order, int type)
|
PyObject *newEulerObject(float *eul, short order, int type, PyTypeObject *base_type)
|
||||||
{
|
{
|
||||||
|
EulerObject *self;
|
||||||
|
|
||||||
|
self= base_type ? (EulerObject *)base_type->tp_alloc(base_type, 0) :
|
||||||
|
(EulerObject *)PyObject_GC_New(EulerObject, &euler_Type);
|
||||||
|
|
||||||
|
if(self) {
|
||||||
|
/* init callbacks as NULL */
|
||||||
|
self->cb_user= NULL;
|
||||||
|
self->cb_type= self->cb_subtype= 0;
|
||||||
|
|
||||||
if(type == Py_WRAP) {
|
if(type == Py_WRAP) {
|
||||||
self->eul = eul;
|
self->eul = eul;
|
||||||
self->wrapped = Py_WRAP;
|
self->wrapped = Py_WRAP;
|
||||||
@ -656,33 +666,15 @@ static int newEulerObject_init(EulerObject *self, float *eul, short order, int t
|
|||||||
else {
|
else {
|
||||||
zero_v3(self->eul);
|
zero_v3(self->eul);
|
||||||
}
|
}
|
||||||
|
|
||||||
self->wrapped = Py_NEW;
|
self->wrapped = Py_NEW;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PyErr_SetString(PyExc_RuntimeError, "invalid type");
|
PyErr_SetString(PyExc_RuntimeError, "Euler(): invalid type");
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
self->order= order;
|
self->order= order;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
PyObject *newEulerObject(float *eul, short order, int type, PyTypeObject *base_type)
|
|
||||||
{
|
|
||||||
EulerObject *self;
|
|
||||||
|
|
||||||
self= base_type ? (EulerObject *)base_type->tp_alloc(base_type, 0) :
|
|
||||||
(EulerObject *)PyObject_GC_New(EulerObject, &euler_Type);
|
|
||||||
|
|
||||||
/* init callbacks as NULL */
|
|
||||||
self->cb_user= NULL;
|
|
||||||
self->cb_type= self->cb_subtype= 0;
|
|
||||||
((BaseMathObject *)self)->data= NULL; /* incase of error */
|
|
||||||
|
|
||||||
if(newEulerObject_init(self, eul, order, type) == -1) {
|
|
||||||
Py_DECREF(self);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
@ -690,19 +682,12 @@ PyObject *newEulerObject(float *eul, short order, int type, PyTypeObject *base_t
|
|||||||
|
|
||||||
PyObject *newEulerObject_cb(PyObject *cb_user, short order, int cb_type, int cb_subtype)
|
PyObject *newEulerObject_cb(PyObject *cb_user, short order, int cb_type, int cb_subtype)
|
||||||
{
|
{
|
||||||
EulerObject *self;
|
EulerObject *self= (EulerObject *)newEulerObject(NULL, order, Py_NEW, NULL);
|
||||||
|
if(self) {
|
||||||
self= (EulerObject *)PyObject_GC_New(VectorObject, &vector_Type);
|
|
||||||
|
|
||||||
Py_INCREF(cb_user);
|
Py_INCREF(cb_user);
|
||||||
self->cb_user= cb_user;
|
self->cb_user= cb_user;
|
||||||
self->cb_type= (unsigned char)cb_type;
|
self->cb_type= (unsigned char)cb_type;
|
||||||
self->cb_subtype= (unsigned char)cb_subtype;
|
self->cb_subtype= (unsigned char)cb_subtype;
|
||||||
((BaseMathObject *)self)->data= NULL; /* incase of error */
|
|
||||||
|
|
||||||
if(newEulerObject_init(self, NULL, order, Py_NEW) == -1) {
|
|
||||||
Py_DECREF(self);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
|
@ -1820,19 +1820,28 @@ self->matrix[1][1] = self->contigPtr[4] */
|
|||||||
(i.e. it was allocated elsewhere by MEM_mallocN())
|
(i.e. it was allocated elsewhere by MEM_mallocN())
|
||||||
pass Py_NEW - if vector is not a WRAPPER and managed by PYTHON
|
pass Py_NEW - if vector is not a WRAPPER and managed by PYTHON
|
||||||
(i.e. it must be created here with PyMEM_malloc())*/
|
(i.e. it must be created here with PyMEM_malloc())*/
|
||||||
static int newMatrixObject_init(MatrixObject *self, float *mat, const unsigned short rowSize, const unsigned short colSize, int type)
|
PyObject *newMatrixObject(float *mat, const unsigned short rowSize, const unsigned short colSize, int type, PyTypeObject *base_type)
|
||||||
{
|
{
|
||||||
|
MatrixObject *self;
|
||||||
int x, row, col;
|
int x, row, col;
|
||||||
|
|
||||||
/*matrix objects can be any 2-4row x 2-4col matrix*/
|
/*matrix objects can be any 2-4row x 2-4col matrix*/
|
||||||
if(rowSize < 2 || rowSize > 4 || colSize < 2 || colSize > 4) {
|
if(rowSize < 2 || rowSize > 4 || colSize < 2 || colSize > 4) {
|
||||||
PyErr_SetString(PyExc_RuntimeError, "matrix(): row and column sizes must be between 2 and 4");
|
PyErr_SetString(PyExc_RuntimeError, "matrix(): row and column sizes must be between 2 and 4");
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self= base_type ? (MatrixObject *)base_type->tp_alloc(base_type, 0) :
|
||||||
|
(MatrixObject *)PyObject_GC_New(MatrixObject, &matrix_Type);
|
||||||
|
|
||||||
|
if(self) {
|
||||||
self->row_size = rowSize;
|
self->row_size = rowSize;
|
||||||
self->col_size = colSize;
|
self->col_size = colSize;
|
||||||
|
|
||||||
|
/* init callbacks as NULL */
|
||||||
|
self->cb_user= NULL;
|
||||||
|
self->cb_type= self->cb_subtype= 0;
|
||||||
|
|
||||||
if(type == Py_WRAP){
|
if(type == Py_WRAP){
|
||||||
self->contigPtr = mat;
|
self->contigPtr = mat;
|
||||||
/*pointer array points to contigous memory*/
|
/*pointer array points to contigous memory*/
|
||||||
@ -1845,7 +1854,7 @@ static int newMatrixObject_init(MatrixObject *self, float *mat, const unsigned s
|
|||||||
self->contigPtr = PyMem_Malloc(rowSize * colSize * sizeof(float));
|
self->contigPtr = PyMem_Malloc(rowSize * colSize * sizeof(float));
|
||||||
if(self->contigPtr == NULL) { /*allocation failure*/
|
if(self->contigPtr == NULL) { /*allocation failure*/
|
||||||
PyErr_SetString(PyExc_MemoryError, "matrix(): problem allocating pointer space");
|
PyErr_SetString(PyExc_MemoryError, "matrix(): problem allocating pointer space");
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
/*pointer array points to contigous memory*/
|
/*pointer array points to contigous memory*/
|
||||||
for(x = 0; x < rowSize; x++) {
|
for(x = 0; x < rowSize; x++) {
|
||||||
@ -1866,50 +1875,21 @@ static int newMatrixObject_init(MatrixObject *self, float *mat, const unsigned s
|
|||||||
self->wrapped = Py_NEW;
|
self->wrapped = Py_NEW;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PyErr_SetString(PyExc_RuntimeError, "invalid type");
|
PyErr_SetString(PyExc_RuntimeError, "Matrix(): invalid type");
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PyObject *newMatrixObject(float *mat, const unsigned short rowSize, const unsigned short colSize, int type, PyTypeObject *base_type)
|
|
||||||
{
|
|
||||||
MatrixObject *self;
|
|
||||||
|
|
||||||
self= base_type ? (MatrixObject *)base_type->tp_alloc(base_type, 0) :
|
|
||||||
(MatrixObject *)PyObject_GC_New(MatrixObject, &matrix_Type);
|
|
||||||
|
|
||||||
/* init callbacks as NULL */
|
|
||||||
self->cb_user= NULL;
|
|
||||||
self->cb_type= self->cb_subtype= 0;
|
|
||||||
((BaseMathObject *)self)->data= NULL; /* incase of error */
|
|
||||||
|
|
||||||
if(newMatrixObject_init(self, mat, rowSize, colSize, type) == -1) {
|
|
||||||
Py_DECREF(self);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return (PyObject *) self;
|
return (PyObject *) self;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *newMatrixObject_cb(PyObject *cb_user, int rowSize, int colSize, int cb_type, int cb_subtype)
|
PyObject *newMatrixObject_cb(PyObject *cb_user, int rowSize, int colSize, int cb_type, int cb_subtype)
|
||||||
{
|
{
|
||||||
MatrixObject *self;
|
MatrixObject *self= (MatrixObject *)newMatrixObject(NULL, rowSize, colSize, Py_NEW, NULL);
|
||||||
|
if(self) {
|
||||||
self= PyObject_GC_New(MatrixObject, &matrix_Type);
|
|
||||||
|
|
||||||
Py_INCREF(cb_user);
|
Py_INCREF(cb_user);
|
||||||
self->cb_user= cb_user;
|
self->cb_user= cb_user;
|
||||||
self->cb_type= (unsigned char)cb_type;
|
self->cb_type= (unsigned char)cb_type;
|
||||||
self->cb_subtype= (unsigned char)cb_subtype;
|
self->cb_subtype= (unsigned char)cb_subtype;
|
||||||
((BaseMathObject *)self)->data= NULL; /* incase of error */
|
|
||||||
|
|
||||||
if(newMatrixObject_init(self, NULL, rowSize, colSize, Py_NEW) == -1) {
|
|
||||||
Py_DECREF(self);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (PyObject *) self;
|
return (PyObject *) self;
|
||||||
}
|
}
|
||||||
|
@ -1078,30 +1078,6 @@ PyTypeObject quaternion_Type = {
|
|||||||
(i.e. it was allocated elsewhere by MEM_mallocN())
|
(i.e. it was allocated elsewhere by MEM_mallocN())
|
||||||
pass Py_NEW - if vector is not a WRAPPER and managed by PYTHON
|
pass Py_NEW - if vector is not a WRAPPER and managed by PYTHON
|
||||||
(i.e. it must be created here with PyMEM_malloc())*/
|
(i.e. it must be created here with PyMEM_malloc())*/
|
||||||
static int newQuaternionObject_init(QuaternionObject *self, float *quat, int type)
|
|
||||||
{
|
|
||||||
if(type == Py_WRAP){
|
|
||||||
self->quat = quat;
|
|
||||||
self->wrapped = Py_WRAP;
|
|
||||||
}
|
|
||||||
else if (type == Py_NEW){
|
|
||||||
self->quat = PyMem_Malloc(QUAT_SIZE * sizeof(float));
|
|
||||||
if(quat) {
|
|
||||||
QUATCOPY(self->quat, quat);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
unit_qt(self->quat);
|
|
||||||
}
|
|
||||||
self->wrapped = Py_NEW;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
PyErr_SetString(PyExc_RuntimeError, "invalid type");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
PyObject *newQuaternionObject(float *quat, int type, PyTypeObject *base_type)
|
PyObject *newQuaternionObject(float *quat, int type, PyTypeObject *base_type)
|
||||||
{
|
{
|
||||||
QuaternionObject *self;
|
QuaternionObject *self;
|
||||||
@ -1109,35 +1085,40 @@ PyObject *newQuaternionObject(float *quat, int type, PyTypeObject *base_type)
|
|||||||
self= base_type ? (QuaternionObject *)base_type->tp_alloc(base_type, 0) :
|
self= base_type ? (QuaternionObject *)base_type->tp_alloc(base_type, 0) :
|
||||||
(QuaternionObject *)PyObject_GC_New(QuaternionObject, &quaternion_Type);
|
(QuaternionObject *)PyObject_GC_New(QuaternionObject, &quaternion_Type);
|
||||||
|
|
||||||
|
if(self) {
|
||||||
/* init callbacks as NULL */
|
/* init callbacks as NULL */
|
||||||
self->cb_user= NULL;
|
self->cb_user= NULL;
|
||||||
self->cb_type= self->cb_subtype= 0;
|
self->cb_type= self->cb_subtype= 0;
|
||||||
((BaseMathObject *)self)->data= NULL; /* incase of error */
|
|
||||||
|
|
||||||
if(newQuaternionObject_init(self, quat, type) == -1) {
|
if(type == Py_WRAP){
|
||||||
Py_DECREF(self);
|
self->quat = quat;
|
||||||
|
self->wrapped = Py_WRAP;
|
||||||
|
}
|
||||||
|
else if (type == Py_NEW){
|
||||||
|
self->quat = PyMem_Malloc(QUAT_SIZE * sizeof(float));
|
||||||
|
if(!quat) { //new empty
|
||||||
|
unit_qt(self->quat);
|
||||||
|
}else{
|
||||||
|
QUATCOPY(self->quat, quat);
|
||||||
|
}
|
||||||
|
self->wrapped = Py_NEW;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
PyErr_SetString(PyExc_RuntimeError, "Quaternion(): invalid type");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return (PyObject *) self;
|
return (PyObject *) self;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *newQuaternionObject_cb(PyObject *cb_user, int cb_type, int cb_subtype)
|
PyObject *newQuaternionObject_cb(PyObject *cb_user, int cb_type, int cb_subtype)
|
||||||
{
|
{
|
||||||
QuaternionObject *self;
|
QuaternionObject *self= (QuaternionObject *)newQuaternionObject(NULL, Py_NEW, NULL);
|
||||||
|
if(self) {
|
||||||
self= PyObject_GC_New(QuaternionObject, &quaternion_Type);
|
|
||||||
|
|
||||||
Py_INCREF(cb_user);
|
Py_INCREF(cb_user);
|
||||||
self->cb_user= cb_user;
|
self->cb_user= cb_user;
|
||||||
self->cb_type= (unsigned char)cb_type;
|
self->cb_type= (unsigned char)cb_type;
|
||||||
self->cb_subtype= (unsigned char)cb_subtype;
|
self->cb_subtype= (unsigned char)cb_subtype;
|
||||||
((BaseMathObject *)self)->data= NULL; /* incase of error */
|
|
||||||
|
|
||||||
if(newQuaternionObject_init(self, NULL, Py_NEW) == -1) {
|
|
||||||
Py_DECREF(self);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
|
@ -2215,15 +2215,25 @@ PyTypeObject vector_Type = {
|
|||||||
(i.e. it was allocated elsewhere by MEM_mallocN())
|
(i.e. it was allocated elsewhere by MEM_mallocN())
|
||||||
pass Py_NEW - if vector is not a WRAPPER and managed by PYTHON
|
pass Py_NEW - if vector is not a WRAPPER and managed by PYTHON
|
||||||
(i.e. it must be created here with PyMEM_malloc())*/
|
(i.e. it must be created here with PyMEM_malloc())*/
|
||||||
static int newVectorObject_init(VectorObject *self, float *vec, const int size, const short type)
|
PyObject *newVectorObject(float *vec, const int size, const int type, PyTypeObject *base_type)
|
||||||
{
|
{
|
||||||
|
VectorObject *self;
|
||||||
|
|
||||||
if(size > 4 || size < 2) {
|
if(size > 4 || size < 2) {
|
||||||
PyErr_SetString(PyExc_RuntimeError, "invalid size");
|
PyErr_SetString(PyExc_RuntimeError, "Vector(): invalid size");
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self= base_type ? (VectorObject *)base_type->tp_alloc(base_type, 0) :
|
||||||
|
(VectorObject *)PyObject_GC_New(VectorObject, &vector_Type);
|
||||||
|
|
||||||
|
if(self) {
|
||||||
self->size = size;
|
self->size = size;
|
||||||
|
|
||||||
|
/* init callbacks as NULL */
|
||||||
|
self->cb_user= NULL;
|
||||||
|
self->cb_type= self->cb_subtype= 0;
|
||||||
|
|
||||||
if(type == Py_WRAP) {
|
if(type == Py_WRAP) {
|
||||||
self->vec = vec;
|
self->vec = vec;
|
||||||
self->wrapped = Py_WRAP;
|
self->wrapped = Py_WRAP;
|
||||||
@ -2242,48 +2252,22 @@ static int newVectorObject_init(VectorObject *self, float *vec, const int size,
|
|||||||
self->wrapped = Py_NEW;
|
self->wrapped = Py_NEW;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PyErr_SetString(PyExc_RuntimeError, "invalid type");
|
PyErr_SetString(PyExc_RuntimeError, "Vector(): invalid type");
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PyObject *newVectorObject(float *vec, const int size, const short type, PyTypeObject *base_type)
|
|
||||||
{
|
|
||||||
VectorObject *self;
|
|
||||||
|
|
||||||
self= base_type ? (VectorObject *)base_type->tp_alloc(base_type, 0) :
|
|
||||||
(VectorObject *)PyObject_GC_New(VectorObject, &vector_Type);
|
|
||||||
|
|
||||||
self->cb_user= NULL;
|
|
||||||
self->cb_type= self->cb_subtype= 0;
|
|
||||||
((BaseMathObject *)self)->data= NULL; /* incase of error */
|
|
||||||
|
|
||||||
if(newVectorObject_init(self, vec, size, type) == -1) {
|
|
||||||
Py_DECREF(self);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return (PyObject *) self;
|
return (PyObject *) self;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *newVectorObject_cb(PyObject *cb_user, int size, int cb_type, int cb_subtype)
|
PyObject *newVectorObject_cb(PyObject *cb_user, int size, int cb_type, int cb_subtype)
|
||||||
{
|
{
|
||||||
VectorObject *self;
|
float dummy[4] = {0.0, 0.0, 0.0, 0.0}; /* dummy init vector, callbacks will be used on access */
|
||||||
|
VectorObject *self= (VectorObject *)newVectorObject(dummy, size, Py_NEW, NULL);
|
||||||
self= PyObject_GC_New(VectorObject, &vector_Type);
|
if(self) {
|
||||||
|
|
||||||
Py_INCREF(cb_user);
|
Py_INCREF(cb_user);
|
||||||
self->cb_user= cb_user;
|
self->cb_user= cb_user;
|
||||||
self->cb_type= (unsigned char)cb_type;
|
self->cb_type= (unsigned char)cb_type;
|
||||||
self->cb_subtype= (unsigned char)cb_subtype;
|
self->cb_subtype= (unsigned char)cb_subtype;
|
||||||
((BaseMathObject *)self)->data= NULL; /* incase of error */
|
|
||||||
|
|
||||||
if(newVectorObject_init(self, NULL, size, Py_NEW) == -1) {
|
|
||||||
Py_DECREF(self);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
|
@ -41,7 +41,7 @@ typedef struct {
|
|||||||
} VectorObject;
|
} VectorObject;
|
||||||
|
|
||||||
/*prototypes*/
|
/*prototypes*/
|
||||||
PyObject *newVectorObject(float *vec, const int size, const short type, PyTypeObject *base_type);
|
PyObject *newVectorObject(float *vec, const int size, const int type, PyTypeObject *base_type);
|
||||||
PyObject *newVectorObject_cb(PyObject *user, int size, int callback_type, int subtype);
|
PyObject *newVectorObject_cb(PyObject *user, int size, int callback_type, int subtype);
|
||||||
|
|
||||||
#endif /* MATHUTILS_VECTOR_H */
|
#endif /* MATHUTILS_VECTOR_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user