Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Phil Muldoon <pmuldoon@redhat.com>
To: Matt Rice <ratmice@gmail.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [patch] [python] find_line_pc_range
Date: Mon, 04 Jul 2011 10:09:00 -0000	[thread overview]
Message-ID: <m3zkkus925.fsf@redhat.com> (raw)
In-Reply-To: <CACTLOFo5rD6PCLeK+hmoBt-vAHGJZDNS_gPbZG6tP=CP=gFeog@mail.gmail.com>	(Matt Rice's message of "Sun, 3 Jul 2011 23:03:51 -0700")

Matt Rice <ratmice@gmail.com> writes:

> Thanks, attached is an updated patch that also includes tests.

Thanks.

> +      ret_tuple = PyTuple_New (2);
> +      if (!ret_tuple)
> +        return Py_None;

Return NULL here.  This signifies an error, and that we have abandoned
the function.  When a Python function returns NULL, the exception is
eventually printed and cleared either by the callers, or by the GDB
Python top-level exception handling code.

> +      start = gdb_py_long_from_ulongest (start_pc);
> +      if (!start)
> +	goto fail_ret;
> +      if (PyTuple_SetItem (ret_tuple, 0, start) != 0)
> +	{
> +	  Py_XDECREF (start);
> +	  goto fail_ret;
> +	}

You do not need to decrement "start" here.  Even if the tuple SetItem
call failed, you have already passed the responsibility to the tuple,
and you no longer own it (stolen reference).  SetItem would decrement
this on failure.  So just goto to your local error block.

> +      end = gdb_py_long_from_ulongest (end_pc);
> +      if (!end)
> +	goto fail_ret;
> +      if (PyTuple_SetItem (ret_tuple, 1, end) != 0)
> +	{
> +	  Py_XDECREF (end);
> +	  goto fail_ret;
> +	}

Same as above.

> +      fail_ret:
> +        Py_XDECREF (ret_tuple);

Small nit, and this is generally ok, but you already know that if this
error block is called, ret_tuple will be instantiated. So in this case
the XDECREF is a tiny bit redundant.  You could just use DECREF here and
skip the NULL check that XDECREF does.  Like I said, a tiny nit, but I
just thought I would point it out.


> +	return Py_None;

If there is a Python exception that you cannot handle internally to your
function, you must always return NULL.  This informs callers, and
ultimately the exception managing code in GDB that some Python call
failed, to print the exception, and clear it.

> @@ -526,6 +573,8 @@ static PyMethodDef sal_object_methods[] = {
>    { "is_valid", salpy_is_valid, METH_NOARGS,
>      "is_valid () -> Boolean.\n\
>  Return true if this symbol table and line is valid, false if not." },
> +  { "find_line_pc_range", salpy_find_line_pc_range, METH_NOARGS,
> +    "Return a tuple of start and end ranges for the symbol table." },
>    {NULL}  /* Sentinel */
>  };

We try to put the return type in the help now as a formal statement.
Look at the two-line help example above: "is_valid()" for guidance.

Nearly there, thanks for the patch!

Cheers,

Phil


  reply	other threads:[~2011-07-04  9:13 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-02  4:03 Matt Rice
2011-07-03 16:35 ` Phil Muldoon
2011-07-04  5:38   ` Phil Muldoon
2011-07-04  6:36   ` Matt Rice
2011-07-04 10:09     ` Phil Muldoon [this message]
2011-07-05  2:47       ` Matt Rice
2011-07-05 20:41         ` Phil Muldoon
2011-07-04 10:50     ` Eli Zaretskii
2011-07-04 10:56       ` Matt Rice
2011-07-04 13:14         ` Eli Zaretskii

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=m3zkkus925.fsf@redhat.com \
    --to=pmuldoon@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=ratmice@gmail.com \
    /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