Message ID | 20210817164110.152016-2-y.karadz@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | [1/4] trace-cruncher: Use proper naming in common.h | 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(+)