aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/scripting-engines/trace-event-python.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/scripting-engines/trace-event-python.c')
-rw-r--r--tools/perf/util/scripting-engines/trace-event-python.c12
1 files changed, 9 insertions, 3 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..315905c748fa 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -1494,34 +1494,40 @@ static void _free_command_line(wchar_t **command_line, int num)
1494static int python_start_script(const char *script, int argc, const char **argv) 1494static int python_start_script(const char *script, int argc, const char **argv)
1495{ 1495{
1496 struct tables *tables = &tables_global; 1496 struct tables *tables = &tables_global;
1497 PyMODINIT_FUNC (*initfunc)(void);
1497#if PY_MAJOR_VERSION < 3 1498#if PY_MAJOR_VERSION < 3
1498 const char **command_line; 1499 const char **command_line;
1499#else 1500#else
1500 wchar_t **command_line; 1501 wchar_t **command_line;
1501#endif 1502#endif
1502 char buf[PATH_MAX]; 1503 /*
1504 * Use a non-const name variable to cope with python 2.6's
1505 * PyImport_AppendInittab prototype
1506 */
1507 char buf[PATH_MAX], name[19] = "perf_trace_context";
1503 int i, err = 0; 1508 int i, err = 0;
1504 FILE *fp; 1509 FILE *fp;
1505 1510
1506#if PY_MAJOR_VERSION < 3 1511#if PY_MAJOR_VERSION < 3
1512 initfunc = initperf_trace_context;
1507 command_line = malloc((argc + 1) * sizeof(const char *)); 1513 command_line = malloc((argc + 1) * sizeof(const char *));
1508 command_line[0] = script; 1514 command_line[0] = script;
1509 for (i = 1; i < argc + 1; i++) 1515 for (i = 1; i < argc + 1; i++)
1510 command_line[i] = argv[i - 1]; 1516 command_line[i] = argv[i - 1];
1511#else 1517#else
1518 initfunc = PyInit_perf_trace_context;
1512 command_line = malloc((argc + 1) * sizeof(wchar_t *)); 1519 command_line = malloc((argc + 1) * sizeof(wchar_t *));
1513 command_line[0] = Py_DecodeLocale(script, NULL); 1520 command_line[0] = Py_DecodeLocale(script, NULL);
1514 for (i = 1; i < argc + 1; i++) 1521 for (i = 1; i < argc + 1; i++)
1515 command_line[i] = Py_DecodeLocale(argv[i - 1], NULL); 1522 command_line[i] = Py_DecodeLocale(argv[i - 1], NULL);
1516#endif 1523#endif
1517 1524
1525 PyImport_AppendInittab(name, initfunc);
1518 Py_Initialize(); 1526 Py_Initialize();
1519 1527
1520#if PY_MAJOR_VERSION < 3 1528#if PY_MAJOR_VERSION < 3
1521 initperf_trace_context();
1522 PySys_SetArgv(argc + 1, (char **)command_line); 1529 PySys_SetArgv(argc + 1, (char **)command_line);
1523#else 1530#else
1524 PyInit_perf_trace_context();
1525 PySys_SetArgv(argc + 1, command_line); 1531 PySys_SetArgv(argc + 1, command_line);
1526#endif 1532#endif
1527 1533