treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / tools / perf / scripts / python / Perf-Trace-Util / Context.c
blob0b709684799182102098a7648956f996dd571b12
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Context.c. Python interfaces for perf script.
5 * Copyright (C) 2010 Tom Zanussi <tzanussi@gmail.com>
6 */
8 #include <Python.h>
9 #include "../../../util/trace-event.h"
11 #if PY_MAJOR_VERSION < 3
12 #define _PyCapsule_GetPointer(arg1, arg2) \
13 PyCObject_AsVoidPtr(arg1)
15 PyMODINIT_FUNC initperf_trace_context(void);
16 #else
17 #define _PyCapsule_GetPointer(arg1, arg2) \
18 PyCapsule_GetPointer((arg1), (arg2))
20 PyMODINIT_FUNC PyInit_perf_trace_context(void);
21 #endif
23 static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args)
25 static struct scripting_context *scripting_context;
26 PyObject *context;
27 int retval;
29 if (!PyArg_ParseTuple(args, "O", &context))
30 return NULL;
32 scripting_context = _PyCapsule_GetPointer(context, NULL);
33 retval = common_pc(scripting_context);
35 return Py_BuildValue("i", retval);
38 static PyObject *perf_trace_context_common_flags(PyObject *obj,
39 PyObject *args)
41 static struct scripting_context *scripting_context;
42 PyObject *context;
43 int retval;
45 if (!PyArg_ParseTuple(args, "O", &context))
46 return NULL;
48 scripting_context = _PyCapsule_GetPointer(context, NULL);
49 retval = common_flags(scripting_context);
51 return Py_BuildValue("i", retval);
54 static PyObject *perf_trace_context_common_lock_depth(PyObject *obj,
55 PyObject *args)
57 static struct scripting_context *scripting_context;
58 PyObject *context;
59 int retval;
61 if (!PyArg_ParseTuple(args, "O", &context))
62 return NULL;
64 scripting_context = _PyCapsule_GetPointer(context, NULL);
65 retval = common_lock_depth(scripting_context);
67 return Py_BuildValue("i", retval);
70 static PyMethodDef ContextMethods[] = {
71 { "common_pc", perf_trace_context_common_pc, METH_VARARGS,
72 "Get the common preempt count event field value."},
73 { "common_flags", perf_trace_context_common_flags, METH_VARARGS,
74 "Get the common flags event field value."},
75 { "common_lock_depth", perf_trace_context_common_lock_depth,
76 METH_VARARGS, "Get the common lock depth event field value."},
77 { NULL, NULL, 0, NULL}
80 #if PY_MAJOR_VERSION < 3
81 PyMODINIT_FUNC initperf_trace_context(void)
83 (void) Py_InitModule("perf_trace_context", ContextMethods);
85 #else
86 PyMODINIT_FUNC PyInit_perf_trace_context(void)
88 static struct PyModuleDef moduledef = {
89 PyModuleDef_HEAD_INIT,
90 "perf_trace_context", /* m_name */
91 "", /* m_doc */
92 -1, /* m_size */
93 ContextMethods, /* m_methods */
94 NULL, /* m_reload */
95 NULL, /* m_traverse */
96 NULL, /* m_clear */
97 NULL, /* m_free */
99 return PyModule_Create(&moduledef);
101 #endif