From: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
To: linux-trace-devel@vger.kernel.org
Cc: rostedt@goodmis.org, warthog9@eaglescrag.net,
"Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
Subject: [PATCH 1/2] trace-cruncher: Optimize get_arg_list()
Date: Wed, 13 Oct 2021 19:56:27 +0300 [thread overview]
Message-ID: <20211013165628.76149-1-y.karadz@gmail.com> (raw)
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
next reply other threads:[~2021-10-13 16:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-13 16:56 Yordan Karadzhov (VMware) [this message]
2021-10-13 16:56 ` [PATCH 2/2] trace-cruncher: Modify the APIs for enable/disable multiple events Yordan Karadzhov (VMware)
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=20211013165628.76149-1-y.karadz@gmail.com \
--to=y.karadz@gmail.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=warthog9@eaglescrag.net \
/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 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).