[RFA,04/13] Call some functions in guile/ for effect

Message ID 20180712205208.32646-5-tom@tromey.com
State New
Headers show
Series
  • Add -Wunused-variable
Related show

Commit Message

Tom Tromey July 12, 2018, 8:51 p.m.
This changes a few spots in guile/ to remove a variable declaration
but to still call a function for effect.

gdb/ChangeLog
2018-07-12  Tom Tromey  <tom@tromey.com>

	* guile/scm-pretty-print.c (gdbscm_apply_val_pretty_printer): Call
	value_contents_for_printing for effect.
	* guile/scm-cmd.c (gdbscm_dont_repeat): Call
	cmdscm_get_valid_command_smob_arg_unsafe for effect.
	* guile/scm-block.c (gdbscm_make_block_syms_iter): Call
	bkscm_get_valid_block_smob_arg_unsafe for effect.
---
 gdb/ChangeLog                | 9 +++++++++
 gdb/guile/scm-block.c        | 5 ++---
 gdb/guile/scm-cmd.c          | 6 +++---
 gdb/guile/scm-pretty-print.c | 4 +++-
 4 files changed, 17 insertions(+), 7 deletions(-)

-- 
2.13.6

Comments

Simon Marchi July 14, 2018, 1:19 a.m. | #1
On 2018-07-12 04:51 PM, Tom Tromey wrote:
> This changes a few spots in guile/ to remove a variable declaration

> but to still call a function for effect.


LGTM, though it would be nice to mention in the comments what is the
desired side-effect (if known).

Simon
Tom Tromey July 14, 2018, 12:39 p.m. | #2
>>>>> "Simon" == Simon Marchi <simark@simark.ca> writes:


Simon> On 2018-07-12 04:51 PM, Tom Tromey wrote:
>> This changes a few spots in guile/ to remove a variable declaration

>> but to still call a function for effect.


Simon> LGTM, though it would be nice to mention in the comments what is the
Simon> desired side-effect (if known).

I really do not know, I just noticed that those functions can throw.

Tom
Pedro Alves July 16, 2018, 1:54 p.m. | #3
On 07/14/2018 01:39 PM, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simark@simark.ca> writes:

> 

> Simon> On 2018-07-12 04:51 PM, Tom Tromey wrote:

>>> This changes a few spots in guile/ to remove a variable declaration

>>> but to still call a function for effect.

> 

> Simon> LGTM, though it would be nice to mention in the comments what is the

> Simon> desired side-effect (if known).

> 

> I really do not know, I just noticed that those functions can throw.


No idea on the guile bits, but for this one:

> --- a/gdb/guile/scm-pretty-print.c

> +++ b/gdb/guile/scm-pretty-print.c

> @@ -970,7 +970,9 @@ gdbscm_apply_val_pretty_printer (const struct extension_language_defn *extlang,

>    struct cleanup *cleanups;

>    enum ext_lang_rc result = EXT_LANG_RC_NOP;

>    enum string_repr_result print_result;

> -  const gdb_byte *valaddr = value_contents_for_printing (val);

> +

> +  /* Call for side effects.  */

> +  value_contents_for_printing (val);

>  

>    /* No pretty-printer support for unavailable values.  */

>    if (!value_bytes_available (val, embedded_offset


... we can't call value_bytes_available on a lazy value (because that function must
be usable with values in the values history, that's why it works with a const value *),
so the desired side effect here is fetching a lazy value.  So I think we
should replace that with:

  if (value_lazy (val))
    value_fetch_lazy (val);

The Python seems to have the same issue, so I think it'd be
a little better to handle both this hunk and the equivalent bit
in Python in the same patch, and in its own patch.

Thanks,
Pedro Alves
Tom Tromey July 16, 2018, 3:57 p.m. | #4
>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:


Pedro> ... we can't call value_bytes_available on a lazy value (because that function must
Pedro> be usable with values in the values history, that's why it works with a const value *),
Pedro> so the desired side effect here is fetching a lazy value.  So I think we
Pedro> should replace that with:

Pedro>   if (value_lazy (val))
Pedro>     value_fetch_lazy (val);

Pedro> The Python seems to have the same issue, so I think it'd be
Pedro> a little better to handle both this hunk and the equivalent bit
Pedro> in Python in the same patch, and in its own patch.

I did this

Tom

Patch

diff --git a/gdb/guile/scm-block.c b/gdb/guile/scm-block.c
index d4566fc1ffe..9caff799dc1 100644
--- a/gdb/guile/scm-block.c
+++ b/gdb/guile/scm-block.c
@@ -613,9 +613,8 @@  bkscm_block_syms_progress_p (SCM scm)
 static SCM
 gdbscm_make_block_syms_iter (SCM self)
 {
-  block_smob *b_smob
-    = bkscm_get_valid_block_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
-  const struct block *block = b_smob->block;
+  /* Call for side effects.  */
+  bkscm_get_valid_block_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
   SCM progress, iter;
 
   progress = bkscm_make_block_syms_progress_smob ();
diff --git a/gdb/guile/scm-cmd.c b/gdb/guile/scm-cmd.c
index 64243d1ba2e..9e5ff8f2636 100644
--- a/gdb/guile/scm-cmd.c
+++ b/gdb/guile/scm-cmd.c
@@ -267,9 +267,9 @@  gdbscm_command_valid_p (SCM self)
 static SCM
 gdbscm_dont_repeat (SCM self)
 {
-  /* We currently don't need anything from SELF, but still verify it.  */
-  command_smob *c_smob
-    = cmdscm_get_valid_command_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
+  /* We currently don't need anything from SELF, but still verify it.
+     Call for side effects.  */
+  cmdscm_get_valid_command_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
 
   dont_repeat ();
 
diff --git a/gdb/guile/scm-pretty-print.c b/gdb/guile/scm-pretty-print.c
index da1b7d2be15..8c96e7e3f8b 100644
--- a/gdb/guile/scm-pretty-print.c
+++ b/gdb/guile/scm-pretty-print.c
@@ -970,7 +970,9 @@  gdbscm_apply_val_pretty_printer (const struct extension_language_defn *extlang,
   struct cleanup *cleanups;
   enum ext_lang_rc result = EXT_LANG_RC_NOP;
   enum string_repr_result print_result;
-  const gdb_byte *valaddr = value_contents_for_printing (val);
+
+  /* Call for side effects.  */
+  value_contents_for_printing (val);
 
   /* No pretty-printer support for unavailable values.  */
   if (!value_bytes_available (val, embedded_offset, TYPE_LENGTH (type)))