diff mbox series

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

Message ID 20210819130827.12327-3-y.karadz@gmail.com (mailing list archive)
State Accepted
Headers show
Series trace-cruncher: Refactor instances and kprobes | expand

Commit Message

Yordan Karadzhov Aug. 19, 2021, 1:08 p.m. UTC
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@gmail.com>
---
 src/common.h | 5 +++++
 1 file changed, 5 insertions(+)
diff mbox series

Patch

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