linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] trace-cruncher: Optimize get_arg_list()
@ 2021-10-13 16:56 Yordan Karadzhov (VMware)
  2021-10-13 16:56 ` [PATCH 2/2] trace-cruncher: Modify the APIs for enable/disable multiple events Yordan Karadzhov (VMware)
  0 siblings, 1 reply; 2+ messages in thread
From: Yordan Karadzhov (VMware) @ 2021-10-13 16:56 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: rostedt, warthog9, Yordan Karadzhov (VMware)

The extraction of a 'C' string from a Python list of strings gets
defined as a static method instead of being coded in the body of
'get_arg_list()'. The new static method will be used in following
patches. The error message emitted in the case of an error is
remover since it will never get printed (it is overwritten by the
error messages of the functions calling 'get_arg_list()').

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/ftracepy-utils.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/ftracepy-utils.c b/src/ftracepy-utils.c
index d8115f6..5c8bcca 100644
--- a/src/ftracepy-utils.c
+++ b/src/ftracepy-utils.c
@@ -274,10 +274,19 @@ PyObject *PyTepEvent_get_pid(PyTepEvent* self, PyObject *args,
 	return PyLong_FromLong(pid);
 }
 
+static const char *str_from_list(PyObject *py_list, int i)
+{
+	PyObject *item = PyList_GetItem(py_list, i);
+
+	if (!PyUnicode_Check(item))
+		return NULL;
+
+	return PyUnicode_DATA(item);
+}
+
 static const char **get_arg_list(PyObject *py_list)
 {
 	const char **argv = NULL;
-	PyObject *arg_py;
 	int i, n;
 
 	if (!PyList_CheckExact(py_list))
@@ -286,18 +295,14 @@ static const char **get_arg_list(PyObject *py_list)
 	n = PyList_Size(py_list);
 	argv = calloc(n + 1, sizeof(*argv));
 	for (i = 0; i < n; ++i) {
-		arg_py = PyList_GetItem(py_list, i);
-		if (!PyUnicode_Check(arg_py))
+		argv[i] = str_from_list(py_list, i);
+		if (!argv[i])
 			goto fail;
-
-		argv[i] = PyUnicode_DATA(arg_py);
 	}
 
 	return argv;
 
  fail:
-	PyErr_SetString(TRACECRUNCHER_ERROR,
-			"Failed to parse argument list.");
 	free(argv);
 	return NULL;
 }
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-10-13 16:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-13 16:56 [PATCH 1/2] trace-cruncher: Optimize get_arg_list() Yordan Karadzhov (VMware)
2021-10-13 16:56 ` [PATCH 2/2] trace-cruncher: Modify the APIs for enable/disable multiple events Yordan Karadzhov (VMware)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).