mathutils: refactor instantiation
remove 'type' argument, very few mathutils objects are wrapped, add new function for creating wrapped objects. also fixes unlikely memory leak if the data-array can't be allocated.
This commit is contained in:
@@ -29,11 +29,23 @@
|
||||
|
||||
/* Can cast different mathutils types to this, use for generic funcs */
|
||||
|
||||
#include "BLI_compiler_attrs.h"
|
||||
|
||||
struct DynStr;
|
||||
|
||||
extern char BaseMathObject_is_wrapped_doc[];
|
||||
extern char BaseMathObject_owner_doc[];
|
||||
|
||||
#define BASE_MATH_NEW(struct_name, root_type, base_type) \
|
||||
(struct_name *)((base_type ? (base_type)->tp_alloc(base_type, 0) : _PyObject_GC_New(&(root_type))));
|
||||
|
||||
|
||||
/* BaseMathObject.flag */
|
||||
enum {
|
||||
BASE_MATH_FLAG_IS_WRAP = (1 << 0),
|
||||
};
|
||||
#define BASE_MATH_FLAG_DEFAULT 0
|
||||
|
||||
#define BASE_MATH_MEMBERS(_data) \
|
||||
PyObject_VAR_HEAD \
|
||||
float *_data; /* array of data (alias), wrapped status depends on wrapped status */ \
|
||||
@@ -42,7 +54,7 @@ extern char BaseMathObject_owner_doc[];
|
||||
unsigned char cb_type; /* which user funcs do we adhere to, RNA, GameObject, etc */ \
|
||||
unsigned char cb_subtype; /* subtype: location, rotation... \
|
||||
* to avoid defining many new functions for every attribute of the same type */ \
|
||||
unsigned char wrapped /* wrapped data type? */ \
|
||||
unsigned char flag /* wrapped data type? */ \
|
||||
|
||||
typedef struct {
|
||||
BASE_MATH_MEMBERS(data);
|
||||
@@ -67,9 +79,6 @@ PyMODINIT_FUNC PyInit_mathutils(void);
|
||||
int EXPP_FloatsAreEqual(float A, float B, int floatSteps);
|
||||
int EXPP_VectorsAreEqual(const float *vecA, const float *vecB, int size, int floatSteps);
|
||||
|
||||
#define Py_NEW 1
|
||||
#define Py_WRAP 2
|
||||
|
||||
typedef struct Mathutils_Callback Mathutils_Callback;
|
||||
|
||||
typedef int (*BaseMathCheckFunc)(BaseMathObject *); /* checks the user is still valid */
|
||||
|
||||
Reference in New Issue
Block a user