This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFC - Python Scripting] New method gdb.Architecture.disassemble
>>>>> "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