From: Tom Tromey <tromey@redhat.com>
To: Siva Chandra <sivachandra@google.com>
Cc: Doug Evans <dje@google.com>, gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [RFC - Python Scripting] New method gdb.Architecture.disassemble
Date: Wed, 13 Feb 2013 18:03:00 -0000 [thread overview]
Message-ID: <87r4kkks5g.fsf@fleche.redhat.com> (raw)
In-Reply-To: <CAGyQ6gzSs617BRcreAGA5418EpXaqCaPN8ZzKjQYNx9yxDSJRA@mail.gmail.com> (Siva Chandra's message of "Wed, 13 Feb 2013 06:37:46 -0800")
>>>>> "Siva" == Siva Chandra <sivachandra@google.com> writes:
Siva> 1. docs.python.org says that PyList_Append sets an exception when it
Siva> fails. It does not say so for PyList_New() and PyDict_New(). However,
Siva> Tom commented that even these functions set exception on failure. In
Siva> general, how do we know if a certain Python C API function sets an
Siva> exception or not?
The general rule in Python is that failures set the exception. I found
some text in the manual, from
http://docs.python.org/2/c-api/intro.html#exceptions
All functions in the Python/C API can raise exceptions, unless an
explicit claim is made otherwise in a function’s documentation. In
general, when a function encounters an error, it sets an exception,
discards any object references that it owns, and returns an error
indicator. If not documented otherwise, this indicator is either NULL
or -1, depending on the function’s return type. A few functions return
a Boolean true/false result, with false indicating an error. Very few
functions return no explicit error indicator or have an ambiguous
return value, and require explicit testing for errors with
PyErr_Occurred(). These exceptions are always explicitly documented.
Siva> 2. One of Tom's suggestion was to use something like this:
Siva> asm_code == NULL ? unknown_str : asm_code
Siva> I have modified my code accordingly, but the concern I have is that
Siva> asm_code is of type 'char *', while unknown_str if of type 'const char
Siva> *'. This means that the type of result of the above expression is
Siva> dynamic! Though the code compiles with GCC, it that standard?
It is. I'd have to dig through the standard to find the real language,
but basically the type of the "?:" expression is the result of applying
the appropriate kind of promotion to its arguments. Here the type is
"const char *".
Siva> + if (!result_list)
There was a recent agreement to use "result == NULL" for pointer types.
I'm sorry if I didn't catch this last time around, I'm having a little
difficulty adapting.
Siva> + if (!insn_dict)
Here too.
Siva> + PyErr_SetString (PyExc_MemoryError,
Siva> + _("Unable to add fields to instruction dict."));
I think you don't need this.
Siva> +gdb_test "python arch.disassemble(0, 0)" ".*gdb\.MemoryError.*" "test exception"
I think this could use a line break somewhere.
Tom
next prev parent reply other threads:[~2013-02-13 18:03 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-04 14:09 Siva Chandra
2013-02-05 23:28 ` Doug Evans
2013-02-06 1:53 ` Siva Chandra
2013-02-06 20:00 ` Tom Tromey
2013-02-08 18:05 ` Doug Evans
2013-02-09 17:55 ` Matt Rice
2013-02-12 14:56 ` Siva Chandra
2013-02-12 21:18 ` Tom Tromey
2013-02-13 14:37 ` Siva Chandra
2013-02-13 17:52 ` Eli Zaretskii
2013-02-13 18:03 ` Tom Tromey [this message]
2013-02-13 19:50 ` Siva Chandra
2013-02-13 20:42 ` Doug Evans
2013-02-14 22:46 ` Siva Chandra
2013-02-15 6:43 ` Doug Evans
2013-02-15 17:32 ` Doug Evans
2013-02-15 17:40 ` Siva Chandra
2013-02-15 17:41 ` Siva Chandra
2013-02-15 18:57 ` Doug Evans
2013-02-15 20:36 ` Siva Chandra
2013-02-15 21:01 ` Siva Chandra
2013-02-16 5:30 ` Doug Evans
2013-02-16 8:47 ` Eli Zaretskii
2013-02-19 5:36 ` Siva Chandra
2013-02-19 15:51 ` Paul_Koning
2013-02-19 16:35 ` Eli Zaretskii
2013-02-19 16:38 ` Eli Zaretskii
2013-02-20 12:34 ` Siva Chandra
2013-02-20 18:44 ` Eli Zaretskii
2013-02-21 1:49 ` Siva Chandra
2013-02-06 19:58 ` Tom Tromey
2013-02-06 20:31 ` Phil Muldoon
2013-02-06 22:31 ` Matt Rice
2013-02-06 23:19 ` Siva Chandra
2013-02-07 1:11 ` Siva Chandra
2013-02-07 23:03 ` Matt Rice
[not found] ` <20130206235707.GA2353@klara.mpi.htwm.de>
2013-02-07 1:18 ` Siva Chandra
2013-02-07 14:14 ` Siva Chandra
2013-02-07 16:42 ` Tom Tromey
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=87r4kkks5g.fsf@fleche.redhat.com \
--to=tromey@redhat.com \
--cc=dje@google.com \
--cc=gdb-patches@sourceware.org \
--cc=sivachandra@google.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