* [PATCH 1/1 v6.17] perf python: Stop using deprecated PyUnicode_AsString()
@ 2025-07-30 13:34 Arnaldo Carvalho de Melo
2025-08-01 17:24 ` Namhyung Kim
0 siblings, 1 reply; 2+ messages in thread
From: Arnaldo Carvalho de Melo @ 2025-07-30 13:34 UTC (permalink / raw)
To: Namhyung Kim
Cc: Adrian Hunter, Ian Rogers, James Clark, Jiri Olsa, Kan Liang,
Linux Kernel Mailing List, linux-perf-users
As noticed while building for Fedora 43:
GEN /tmp/build/perf/python/perf.cpython-314-x86_64-linux-gnu.so
/git/perf-6.16.0-rc3/tools/perf/util/python.c: In function ‘get_tracepoint_field’:
/git/perf-6.16.0-rc3/tools/perf/util/python.c:340:9: error: ‘_PyUnicode_AsString’ is deprecated [-Werror=deprecated-declarations]
340 | const char *str = _PyUnicode_AsString(PyObject_Str(attr_name));
| ^~~~~
In file included from /usr/include/python3.14/unicodeobject.h:1022,
from /usr/include/python3.14/Python.h:89,
from /git/perf-6.16.0-rc3/tools/perf/util/python.c:2:
/usr/include/python3.14/cpython/unicodeobject.h:648:1: note: declared here
648 | _PyUnicode_AsString(PyObject *unicode)
| ^~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
error: command '/usr/bin/gcc' failed with exit code 1
Use PyUnicode_AsUTF8() instead and also check if PyObject_Str() fails
before doing so.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/python.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index 2f28f71325a87a2d..ea77bea0306fa08d 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -337,7 +337,6 @@ tracepoint_field(const struct pyrf_event *pe, struct tep_format_field *field)
static PyObject*
get_tracepoint_field(struct pyrf_event *pevent, PyObject *attr_name)
{
- const char *str = _PyUnicode_AsString(PyObject_Str(attr_name));
struct evsel *evsel = pevent->evsel;
struct tep_event *tp_format = evsel__tp_format(evsel);
struct tep_format_field *field;
@@ -345,7 +344,18 @@ get_tracepoint_field(struct pyrf_event *pevent, PyObject *attr_name)
if (IS_ERR_OR_NULL(tp_format))
return NULL;
+ PyObject *obj = PyObject_Str(attr_name);
+ if (obj == NULL)
+ return NULL;
+
+ const char *str = PyUnicode_AsUTF8(obj);
+ if (str == NULL) {
+ Py_DECREF(obj);
+ return NULL;
+ }
+
field = tep_find_any_field(tp_format, str);
+ Py_DECREF(obj);
return field ? tracepoint_field(pevent, field) : NULL;
}
#endif /* HAVE_LIBTRACEEVENT */
--
2.50.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 1/1 v6.17] perf python: Stop using deprecated PyUnicode_AsString()
2025-07-30 13:34 [PATCH 1/1 v6.17] perf python: Stop using deprecated PyUnicode_AsString() Arnaldo Carvalho de Melo
@ 2025-08-01 17:24 ` Namhyung Kim
0 siblings, 0 replies; 2+ messages in thread
From: Namhyung Kim @ 2025-08-01 17:24 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Adrian Hunter, Ian Rogers, James Clark, Jiri Olsa, Kan Liang,
Linux Kernel Mailing List, linux-perf-users
On Wed, 30 Jul 2025 10:34:20 -0300, Arnaldo Carvalho de Melo wrote:
> As noticed while building for Fedora 43:
>
> GEN /tmp/build/perf/python/perf.cpython-314-x86_64-linux-gnu.so
> /git/perf-6.16.0-rc3/tools/perf/util/python.c: In function ‘get_tracepoint_field’:
> /git/perf-6.16.0-rc3/tools/perf/util/python.c:340:9: error: ‘_PyUnicode_AsString’ is deprecated [-Werror=deprecated-declarations]
> 340 | const char *str = _PyUnicode_AsString(PyObject_Str(attr_name));
> | ^~~~~
> In file included from /usr/include/python3.14/unicodeobject.h:1022,
> from /usr/include/python3.14/Python.h:89,
> from /git/perf-6.16.0-rc3/tools/perf/util/python.c:2:
> /usr/include/python3.14/cpython/unicodeobject.h:648:1: note: declared here
> 648 | _PyUnicode_AsString(PyObject *unicode)
> | ^~~~~~~~~~~~~~~~~~~
> cc1: all warnings being treated as errors
> error: command '/usr/bin/gcc' failed with exit code 1
>
> [...]
Applied to perf-tools-next, thanks!
Best regards,
Namhyung
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-08-01 17:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-30 13:34 [PATCH 1/1 v6.17] perf python: Stop using deprecated PyUnicode_AsString() Arnaldo Carvalho de Melo
2025-08-01 17:24 ` Namhyung Kim
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).