summaryrefslogtreecommitdiff
path: root/tools/perf/util/python.c
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2026-06-15 18:15:24 -0700
committerNamhyung Kim <namhyung@kernel.org>2026-06-30 10:17:09 -0700
commit01fa2d416aceab51f97ec2769e8da9971a605eeb (patch)
treeea3766f5d47109a73a9283d9fed1cb6338784ad7 /tools/perf/util/python.c
parentfaa0abae75f7116d461415ab268f70cacb736741 (diff)
perf python: Add missed explicit dependencies
Fix missing #include of pmus.h found while cleaning the evsel/evlist header files. Also define PY_SSIZE_T_CLEAN before including Python.h to comply with modern Python 3 C-API requirements, and introduce CHECK_INITIALIZED and CHECK_INITIALIZED_INT safety macros to be used by subsequent patches. Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alice Rogers <alice.mei.rogers@gmail.com> Cc: Dapeng Mi <dapeng1.mi@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@linaro.org> Cc: Leo Yan <leo.yan@linux.dev> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Richter <tmricht@linux.ibm.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Diffstat (limited to 'tools/perf/util/python.c')
-rw-r--r--tools/perf/util/python.c41
1 files changed, 32 insertions, 9 deletions
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index cc1019d29a5d..98a8dd9b673d 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -1,30 +1,37 @@
// SPDX-License-Identifier: GPL-2.0
+#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include <structmember.h>
+
#include <inttypes.h>
-#include <poll.h>
+
#include <linux/err.h>
+#include <poll.h>
+
+#include <internal/lib.h>
#include <perf/cpumap.h>
-#ifdef HAVE_LIBTRACEEVENT
-#include <event-parse.h>
-#endif
#include <perf/mmap.h>
+#include <structmember.h>
+
#include "callchain.h"
#include "counts.h"
+#include "event.h"
#include "evlist.h"
#include "evsel.h"
-#include "event.h"
#include "expr.h"
+#include "metricgroup.h"
+#include "mmap.h"
+#include "pmus.h"
#include "print_binary.h"
#include "record.h"
#include "strbuf.h"
#include "thread_map.h"
#include "tp_pmu.h"
#include "trace-event.h"
-#include "metricgroup.h"
-#include "mmap.h"
#include "util/sample.h"
-#include <internal/lib.h>
+
+#ifdef HAVE_LIBTRACEEVENT
+#include <event-parse.h>
+#endif
PyMODINIT_FUNC PyInit_perf(void);
@@ -38,6 +45,22 @@ PyMODINIT_FUNC PyInit_perf(void);
offsetof(struct pyrf_event, sample) + offsetof(struct perf_sample, member), \
0, help }
+#define CHECK_INITIALIZED(ptr, msg) \
+ do { \
+ if (!(ptr)) { \
+ PyErr_SetString(PyExc_ValueError, msg " not initialized"); \
+ return NULL; \
+ } \
+ } while (0)
+
+#define CHECK_INITIALIZED_INT(ptr, msg) \
+ do { \
+ if (!(ptr)) { \
+ PyErr_SetString(PyExc_ValueError, msg " not initialized"); \
+ return -1; \
+ } \
+ } while (0)
+
struct pyrf_event {
PyObject_HEAD
struct evsel *evsel;