From c17c6557b4ea4bfeb4528b74703795798aedaa66 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 29 Nov 2017 16:09:46 +1100 Subject: PyAPI: add function to check any mathutils type Also add CheckExact versions of type checking macros. --- source/blender/python/mathutils/mathutils.h | 4 ++++ source/blender/python/mathutils/mathutils_Color.h | 3 ++- source/blender/python/mathutils/mathutils_Euler.h | 3 ++- source/blender/python/mathutils/mathutils_Matrix.h | 5 ++++- source/blender/python/mathutils/mathutils_Quaternion.h | 4 +++- source/blender/python/mathutils/mathutils_Vector.h | 4 +++- source/blender/python/mathutils/mathutils_bvhtree.h | 2 +- 7 files changed, 19 insertions(+), 6 deletions(-) (limited to 'source/blender/python') diff --git a/source/blender/python/mathutils/mathutils.h b/source/blender/python/mathutils/mathutils.h index d1fb6dcdb82..ec927a9e316 100644 --- a/source/blender/python/mathutils/mathutils.h +++ b/source/blender/python/mathutils/mathutils.h @@ -78,6 +78,10 @@ typedef struct { #include "mathutils_Euler.h" #include "mathutils_Color.h" +/* avoid checking all types */ +#define BaseMathObject_CheckExact(v) \ + (Py_TYPE(v)->tp_dealloc == (destructor)BaseMathObject_dealloc) + PyObject *BaseMathObject_owner_get(BaseMathObject *self, void *); PyObject *BaseMathObject_is_wrapped_get(BaseMathObject *self, void *); PyObject *BaseMathObject_is_frozen_get(BaseMathObject *self, void *); diff --git a/source/blender/python/mathutils/mathutils_Color.h b/source/blender/python/mathutils/mathutils_Color.h index 1290f73da62..e1a392de3da 100644 --- a/source/blender/python/mathutils/mathutils_Color.h +++ b/source/blender/python/mathutils/mathutils_Color.h @@ -30,7 +30,8 @@ #define __MATHUTILS_COLOR_H__ extern PyTypeObject color_Type; -#define ColorObject_Check(_v) PyObject_TypeCheck((_v), &color_Type) +#define ColorObject_Check(v) PyObject_TypeCheck((v), &color_Type) +#define ColorObject_CheckExact(v) (Py_TYPE(v) == &color_Type) typedef struct { BASE_MATH_MEMBERS(col); diff --git a/source/blender/python/mathutils/mathutils_Euler.h b/source/blender/python/mathutils/mathutils_Euler.h index 744f39faed1..4f5ba76b8df 100644 --- a/source/blender/python/mathutils/mathutils_Euler.h +++ b/source/blender/python/mathutils/mathutils_Euler.h @@ -29,7 +29,8 @@ */ extern PyTypeObject euler_Type; -#define EulerObject_Check(_v) PyObject_TypeCheck((_v), &euler_Type) +#define EulerObject_Check(v) PyObject_TypeCheck((v), &euler_Type) +#define EulerObject_CheckExact(v) (Py_TYPE(v) == &euler_Type) typedef struct { BASE_MATH_MEMBERS(eul); diff --git a/source/blender/python/mathutils/mathutils_Matrix.h b/source/blender/python/mathutils/mathutils_Matrix.h index 9c84716d307..d2fbe6a04d5 100644 --- a/source/blender/python/mathutils/mathutils_Matrix.h +++ b/source/blender/python/mathutils/mathutils_Matrix.h @@ -30,7 +30,10 @@ extern PyTypeObject matrix_Type; extern PyTypeObject matrix_access_Type; -#define MatrixObject_Check(_v) PyObject_TypeCheck((_v), &matrix_Type) + +#define MatrixObject_Check(v) PyObject_TypeCheck((v), &matrix_Type) +#define MatrixObject_CheckExact(v) (Py_TYPE(v) == &matrix_Type) + #define MATRIX_MAX_DIM 4 /* matrix[row][col] == MATRIX_ITEM_INDEX(matrix, row, col) */ diff --git a/source/blender/python/mathutils/mathutils_Quaternion.h b/source/blender/python/mathutils/mathutils_Quaternion.h index 66ee3362906..46f305b0f0e 100644 --- a/source/blender/python/mathutils/mathutils_Quaternion.h +++ b/source/blender/python/mathutils/mathutils_Quaternion.h @@ -28,7 +28,9 @@ */ extern PyTypeObject quaternion_Type; -#define QuaternionObject_Check(_v) PyObject_TypeCheck((_v), &quaternion_Type) + +#define QuaternionObject_Check(v) PyObject_TypeCheck((v), &quaternion_Type) +#define QuaternionObject_CheckExact(v) (Py_TYPE(v) == &quaternion_Type) typedef struct { BASE_MATH_MEMBERS(quat); diff --git a/source/blender/python/mathutils/mathutils_Vector.h b/source/blender/python/mathutils/mathutils_Vector.h index 74ca3336f4b..9ebf9457f2b 100644 --- a/source/blender/python/mathutils/mathutils_Vector.h +++ b/source/blender/python/mathutils/mathutils_Vector.h @@ -29,7 +29,9 @@ #define __MATHUTILS_VECTOR_H__ extern PyTypeObject vector_Type; -#define VectorObject_Check(_v) PyObject_TypeCheck((_v), &vector_Type) + +#define VectorObject_Check(v) PyObject_TypeCheck((v), &vector_Type) +#define VectorObject_CheckExact(v) (Py_TYPE(v) == &vector_Type) typedef struct { BASE_MATH_MEMBERS(vec); diff --git a/source/blender/python/mathutils/mathutils_bvhtree.h b/source/blender/python/mathutils/mathutils_bvhtree.h index 634556d68f7..445a393b93e 100644 --- a/source/blender/python/mathutils/mathutils_bvhtree.h +++ b/source/blender/python/mathutils/mathutils_bvhtree.h @@ -30,7 +30,7 @@ PyMODINIT_FUNC PyInit_mathutils_bvhtree(void); extern PyTypeObject PyBVHTree_Type; -#define PyBVHTree_Check(_v) PyObject_TypeCheck((_v), &PyBVHTree_Type) +#define PyBVHTree_Check(v) PyObject_TypeCheck((v), &PyBVHTree_Type) #define PyBVHTree_CheckExact(v) (Py_TYPE(v) == &PyBVHTree_Type) #endif /* __MATHUTILS_BVHTREE_H__ */ -- cgit v1.2.3