Simplify perf-trace-context module functions by factoring out some common code.
Showing the changes to tools/perf/scripts/python (1 of 1 file). Show all
Unified · Split
| @@ -20,51 +20,46 @@ PyMODINIT_FUNC initperf_trace_context(void); · 19 unmodified lines | |||
| 20 | PyMODINIT_FUNC PyInit_perf_trace_context(void); | 20 | PyMODINIT_FUNC PyInit_perf_trace_context(void); |
| 21 | #endif | 21 | #endif |
| 22 | 22 | ||
| 23 | static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args) | 23 | static struct scripting_context *get_scripting_context(PyObject *args) |
| 24 | { | 24 | { |
| 25 | struct scripting_context *scripting_context; | ||
| 26 | PyObject *context; | 25 | PyObject *context; |
| 27 | int retval; | ||
| 28 | 26 | ||
| 29 | if (!PyArg_ParseTuple(args, "O", &context)) | 27 | if (!PyArg_ParseTuple(args, "O", &context)) |
| 30 | return NULL; | 28 | return NULL; |
| 31 | 29 | ||
| 32 | scripting_context = _PyCapsule_GetPointer(context, NULL); | 30 | return _PyCapsule_GetPointer(context, NULL); |
| 33 | retval = common_pc(scripting_context); | 31 | } |
| 32 | |||
| 33 | static PyObject *perf_trace_context_common_pc(PyObject *obj, PyObject *args) | ||
| 34 | { | ||
| 35 | struct scripting_context *c = get_scripting_context(args); | ||
| 36 | |||
| 37 | if (!c) | ||
| 38 | return NULL; | ||
| 34 | 39 | ||
| 35 | return Py_BuildValue("i", retval); | 40 | return Py_BuildValue("i", common_pc(c)); |
| 36 | } | 41 | } |
| 37 | 42 | ||
| 38 | static PyObject *perf_trace_context_common_flags(PyObject *obj, | 43 | static PyObject *perf_trace_context_common_flags(PyObject *obj, |
| 39 | PyObject *args) | 44 | PyObject *args) |
| 40 | { | 45 | { |
| 41 | struct scripting_context *scripting_context; | 46 | struct scripting_context *c = get_scripting_context(args); |
| 42 | PyObject *context; | ||
| 43 | int retval; | ||
| 44 | 47 | ||
| 45 | if (!PyArg_ParseTuple(args, "O", &context)) | 48 | if (!c) |
| 46 | return NULL; | 49 | return NULL; |
| 47 | 50 | ||
| 48 | scripting_context = _PyCapsule_GetPointer(context, NULL); | 51 | return Py_BuildValue("i", common_flags(c)); |
| 49 | retval = common_flags(scripting_context); | ||
| 50 | |||
| 51 | return Py_BuildValue("i", retval); | ||
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | static PyObject *perf_trace_context_common_lock_depth(PyObject *obj, | 54 | static PyObject *perf_trace_context_common_lock_depth(PyObject *obj, |
| 55 | PyObject *args) | 55 | PyObject *args) |
| 56 | { | 56 | { |
| 57 | struct scripting_context *scripting_context; | 57 | struct scripting_context *c = get_scripting_context(args); |
| 58 | PyObject *context; | ||
| 59 | int retval; | ||
| 60 | 58 | ||
| 61 | if (!PyArg_ParseTuple(args, "O", &context)) | 59 | if (!c) |
| 62 | return NULL; | 60 | return NULL; |
| 63 | 61 | ||
| 64 | scripting_context = _PyCapsule_GetPointer(context, NULL); | 62 | return Py_BuildValue("i", common_lock_depth(c)); |
| 65 | retval = common_lock_depth(scripting_context); | ||
| 66 | |||
| 67 | return Py_BuildValue("i", retval); | ||
| 68 | } | 63 | } |
| 69 | 64 | ||
| 70 | static PyMethodDef ContextMethods[] = { | 65 | static PyMethodDef ContextMethods[] = { |