From: Namhyung Kim <namhyung@kernel.org>
To: Joseph Schuchart <joseph.schuchart@tu-dresden.de>
Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@redhat.com>,
Thomas Ilsche <thomas.ilsche@tu-dresden.de>,
linux-kernel@vger.kernel.org, jolsa@redhat.com
Subject: Re: [PATCH 1/3] Add missing calls to Py_DECREF
Date: Wed, 04 Jun 2014 23:44:06 +0900 [thread overview]
Message-ID: <1401893046.1673.12.camel@leonhard> (raw)
In-Reply-To: <538F0BEE.7070703@tu-dresden.de>
Hi Joseph,
(Adding Jiri Olsa to CC list as he's maintaining the tooling part as of
now..)
2014-06-04 (수), 14:07 +0200, Joseph Schuchart:
> Add missing calls to Py_DECREF.
>
> The function PyObject_CallObject() returns a new PyObject reference
> on which Py_DECREF has to be called to avoid memory leaks.
> This patch adds these calls where necessary.
>
> It also marks handler_call_die() as NORETURN to make this clear and to
> avoid unnecessary else statements. Note that the abort() is necessary
> since Py_FatalError() does not return but seems to be missing the
> __noretun__ attribute in Python versions <=2.7
Acked-by: Namhyung Kim <namhyung@kernel.org>
Just nitpicks below..
> ---
> tools/perf/util/scripting-engines/trace-event-python.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
> index cd9774d..8454dc9 100644
> --- a/tools/perf/util/scripting-engines/trace-event-python.c
> +++ b/tools/perf/util/scripting-engines/trace-event-python.c
> @@ -50,10 +50,14 @@ static int zero_flag_atom;
>
> static PyObject *main_module, *main_dict;
>
> +static void handler_call_die(const char *handler_name) NORETURN;
Why is this extra decl line needed? What about just adding the NORETURN
marker to the function definition?
> static void handler_call_die(const char *handler_name)
> {
> PyErr_Print();
> Py_FatalError("problem in Python trace event handler");
> + // Py_FatalError does not return
> + // but we have to make the compiler happy
Please use C-style /* ... */ comments.
Thanks,
Namhyung
> + abort();
> }
>
> /*
> @@ -97,6 +101,7 @@ static void define_value(enum print_arg_type field_type,
> retval = PyObject_CallObject(handler, t);
> if (retval == NULL)
> handler_call_die(handler_name);
> + Py_DECREF(retval);
> }
>
> Py_DECREF(t);
> @@ -143,6 +148,7 @@ static void define_field(enum print_arg_type field_type,
> retval = PyObject_CallObject(handler, t);
> if (retval == NULL)
> handler_call_die(handler_name);
> + Py_DECREF(retval);
> }
>
> Py_DECREF(t);
> @@ -333,6 +339,7 @@ static void python_process_tracepoint(struct perf_sample *sample,
> retval = PyObject_CallObject(handler, t);
> if (retval == NULL)
> handler_call_die(handler_name);
> + Py_DECREF(retval);
> } else {
> handler = PyDict_GetItemString(main_dict, "trace_unhandled");
> if (handler && PyCallable_Check(handler)) {
> @@ -340,6 +347,7 @@ static void python_process_tracepoint(struct perf_sample *sample,
> retval = PyObject_CallObject(handler, t);
> if (retval == NULL)
> handler_call_die("trace_unhandled");
> + Py_DECREF(retval);
> }
> Py_DECREF(dict);
> }
> @@ -399,6 +407,7 @@ static void python_process_general_event(struct perf_sample *sample,
> retval = PyObject_CallObject(handler, t);
> if (retval == NULL)
> handler_call_die(handler_name);
> + Py_DECREF(retval);
> exit:
> Py_DECREF(dict);
> Py_DECREF(t);
> @@ -520,8 +529,7 @@ static int python_stop_script(void)
> retval = PyObject_CallObject(handler, NULL);
> if (retval == NULL)
> handler_call_die("trace_end");
> - else
> - Py_DECREF(retval);
> + Py_DECREF(retval);
> out:
> Py_XDECREF(main_dict);
> Py_XDECREF(main_module);
next prev parent reply other threads:[~2014-06-04 14:44 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-18 8:43 [PATCH] Provide additional sample information to Python scripts Joseph Schuchart
2014-03-07 14:18 ` Arnaldo Carvalho de Melo
2014-03-12 15:29 ` Thomas Ilsche
2014-03-12 18:39 ` Arnaldo Carvalho de Melo
2014-04-03 8:57 ` Joseph Schuchart
2014-05-29 6:01 ` Namhyung Kim
2014-06-04 12:07 ` Joseph Schuchart
2014-06-04 12:07 ` [PATCH 1/3] Add missing calls to Py_DECREF Joseph Schuchart
2014-06-04 14:44 ` Namhyung Kim [this message]
2014-06-04 12:07 ` [PATCH 2/3] Add callchain to generic and tracepoint events Joseph Schuchart
2014-06-04 14:46 ` Namhyung Kim
2014-07-07 17:17 ` Jiri Olsa
2014-07-09 7:40 ` [PATCH 1/3] perf script: Add missing calls to Py_DECREF for return values Joseph Schuchart
2014-07-09 8:14 ` Namhyung Kim
2014-07-09 7:40 ` [PATCH 2/3] perf script: Add callchain to generic and tracepoint events Joseph Schuchart
2014-07-09 8:15 ` Namhyung Kim
2014-07-09 11:27 ` Jiri Olsa
2014-07-09 11:43 ` Joseph Schuchart
2014-07-09 11:49 ` Jiri Olsa
2014-07-09 14:16 ` Joseph Schuchart
2014-07-09 14:16 ` [PATCH 1/3] perf script: Add missing calls to Py_DECREF Joseph Schuchart
2014-07-09 19:07 ` Arnaldo Carvalho de Melo
2014-07-18 4:22 ` [tip:perf/core] perf script: Add missing calls to Py_DECREF for return values tip-bot for Joseph Schuchart
2014-07-09 14:16 ` [PATCH 2/3] perf script: Add callchain to generic and tracepoint events Joseph Schuchart
2014-07-09 19:09 ` Arnaldo Carvalho de Melo
2014-07-09 19:12 ` Arnaldo Carvalho de Melo
2014-07-09 19:29 ` Arnaldo Carvalho de Melo
2014-07-10 11:50 ` Joseph Schuchart
2014-07-10 11:50 ` Joseph Schuchart
2014-07-18 4:22 ` [tip:perf/core] " tip-bot for Joseph Schuchart
2014-07-10 11:50 ` [PATCH 3/3] perf script: Provide additional sample information on generic events Joseph Schuchart
2014-07-18 4:23 ` [tip:perf/core] " tip-bot for Joseph Schuchart
2014-07-09 14:16 ` [PATCH 3/3] " Joseph Schuchart
2014-07-09 7:40 ` Joseph Schuchart
2014-07-09 8:16 ` Namhyung Kim
2014-06-04 12:07 ` [PATCH 3/3] " Joseph Schuchart
2014-06-04 14:55 ` Namhyung Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1401893046.1673.12.camel@leonhard \
--to=namhyung@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@ghostprotocols.net \
--cc=jolsa@redhat.com \
--cc=joseph.schuchart@tu-dresden.de \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=paulus@samba.org \
--cc=thomas.ilsche@tu-dresden.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox