We already have APIs for attaching/detaching an object from/to the 'ftracepy' module. For the sake of completeness we have to add an API that checks if the object is attached. Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@xxxxxxxxx> --- src/ftracepy-utils.c | 22 ++++++++++++++++++++++ src/ftracepy-utils.h | 2 ++ src/ftracepy.c | 5 +++++ 3 files changed, 29 insertions(+) diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c index 1b1f350..aac31a4 100644 --- a/src/ftracepy-utils.c +++ b/src/ftracepy-utils.c @@ -1037,6 +1037,28 @@ PyObject *PyFtrace_attach(PyObject *self, PyObject *args, PyObject *kwargs) return set_destroy(args, kwargs, true); } +static bool get_destroy_flag(PyObject *py_obj) +{ + PyFtrace_Object_HEAD *obj_head = (PyFtrace_Object_HEAD *)py_obj; + return obj_head->destroy; +} + +PyObject *PyFtrace_is_attached(PyObject *self, PyObject *args, PyObject *kwargs) +{ + static char *kwlist[] = {"object", NULL}; + PyObject *py_obj; + + if (!PyArg_ParseTupleAndKeywords(args, + kwargs, + "O", + kwlist, + &py_obj)) { + return NULL; + } + + return get_destroy_flag(py_obj) ? Py_True : Py_False; +} + static char aname_pool[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; diff --git a/src/ftracepy-utils.h b/src/ftracepy-utils.h index d09c8bf..fc5016c 100644 --- a/src/ftracepy-utils.h +++ b/src/ftracepy-utils.h @@ -125,6 +125,8 @@ PyObject *PyFtrace_detach(PyObject *self, PyObject *args, PyObject *kwargs); PyObject *PyFtrace_attach(PyObject *self, PyObject *args, PyObject *kwargs); +PyObject *PyFtrace_is_attached(PyObject *self, PyObject *args, PyObject *kwargs); + PyObject *PyFtrace_create_instance(PyObject *self, PyObject *args, PyObject *kwargs); diff --git a/src/ftracepy.c b/src/ftracepy.c index b270b71..f59bd4c 100644 --- a/src/ftracepy.c +++ b/src/ftracepy.c @@ -237,6 +237,11 @@ static PyMethodDef ftracepy_methods[] = { METH_VARARGS | METH_KEYWORDS, "Attach object to the \'ftracepy\' module." }, + {"is_attached", + (PyCFunction) PyFtrace_is_attached, + METH_VARARGS | METH_KEYWORDS, + "Check if the object is attached to the \'ftracepy\' module." + }, {"create_instance", (PyCFunction) PyFtrace_create_instance, METH_VARARGS | METH_KEYWORDS, -- 2.32.0