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