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 05:38:00 -0000 [thread overview]
Message-ID: <m3aacvdq4w.fsf@redhat.com> (raw)
In-Reply-To: <m3y60fmj76.fsf@redhat.com> (Phil Muldoon's message of "Sun, 03 Jul 2011 17:18:21 +0100")
Phil Muldoon <pmuldoon@redhat.com> writes:
>
>> + start = gdb_py_long_from_longest (start_pc);
>> + end = gdb_py_long_from_longest (end_pc);
>> + PyTuple_SET_ITEM (ret_tuple, 0, start);
>> + PyTuple_SET_ITEM (ret_tuple, 1, end);
>> + }
>
>>
> Also gdb_py_long_from_longest is macro that points to Py
> Long_FromUnsignedLongLong. This can also return NULL which indicates a
> failure, so similar to above, you need to check the return and return
> NULL if one of them fails. If one of them does return NULL, you also
> need to appropriately clean-up previous references that were created in
> Python. We normally do this by creating a local error: goto.
I read this back, and I thought, I need to explain this a little more
because of the weird reference stealing behaviour of Python
Tuples/Lists. In a "normal" scenario, if you create a Python object,
and later on some bit of code fails, you need to decrement that object
in your local error block (or later, if the function succeeds). But
because Py_Tuple "steals" a reference, it takes ownership of that
object, even if the Tuple itself somehow fails. So in the above case,
if "start" was added ok, but "end" did not, you do not need to decrement
"start", just decrement the tuple. I think this is one of two Python
APIs that does this, so you don't come across it often.
Cheers,
Phil
next prev parent reply other threads:[~2011-07-03 21: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 [this message]
2011-07-04 6:36 ` Matt Rice
2011-07-04 10:09 ` Phil Muldoon
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=m3aacvdq4w.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