Re: [PATCH v7 16/59] perf python: Add syscall name/id to convert syscall number and name

sashiko-bot
2026-04-25T23:15:44Z

Sashiko AI review found 1 potential issue(s):
- [Low] The use of `static char * const kwlist[]` causes a fatal compiler warning (treated as an error) on widely used Python versions.
--

commit 255ac1bdc670015e70083350909742474af1b56e
Author: Ian Rogers <irogers@google.com>

perf python: Add syscall name/id to convert syscall number and name

This commit adds syscalltbl support to the perf python module. It provides
functions to convert between syscall numbers and names using the host
machine's syscall table, removing the dependency on python libaudit.

> diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
> index 1af53480661f..861973144106 100644
> --- a/tools/perf/util/python.c
> +++ b/tools/perf/util/python.c

[ ... ]

> @@ -2669,6 +2671,40 @@ static int pyrf_session__setup_types(void)
> return PyType_Ready(&pyrf_session__type);
> }
>
> +static PyObject *pyrf__syscall_name(PyObject *self, PyObject *args, PyObject *kwargs)
> +{
> + const char *name;
> + int id;
> + int elf_machine = EM_HOST;
> + static char * const kwlist[] = { "id", "elf_machine", NULL };

Does this declaration cause a build failure on older Python versions?

In Python versions up to 3.12, PyArg_ParseTupleAndKeywords() expects the
keywords argument to be char ** (or char *keywords[]). Passing char * const *
drops the const qualifier, which triggers an incompatible-pointer-types warning
in GCC. Since tools/perf builds with -Werror by default, this warning becomes
a fatal build error.

> +
> + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i|$i", kwlist, &id, &elf_machine))
> + return NULL;
> +
> + name = syscalltbl__name(elf_machine, id);
> + if (!name)
> + Py_RETURN_NONE;
> + return PyUnicode_FromString(name);
> +}
> +
> +static PyObject *pyrf__syscall_id(PyObject *self, PyObject *args, PyObject *kwargs)
> +{
> + const char *name;
> + int id;
> + int elf_machine = EM_HOST;
> + static char * const kwlist[] = { "name", "elf_machine", NULL };

Could this declaration also be updated to drop the const qualifier for the
same reason?

> +
> + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|$i", kwlist, &name, &elf_machine))
> + return NULL;
> +
> + id = syscalltbl__id(elf_machine, name);
> + if (id < 0) {
> + PyErr_Format(PyExc_ValueError, "Failed to find syscall %s", name);
> + return NULL;
> + }
> + return PyLong_FromLong(id);
> +}

--
Sashiko AI review · https://sashiko.dev/#/patchset/20260425224951.174663-1-irogers@google.com?part=16