[PATCH v2 2/7] trace-cruncher: Add type checking for the custom Python types

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The new method checks if an object has a Python type that matches
the type defined in the C extension module.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@xxxxxxxxx>
---
 src/common.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/common.h b/src/common.h
index 6046c0f..fa64696 100644
--- a/src/common.h
+++ b/src/common.h
@@ -65,6 +65,7 @@ static inline void no_free()
 } py_type;									\
 PyObject *py_type##_New(struct c_type *c_ptr);					\
 bool py_type##TypeInit();							\
+bool py_type##_Check(PyObject *obj);						\
 
 #define  C_OBJECT_WRAPPER(c_type, py_type, ptr_free)				\
 static PyTypeObject py_type##Type = {						\
@@ -101,5 +102,9 @@ bool py_type##TypeInit()							\
 	Py_INCREF(&py_type##Type);						\
 	return true;								\
 }										\
+bool py_type##_Check(PyObject *obj)						\
+{										\
+	return (obj->ob_type == &py_type##Type) ? true : false;			\
+}										\
 
 #endif
-- 
2.30.2




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux