diff options
Diffstat (limited to 'tools/perf/util/scripting-engines/trace-event-python.c')
-rw-r--r-- | tools/perf/util/scripting-engines/trace-event-python.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 87ef16a1b17e..7059d1be2d09 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c | |||
@@ -733,8 +733,7 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample, | |||
733 | Py_FatalError("couldn't create Python dictionary"); | 733 | Py_FatalError("couldn't create Python dictionary"); |
734 | 734 | ||
735 | pydict_set_item_string_decref(dict, "ev_name", _PyUnicode_FromString(perf_evsel__name(evsel))); | 735 | pydict_set_item_string_decref(dict, "ev_name", _PyUnicode_FromString(perf_evsel__name(evsel))); |
736 | pydict_set_item_string_decref(dict, "attr", _PyUnicode_FromStringAndSize( | 736 | pydict_set_item_string_decref(dict, "attr", _PyBytes_FromStringAndSize((const char *)&evsel->attr, sizeof(evsel->attr))); |
737 | (const char *)&evsel->attr, sizeof(evsel->attr))); | ||
738 | 737 | ||
739 | pydict_set_item_string_decref(dict_sample, "pid", | 738 | pydict_set_item_string_decref(dict_sample, "pid", |
740 | _PyLong_FromLong(sample->pid)); | 739 | _PyLong_FromLong(sample->pid)); |
@@ -1494,34 +1493,40 @@ static void _free_command_line(wchar_t **command_line, int num) | |||
1494 | static int python_start_script(const char *script, int argc, const char **argv) | 1493 | static int python_start_script(const char *script, int argc, const char **argv) |
1495 | { | 1494 | { |
1496 | struct tables *tables = &tables_global; | 1495 | struct tables *tables = &tables_global; |
1496 | PyMODINIT_FUNC (*initfunc)(void); | ||
1497 | #if PY_MAJOR_VERSION < 3 | 1497 | #if PY_MAJOR_VERSION < 3 |
1498 | const char **command_line; | 1498 | const char **command_line; |
1499 | #else | 1499 | #else |
1500 | wchar_t **command_line; | 1500 | wchar_t **command_line; |
1501 | #endif | 1501 | #endif |
1502 | char buf[PATH_MAX]; | 1502 | /* |
1503 | * Use a non-const name variable to cope with python 2.6's | ||
1504 | * PyImport_AppendInittab prototype | ||
1505 | */ | ||
1506 | char buf[PATH_MAX], name[19] = "perf_trace_context"; | ||
1503 | int i, err = 0; | 1507 | int i, err = 0; |
1504 | FILE *fp; | 1508 | FILE *fp; |
1505 | 1509 | ||
1506 | #if PY_MAJOR_VERSION < 3 | 1510 | #if PY_MAJOR_VERSION < 3 |
1511 | initfunc = initperf_trace_context; | ||
1507 | command_line = malloc((argc + 1) * sizeof(const char *)); | 1512 | command_line = malloc((argc + 1) * sizeof(const char *)); |
1508 | command_line[0] = script; | 1513 | command_line[0] = script; |
1509 | for (i = 1; i < argc + 1; i++) | 1514 | for (i = 1; i < argc + 1; i++) |
1510 | command_line[i] = argv[i - 1]; | 1515 | command_line[i] = argv[i - 1]; |
1511 | #else | 1516 | #else |
1517 | initfunc = PyInit_perf_trace_context; | ||
1512 | command_line = malloc((argc + 1) * sizeof(wchar_t *)); | 1518 | command_line = malloc((argc + 1) * sizeof(wchar_t *)); |
1513 | command_line[0] = Py_DecodeLocale(script, NULL); | 1519 | command_line[0] = Py_DecodeLocale(script, NULL); |
1514 | for (i = 1; i < argc + 1; i++) | 1520 | for (i = 1; i < argc + 1; i++) |
1515 | command_line[i] = Py_DecodeLocale(argv[i - 1], NULL); | 1521 | command_line[i] = Py_DecodeLocale(argv[i - 1], NULL); |
1516 | #endif | 1522 | #endif |
1517 | 1523 | ||
1524 | PyImport_AppendInittab(name, initfunc); | ||
1518 | Py_Initialize(); | 1525 | Py_Initialize(); |
1519 | 1526 | ||
1520 | #if PY_MAJOR_VERSION < 3 | 1527 | #if PY_MAJOR_VERSION < 3 |
1521 | initperf_trace_context(); | ||
1522 | PySys_SetArgv(argc + 1, (char **)command_line); | 1528 | PySys_SetArgv(argc + 1, (char **)command_line); |
1523 | #else | 1529 | #else |
1524 | PyInit_perf_trace_context(); | ||
1525 | PySys_SetArgv(argc + 1, command_line); | 1530 | PySys_SetArgv(argc + 1, command_line); |
1526 | #endif | 1531 | #endif |
1527 | 1532 | ||