All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
To: linux-trace-devel@vger.kernel.org
Cc: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
Subject: [PATCH v2 2/7] trace-cruncher: Add type checking for the custom Python types
Date: Thu, 19 Aug 2021 16:08:22 +0300	[thread overview]
Message-ID: <20210819130827.12327-3-y.karadz@gmail.com> (raw)
In-Reply-To: <20210819130827.12327-1-y.karadz@gmail.com>

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 --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


  parent reply	other threads:[~2021-08-19 13:08 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-19 13:08 [PATCH v2 0/7] trace-cruncher: Refactor instances and kprobes Yordan Karadzhov (VMware)
2021-08-19 13:08 ` [PATCH v2 1/7] trace-cruncher: Use proper naming in common.h Yordan Karadzhov (VMware)
2021-08-19 13:08 ` Yordan Karadzhov (VMware) [this message]
2021-08-19 13:08 ` [PATCH v2 3/7] trace-cruncher: Allow for detachable custom objects Yordan Karadzhov (VMware)
2021-08-19 13:08 ` [PATCH v2 4/7] trace-cruncher: Define Python type for instances Yordan Karadzhov (VMware)
2021-08-19 13:08 ` [PATCH v2 5/7] trace-cruncher: Refactor the way libtracefs instances are handled Yordan Karadzhov (VMware)
2021-08-19 13:08 ` [PATCH v2 6/7] trace-cruncher: Define Python type for kprobes Yordan Karadzhov (VMware)
2021-08-19 13:08 ` [PATCH v2 7/7] trace-cruncher: Refactor the way kprobes are handled Yordan Karadzhov (VMware)
2021-08-19 19:54 ` [PATCH v2 0/7] trace-cruncher: Refactor instances and kprobes Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210819130827.12327-3-y.karadz@gmail.com \
    --to=y.karadz@gmail.com \
    --cc=linux-trace-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.