diff mbox series

trace-cruncher: Always use get_instance_from_arg()

Message ID 20211001132253.7851-1-y.karadz@gmail.com (mailing list archive)
State Accepted
Headers show
Series trace-cruncher: Always use get_instance_from_arg() | expand

Commit Message

Yordan Karadzhov Oct. 1, 2021, 1:22 p.m. UTC
Avoid the code duplication in the case when the Python method takes
only a single 'instance' argument.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/ftracepy-utils.c | 36 +++---------------------------------
 1 file changed, 3 insertions(+), 33 deletions(-)
diff mbox series

Patch

diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c
index 7b1ff1b..ca7f914 100644
--- a/src/ftracepy-utils.c
+++ b/src/ftracepy-utils.c
@@ -1889,19 +1889,9 @@  PyObject *PyKprobe_clear_filter(PyKprobe *self, PyObject *args,
 						PyObject *kwargs)
 {
 	struct tracefs_instance *instance;
-	PyObject *py_inst = NULL;
 	char path[PATH_MAX];
 
-	static char *kwlist[] = {"instance", NULL};
-	if (!PyArg_ParseTupleAndKeywords(args,
-					 kwargs,
-					 "|O",
-					 kwlist,
-					 &py_inst)) {
-		return NULL;
-	}
-
-	if (!get_optional_instance(py_inst, &instance))
+	if (!get_instance_from_arg(args, kwargs, &instance))
 		return NULL;
 
 	sprintf(path, "events/%s/%s/filter", TC_SYS, self->ptrObj->event);
@@ -1916,19 +1906,9 @@  PyObject *PyKprobe_clear_filter(PyKprobe *self, PyObject *args,
 static bool enable_kprobe(PyKprobe *self, PyObject *args, PyObject *kwargs,
 			  bool enable)
 {
-	static char *kwlist[] = {"instance", NULL};
 	struct tracefs_instance *instance;
-	PyObject *py_inst = NULL;
-
-	if (!PyArg_ParseTupleAndKeywords(args,
-					 kwargs,
-					 "|O",
-					 kwlist,
-					 &py_inst)) {
-		return false;
-	}
 
-	if (!get_optional_instance(py_inst, &instance))
+	if (!get_instance_from_arg(args, kwargs, &instance))
 		return false;
 
 	return event_enable_disable(instance, TC_SYS, self->ptrObj->event,
@@ -1956,19 +1936,9 @@  PyObject *PyKprobe_disable(PyKprobe *self, PyObject *args,
 PyObject *PyKprobe_is_enabled(PyKprobe *self, PyObject *args,
 					      PyObject *kwargs)
 {
-	static char *kwlist[] = {"instance", NULL};
 	struct tracefs_instance *instance;
-	PyObject *py_inst = NULL;
-
-	if (!PyArg_ParseTupleAndKeywords(args,
-					 kwargs,
-					 "|O",
-					 kwlist,
-					 &py_inst)) {
-		return NULL;
-	}
 
-	if (!get_optional_instance(py_inst, &instance))
+	if (!get_instance_from_arg(args, kwargs, &instance))
 		return NULL;
 
 	return event_is_enabled(instance, TC_SYS, self->ptrObj->event);