This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 28/40] use explicit returns to avoid checker confusion


On 2013-5-10 2:52, Tom Tromey wrote:
> The checker does not understand the idiom
> 
> if (except.reason < 0) {
>    do_cleanups (whatever);
>    GDB_PY_HANDLE_EXCEPTION (except);
> }
> 
> because it doesn't realize that the nested 'if' actually has the same
> condition.
> 
> This fixes instances of this to be more explicit.
> 
> 	* python/py-breakpoint.c (bppy_get_commands): Use
> 	explicit, unconditional return.
> 	* python/py-frame.c (frapy_read_var): Likewise.
> 	* python/python.c (gdbpy_decode_line): Likewise.
> ---
>  gdb/python/py-breakpoint.c | 2 +-
>  gdb/python/py-frame.c      | 2 +-
>  gdb/python/python.c        | 2 +-
>  3 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
> index d099892..fd13811 100644
> --- a/gdb/python/py-breakpoint.c
> +++ b/gdb/python/py-breakpoint.c
> @@ -492,7 +492,7 @@ bppy_get_commands (PyObject *self, void *closure)
>    if (except.reason < 0)
>      {
>        do_cleanups (chain);
> -      GDB_PY_HANDLE_EXCEPTION (except);
> +      return gdbpy_convert_exception (except);
>      }
>  
>    cmdstr = ui_file_xstrdup (string_file, &length);
> diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
> index 33d0bd0..10a50ea 100644
> --- a/gdb/python/py-frame.c
> +++ b/gdb/python/py-frame.c
> @@ -472,7 +472,7 @@ frapy_read_var (PyObject *self, PyObject *args)
>        if (except.reason < 0)
>  	{
>  	  do_cleanups (cleanup);
> -	  GDB_PY_HANDLE_EXCEPTION (except);
> +	  return gdbpy_convert_exception (except);
>  	}
>  
>        if (!var)
> diff --git a/gdb/python/python.c b/gdb/python/python.c
> index 67d06e5..c4be31b 100644
> --- a/gdb/python/python.c
> +++ b/gdb/python/python.c
> @@ -644,7 +644,7 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
>      {
>        do_cleanups (cleanups);
>        /* We know this will always throw.  */
> -      GDB_PY_HANDLE_EXCEPTION (except);
> +      return gdbpy_convert_exception (except);
>      }
>  
>    if (sals.nelts)
> 

I see a compiler error:

mingw32-gcc -O0 -g -D__USE_MINGW_ACCESS   -I. -I../../archer/gdb -I../../archer/gdb/common -I../../archer/gdb/config -DLOCALEDIR="\"/mingw/share/locale\"" -DHAVE_CONFIG_H -I../../archer/gdb/../include/opcode -I../../archer/gdb/../opcodes/.. -I../../archer/gdb/../readline/.. -I../bfd -I../../archer/gdb/../bfd -I../../archer/gdb/../include -I../libdecnumber -I../../archer/gdb/../libdecnumber  -I../../archer/gdb/gnulib/import -Ibuild-gnulib/import    -IE:/code/python27/include -IE:/code/python27/include -Wall -Wdeclaration-after-statement -Wpointer-arith -Wpointer-sign -Wno-unused -Wunused-value -Wunused-function -Wno-switch -Wno-char-subscripts -Wmissing-prototypes -Wdeclaration-after-statement -Wempty-body -Wno-format -Werror -c -o python.o -MT python.o -MMD -MP -MF .deps/python.Tpo -fno-strict-aliasing -DNDEBUG -fwrapv ../../archer/gdb/python/python.c
../../archer/gdb/python/python.c: In function 'gdbpy_decode_line':
../../archer/gdb/python/python.c:656:7: error: void value not ignored as it ought to be
make[2]: *** [python.o] Error 1
make[2]: Leaving directory `/f/build_gdb/abuild/gdb'
make[1]: *** [all-gdb] Error 2
make[1]: Leaving directory `/f/build_gdb/abuild'
make: *** [all] Error 2

I see that: gdbpy_convert_exception (except) return a "void" type, but the function gdbpy_decode_line() need to return a "PyObject *"

The macro GDB_PY_HANDLE_EXCEPTION (except) did return a NULL, see:
/* Use this after a TRY_EXCEPT to throw the appropriate Python
   exception.  */
#define GDB_PY_HANDLE_EXCEPTION(Exception)	\
  do {						\
    if (Exception.reason < 0)			\
      {						\
	gdbpy_convert_exception (Exception);	\
        return NULL;				\
      }						\
  } while (0)


So, what about:

gdbpy_convert_exception (except);
return NULL;


Yuanhui Zhang


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]