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:
@@ -1078,30 +1078,6 @@ PyTypeObject quaternion_Type = {
|
||||
(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())*/
|
||||
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)
|
||||
{
|
||||
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) :
|
||||
(QuaternionObject *)PyObject_GC_New(QuaternionObject, &quaternion_Type);
|
||||
|
||||
if(self) {
|
||||
/* init callbacks as NULL */
|
||||
self->cb_user= NULL;
|
||||
self->cb_type= self->cb_subtype= 0;
|
||||
|
||||
/* init callbacks as NULL */
|
||||
self->cb_user= NULL;
|
||||
self->cb_type= self->cb_subtype= 0;
|
||||
((BaseMathObject *)self)->data= NULL; /* incase of error */
|
||||
|
||||
if(newQuaternionObject_init(self, quat, type) == -1) {
|
||||
Py_DECREF(self);
|
||||
return NULL;
|
||||
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) { //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 (PyObject *) self;
|
||||
}
|
||||
|
||||
PyObject *newQuaternionObject_cb(PyObject *cb_user, int cb_type, int cb_subtype)
|
||||
{
|
||||
QuaternionObject *self;
|
||||
|
||||
self= PyObject_GC_New(QuaternionObject, &quaternion_Type);
|
||||
|
||||
Py_INCREF(cb_user);
|
||||
self->cb_user= cb_user;
|
||||
self->cb_type= (unsigned char)cb_type;
|
||||
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;
|
||||
QuaternionObject *self= (QuaternionObject *)newQuaternionObject(NULL, Py_NEW, NULL);
|
||||
if(self) {
|
||||
Py_INCREF(cb_user);
|
||||
self->cb_user= cb_user;
|
||||
self->cb_type= (unsigned char)cb_type;
|
||||
self->cb_subtype= (unsigned char)cb_subtype;
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
|
Reference in New Issue
Block a user