PyAPI: add function to check any mathutils type
authorCampbell Barton <ideasman42@gmail.com>
Wed, 29 Nov 2017 05:09:46 +0000 (16:09 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 29 Nov 2017 05:13:26 +0000 (16:13 +1100)
Also add CheckExact versions of type checking macros.

source/blender/python/mathutils/mathutils.h
source/blender/python/mathutils/mathutils_Color.h
source/blender/python/mathutils/mathutils_Euler.h
source/blender/python/mathutils/mathutils_Matrix.h
source/blender/python/mathutils/mathutils_Quaternion.h
source/blender/python/mathutils/mathutils_Vector.h
source/blender/python/mathutils/mathutils_bvhtree.h

index d1fb6dcdb82157d76b661be53cf56094171fa999..ec927a9e31614c4adcd5404eddf54ce352014bf3 100644 (file)
@@ -78,6 +78,10 @@ typedef struct {
 #include "mathutils_Euler.h"
 #include "mathutils_Color.h"
 
 #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 *);
 PyObject *BaseMathObject_owner_get(BaseMathObject *self, void *);
 PyObject *BaseMathObject_is_wrapped_get(BaseMathObject *self, void *);
 PyObject *BaseMathObject_is_frozen_get(BaseMathObject *self, void *);
index 1290f73da62bd1195fc64a27f5347ab0b7ed0fbe..e1a392de3da895c66f220d66974645841ac31c50 100644 (file)
@@ -30,7 +30,8 @@
 #define __MATHUTILS_COLOR_H__
 
 extern PyTypeObject color_Type;
 #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);
 
 typedef struct {
        BASE_MATH_MEMBERS(col);
index 744f39faed1fe9ae5dc1eae5b4040e483763dd34..4f5ba76b8dfb245de485a503a604f1234cf0437c 100644 (file)
@@ -29,7 +29,8 @@
  */
 
 extern PyTypeObject euler_Type;
  */
 
 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);
 
 typedef struct {
        BASE_MATH_MEMBERS(eul);
index 9c84716d3072d53a406fc75cbf69b99c913d0b5b..d2fbe6a04d58331502c2b5b110f76f711b11336b 100644 (file)
 
 extern PyTypeObject matrix_Type;
 extern PyTypeObject matrix_access_Type;
 
 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) */
 #define MATRIX_MAX_DIM 4
 
 /* matrix[row][col] == MATRIX_ITEM_INDEX(matrix, row, col) */
index 66ee3362906d3b5401c69cce4b1f83d329a8a227..46f305b0f0ee8341120ff29b4c1e27e8549c9537 100644 (file)
@@ -28,7 +28,9 @@
  */
 
 extern PyTypeObject quaternion_Type;
  */
 
 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);
 
 typedef struct {
        BASE_MATH_MEMBERS(quat);
index 74ca3336f4bd13b3bf3a46ba4d86ac57a1acf64c..9ebf9457f2b2eb32dc21137df4b2cc2c68260481 100644 (file)
@@ -29,7 +29,9 @@
 #define __MATHUTILS_VECTOR_H__
 
 extern PyTypeObject vector_Type;
 #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);
 
 typedef struct {
        BASE_MATH_MEMBERS(vec);
index 634556d68f7c65f69863e5a205fee4c80c4ffad2..445a393b93edab1932212b180e71932d1cfeb64d 100644 (file)
@@ -30,7 +30,7 @@ PyMODINIT_FUNC PyInit_mathutils_bvhtree(void);
 
 extern PyTypeObject PyBVHTree_Type;
 
 
 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__ */
 #define PyBVHTree_CheckExact(v)  (Py_TYPE(v) == &PyBVHTree_Type)
 
 #endif /* __MATHUTILS_BVHTREE_H__ */