[PATCH] trace-cruncher: Always use get_instance_from_arg()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 src/ftracepy-utils.c | 36 +++---------------------------------
 1 file changed, 3 insertions(+), 33 deletions(-)

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);
-- 
2.30.2




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux