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 | 20 | PyMODINIT_FUNC PyInit_perf_trace_context(void); |
| 21 | 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 | 25 | PyObject *context; |
| 27 | − int retval; | |
| 28 | 26 | |
| 29 | 27 | if (!PyArg_ParseTuple(args, "O", &context)) |
| 30 | 28 | return NULL; |
| 31 | 29 | |
| 32 | − scripting_context = _PyCapsule_GetPointer(context, NULL); | |
| 33 | − retval = common_pc(scripting_context); | |
| 30 | + return _PyCapsule_GetPointer(context, NULL); | |
| 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 | 43 | static PyObject *perf_trace_context_common_flags(PyObject *obj, |
| 39 | 44 | PyObject *args) |
| 40 | 45 | { |
| 41 | − struct scripting_context *scripting_context; | |
| 42 | − PyObject *context; | |
| 43 | − int retval; | |
| 46 | + struct scripting_context *c = get_scripting_context(args); | |
| 44 | 47 | |
| 45 | − if (!PyArg_ParseTuple(args, "O", &context)) | |
| 48 | + if (!c) | |
| 46 | 49 | return NULL; |
| 47 | 50 | |
| 48 | − scripting_context = _PyCapsule_GetPointer(context, NULL); | |
| 49 | − retval = common_flags(scripting_context); | |
| 50 | − | |
| 51 | − return Py_BuildValue("i", retval); | |
| 51 | + return Py_BuildValue("i", common_flags(c)); | |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | static PyObject *perf_trace_context_common_lock_depth(PyObject *obj, |
| 55 | 55 | PyObject *args) |
| 56 | 56 | { |
| 57 | − struct scripting_context *scripting_context; | |
| 58 | − PyObject *context; | |
| 59 | − int retval; | |
| 57 | + struct scripting_context *c = get_scripting_context(args); | |
| 60 | 58 | |
| 61 | − if (!PyArg_ParseTuple(args, "O", &context)) | |
| 59 | + if (!c) | |
| 62 | 60 | return NULL; |
| 63 | 61 | |
| 64 | − scripting_context = _PyCapsule_GetPointer(context, NULL); | |
| 65 | − retval = common_lock_depth(scripting_context); | |
| 66 | − | |
| 67 | − return Py_BuildValue("i", retval); | |
| 62 | + return Py_BuildValue("i", common_lock_depth(c)); | |
| 68 | 63 | } |
| 69 | 64 | |
| 70 | 65 | static PyMethodDef ContextMethods[] = { |