diff options
Diffstat (limited to 'tools/perf/scripts/python')
-rw-r--r-- | tools/perf/scripts/python/Perf-Trace-Util/Context.c | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/tools/perf/scripts/python/Perf-Trace-Util/Context.c b/tools/perf/scripts/python/Perf-Trace-Util/Context.c index fcd1dd667906..1a0d27757eec 100644 --- a/tools/perf/scripts/python/Perf-Trace-Util/Context.c +++ b/tools/perf/scripts/python/Perf-Trace-Util/Context.c | |||
@@ -23,7 +23,17 @@ | |||
23 | #include "../../../perf.h" | 23 | #include "../../../perf.h" |
24 | #include "../../../util/trace-event.h" | 24 | #include "../../../util/trace-event.h" |
25 | 25 | ||
26 | #if PY_MAJOR_VERSION < 3 | ||
27 | #define _PyCapsule_GetPointer(arg1, arg2) \ | ||
28 | PyCObject_AsVoidPtr(arg1) | ||
29 | |||
26 | PyMODINIT_FUNC initperf_trace_context(void); | 30 | PyMODINIT_FUNC initperf_trace_context(void); |
31 | #else | ||
32 | #define _PyCapsule_GetPointer(arg1, arg2) \ | ||
33 | PyCapsule_GetPointer((arg1), (arg2)) | ||
34 | |||
35 | PyMODINIT_FUNC PyInit_perf_trace_context(void); | ||
36 | #endif | ||
27 | 37 | ||
28 | static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args) | 38 | static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args) |
29 | { | 39 | { |
@@ -34,7 +44,7 @@ static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args) | |||
34 | if (!PyArg_ParseTuple(args, "O", &context)) | 44 | if (!PyArg_ParseTuple(args, "O", &context)) |
35 | return NULL; | 45 | return NULL; |
36 | 46 | ||
37 | scripting_context = PyCObject_AsVoidPtr(context); | 47 | scripting_context = _PyCapsule_GetPointer(context, NULL); |
38 | retval = common_pc(scripting_context); | 48 | retval = common_pc(scripting_context); |
39 | 49 | ||
40 | return Py_BuildValue("i", retval); | 50 | return Py_BuildValue("i", retval); |
@@ -50,7 +60,7 @@ static PyObject *perf_trace_context_common_flags(PyObject *obj, | |||
50 | if (!PyArg_ParseTuple(args, "O", &context)) | 60 | if (!PyArg_ParseTuple(args, "O", &context)) |
51 | return NULL; | 61 | return NULL; |
52 | 62 | ||
53 | scripting_context = PyCObject_AsVoidPtr(context); | 63 | scripting_context = _PyCapsule_GetPointer(context, NULL); |
54 | retval = common_flags(scripting_context); | 64 | retval = common_flags(scripting_context); |
55 | 65 | ||
56 | return Py_BuildValue("i", retval); | 66 | return Py_BuildValue("i", retval); |
@@ -66,7 +76,7 @@ static PyObject *perf_trace_context_common_lock_depth(PyObject *obj, | |||
66 | if (!PyArg_ParseTuple(args, "O", &context)) | 76 | if (!PyArg_ParseTuple(args, "O", &context)) |
67 | return NULL; | 77 | return NULL; |
68 | 78 | ||
69 | scripting_context = PyCObject_AsVoidPtr(context); | 79 | scripting_context = _PyCapsule_GetPointer(context, NULL); |
70 | retval = common_lock_depth(scripting_context); | 80 | retval = common_lock_depth(scripting_context); |
71 | 81 | ||
72 | return Py_BuildValue("i", retval); | 82 | return Py_BuildValue("i", retval); |
@@ -82,7 +92,25 @@ static PyMethodDef ContextMethods[] = { | |||
82 | { NULL, NULL, 0, NULL} | 92 | { NULL, NULL, 0, NULL} |
83 | }; | 93 | }; |
84 | 94 | ||
95 | #if PY_MAJOR_VERSION < 3 | ||
85 | PyMODINIT_FUNC initperf_trace_context(void) | 96 | PyMODINIT_FUNC initperf_trace_context(void) |
86 | { | 97 | { |
87 | (void) Py_InitModule("perf_trace_context", ContextMethods); | 98 | (void) Py_InitModule("perf_trace_context", ContextMethods); |
88 | } | 99 | } |
100 | #else | ||
101 | PyMODINIT_FUNC PyInit_perf_trace_context(void) | ||
102 | { | ||
103 | static struct PyModuleDef moduledef = { | ||
104 | PyModuleDef_HEAD_INIT, | ||
105 | "perf_trace_context", /* m_name */ | ||
106 | "", /* m_doc */ | ||
107 | -1, /* m_size */ | ||
108 | ContextMethods, /* m_methods */ | ||
109 | NULL, /* m_reload */ | ||
110 | NULL, /* m_traverse */ | ||
111 | NULL, /* m_clear */ | ||
112 | NULL, /* m_free */ | ||
113 | }; | ||
114 | return PyModule_Create(&moduledef); | ||
115 | } | ||
116 | #endif | ||