[v3,2/3] Guile: add {r,}value-reference-value

Message ID a2/om2x1eht6jpueahqskn1s9k/0gbd/dzo-o5epa&g2-vmj3eo_@mail.bob131.so
State Superseded
Headers show
Series
  • Guile: add value-{reference,const}-value
Related show

Commit Message

Eli Zaretskii via Gdb-patches April 28, 2021, 4:27 p.m.
The Guile API doesn't currently have an equivalent to the Python API's
Value.reference_value() or Value.rvalue_reference_value(). This commit
adds a procedure with equivalent semantics to the Guile API.

gdb/ChangeLog:

2021-04-29  George Barrett  <bob@bob131.so>

	* guile/scm-value.c (gdbscm_reference_value): Add helper
	function for reference value creation.
	(gdbscm_value_reference_value): Add implementation of
	value-reference-value procedure.
	(gdbscm_rvalue_reference_value): Add implementation of
	rvalue-reference-value procedure.
	(value_functions): Add value-reference-value procedure.
	Add rvalue-reference-value procedure.
	* NEWS (Guile API): Note the addition of new procedures.

gdb/doc/ChangeLog:

2021-04-29  George Barrett  <bob@bob131.so>

	* guile.texi (Values From Inferior In Guile): Add
	documentation for value-reference-value.
	Add documentation for rvalue-reference-value.

gdb/testsuite/ChangeLog:

2021-04-29  George Barrett  <bob@bob131.so>

	* gdb.guile/scm-value.exp (test_value_in_inferior): Add test
	for value-reference-value.
	Add test for rvalue-reference-value.
---
 gdb/NEWS                              |  3 ++
 gdb/doc/guile.texi                    | 10 +++++++
 gdb/guile/scm-value.c                 | 42 +++++++++++++++++++++++++++
 gdb/testsuite/gdb.guile/scm-value.exp | 10 +++++++
 4 files changed, 65 insertions(+)

-- 
2.30.2

Comments

Eli Zaretskii via Gdb-patches April 28, 2021, 4:40 p.m. | #1
> Date: Thu, 29 Apr 2021 02:27:37 +1000

> From: George Barrett via Gdb-patches <gdb-patches@sourceware.org>

> Cc: George Barrett <bob@bob131.so>

> 

> The Guile API doesn't currently have an equivalent to the Python API's

> Value.reference_value() or Value.rvalue_reference_value(). This commit

> adds a procedure with equivalent semantics to the Guile API.

> 

> gdb/ChangeLog:

> 

> 2021-04-29  George Barrett  <bob@bob131.so>

> 

> 	* guile/scm-value.c (gdbscm_reference_value): Add helper

> 	function for reference value creation.

> 	(gdbscm_value_reference_value): Add implementation of

> 	value-reference-value procedure.

> 	(gdbscm_rvalue_reference_value): Add implementation of

> 	rvalue-reference-value procedure.

> 	(value_functions): Add value-reference-value procedure.

> 	Add rvalue-reference-value procedure.

> 	* NEWS (Guile API): Note the addition of new procedures.

> 

> gdb/doc/ChangeLog:

> 

> 2021-04-29  George Barrett  <bob@bob131.so>

> 

> 	* guile.texi (Values From Inferior In Guile): Add

> 	documentation for value-reference-value.

> 	Add documentation for rvalue-reference-value.

> 

> gdb/testsuite/ChangeLog:

> 

> 2021-04-29  George Barrett  <bob@bob131.so>

> 

> 	* gdb.guile/scm-value.exp (test_value_in_inferior): Add test

> 	for value-reference-value.

> 	Add test for rvalue-reference-value.


Thanks, the documentation parts are okay.
Andrew Burgess April 28, 2021, 4:59 p.m. | #2
* George Barrett via Gdb-patches <gdb-patches@sourceware.org> [2021-04-29 02:27:37 +1000]:

> The Guile API doesn't currently have an equivalent to the Python API's

> Value.reference_value() or Value.rvalue_reference_value(). This commit

> adds a procedure with equivalent semantics to the Guile API.


Thank you for doing this work.  I'm sorry to be a real pain, but could
you rename the second new function to value-rvalue-reference-value
please, I think this would be inline with the existing naming
convention; the first 'value-' indicates that the function applies to
something of value type, and the rest of the name
'rvalue-reference-value' indicates what you're going to get.

If you just make the rename as suggested, then this patch is approved.

Thanks,
Andrew

> 

> gdb/ChangeLog:

> 

> 2021-04-29  George Barrett  <bob@bob131.so>

> 

> 	* guile/scm-value.c (gdbscm_reference_value): Add helper

> 	function for reference value creation.

> 	(gdbscm_value_reference_value): Add implementation of

> 	value-reference-value procedure.

> 	(gdbscm_rvalue_reference_value): Add implementation of

> 	rvalue-reference-value procedure.

> 	(value_functions): Add value-reference-value procedure.

> 	Add rvalue-reference-value procedure.

> 	* NEWS (Guile API): Note the addition of new procedures.

> 

> gdb/doc/ChangeLog:

> 

> 2021-04-29  George Barrett  <bob@bob131.so>

> 

> 	* guile.texi (Values From Inferior In Guile): Add

> 	documentation for value-reference-value.

> 	Add documentation for rvalue-reference-value.

> 

> gdb/testsuite/ChangeLog:

> 

> 2021-04-29  George Barrett  <bob@bob131.so>

> 

> 	* gdb.guile/scm-value.exp (test_value_in_inferior): Add test

> 	for value-reference-value.

> 	Add test for rvalue-reference-value.

> ---

>  gdb/NEWS                              |  3 ++

>  gdb/doc/guile.texi                    | 10 +++++++

>  gdb/guile/scm-value.c                 | 42 +++++++++++++++++++++++++++

>  gdb/testsuite/gdb.guile/scm-value.exp | 10 +++++++

>  4 files changed, 65 insertions(+)

> 

> diff --git a/gdb/NEWS b/gdb/NEWS

> index 9c76df8b6d5..0c51f5fceca 100644

> --- a/gdb/NEWS

> +++ b/gdb/NEWS

> @@ -192,6 +192,9 @@ QMemTags

>       value-referenced-value procedure now handles rvalue reference

>       values.

>  

> +  ** New procedures for obtaining reference values:

> +     value-reference-value and rvalue-reference-value.

> +

>  *** Changes in GDB 10

>  

>  * There are new feature names for ARC targets: "org.gnu.gdb.arc.core"

> diff --git a/gdb/doc/guile.texi b/gdb/doc/guile.texi

> index c7904574002..18782bb7589 100644

> --- a/gdb/doc/guile.texi

> +++ b/gdb/doc/guile.texi

> @@ -801,6 +801,16 @@ The @code{<gdb:value>} object @code{scm-val} is identical to that

>  corresponding to @code{val}.

>  @end deffn

>  

> +@deffn {Scheme Procedure} value-reference-value value

> +Return a new @code{<gdb:value>} object which is a reference to the value

> +encapsulated by @code{<gdb:value>} object @var{value}.

> +@end deffn

> +

> +@deffn {Scheme Procedure} rvalue-reference-value value

> +Return a new @code{<gdb:value>} object which is an rvalue reference to

> +the value encapsulated by @code{<gdb:value>} object @var{value}.

> +@end deffn

> +

>  @deffn {Scheme Procedure} value-field value field-name

>  Return field @var{field-name} from @code{<gdb:value>} object @var{value}.

>  @end deffn

> diff --git a/gdb/guile/scm-value.c b/gdb/guile/scm-value.c

> index f50e8b5b46c..2ab193f044a 100644

> --- a/gdb/guile/scm-value.c

> +++ b/gdb/guile/scm-value.c

> @@ -488,6 +488,38 @@ gdbscm_value_referenced_value (SCM self)

>      });

>  }

>  

> +static SCM

> +gdbscm_reference_value (SCM self, enum type_code refcode)

> +{

> +  value_smob *v_smob

> +    = vlscm_get_value_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);

> +  struct value *value = v_smob->value;

> +

> +  return gdbscm_wrap ([=]

> +    {

> +      scoped_value_mark free_values;

> +

> +      struct value *res_val = value_ref (value, refcode);

> +      return vlscm_scm_from_value (res_val);

> +    });

> +}

> +

> +/* (value-reference-value <gdb:value>) -> <gdb:value> */

> +

> +static SCM

> +gdbscm_value_reference_value (SCM self)

> +{

> +  return gdbscm_reference_value (self, TYPE_CODE_REF);

> +}

> +

> +/* (rvalue-reference-value <gdb:value>) -> <gdb:value> */

> +

> +static SCM

> +gdbscm_rvalue_reference_value (SCM self)

> +{

> +  return gdbscm_reference_value (self, TYPE_CODE_RVALUE_REF);

> +}

> +

>  /* (value-type <gdb:value>) -> <gdb:type> */

>  

>  static SCM

> @@ -1352,6 +1384,16 @@ For example, for a value which is a reference to an 'int' pointer ('int *'),\n\

>  value-dereference will result in a value of type 'int' while\n\

>  value-referenced-value will result in a value of type 'int *'." },

>  

> +  { "value-reference-value", 1, 0, 0,

> +    as_a_scm_t_subr (gdbscm_value_reference_value),

> +    "\

> +Return a <gdb:value> object which is a reference to the given value." },

> +

> +  { "rvalue-reference-value", 1, 0, 0,

> +    as_a_scm_t_subr (gdbscm_rvalue_reference_value),

> +    "\

> +Return a <gdb:value> object which is an rvalue reference to the given value." },

> +

>    { "value-field", 2, 0, 0, as_a_scm_t_subr (gdbscm_value_field),

>      "\

>  Return the specified field of the value.\n\

> diff --git a/gdb/testsuite/gdb.guile/scm-value.exp b/gdb/testsuite/gdb.guile/scm-value.exp

> index 191af1d71a6..883c4bea72e 100644

> --- a/gdb/testsuite/gdb.guile/scm-value.exp

> +++ b/gdb/testsuite/gdb.guile/scm-value.exp

> @@ -173,6 +173,16 @@ proc test_value_in_inferior {} {

>  	"get string beyond null"

>      gdb_test "gu (print nullst)" \

>  	"= divide\\\\000et"

> +

> +    gdb_scm_test_silent_cmd "gu (define argv-ref (value-reference-value argv))" \

> +	"test value-reference-value"

> +    gdb_test "gu (equal? argv (value-referenced-value argv-ref))" "#t"

> +    gdb_test "gu (eqv? (type-code (value-type argv-ref)) TYPE_CODE_REF)" "#t"

> +

> +    gdb_scm_test_silent_cmd "gu (define argv-rref (rvalue-reference-value argv))" \

> +	"test rvalue-reference-value"

> +    gdb_test "gu (equal? argv (value-referenced-value argv-rref))" "#t"

> +    gdb_test "gu (eqv? (type-code (value-type argv-rref)) TYPE_CODE_RVALUE_REF)" "#t"

>  }

>  

>  proc test_strings {} {

> -- 

> 2.30.2
Eli Zaretskii via Gdb-patches April 28, 2021, 5:11 p.m. | #3
On Wed, Apr 28, 2021 at 05:59:45PM +0100, Andrew Burgess wrote:
> Thank you for doing this work.  I'm sorry to be a real pain, but could

> you rename the second new function to value-rvalue-reference-value

> please, I think this would be inline with the existing naming

> convention; the first 'value-' indicates that the function applies to

> something of value type, and the rest of the name

> 'rvalue-reference-value' indicates what you're going to get.


No problem, thank you for your patience with me. I have no objection to the
name change (in fact, I'm not sure why I thought the name I chose was an
appropriate one :P) so I'll roll a v4 in a moment.

> If you just make the rename as suggested, then this patch is approved.

> 

> Thanks,

> Andrew


Thanks

Patch

diff --git a/gdb/NEWS b/gdb/NEWS
index 9c76df8b6d5..0c51f5fceca 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -192,6 +192,9 @@  QMemTags
      value-referenced-value procedure now handles rvalue reference
      values.
 
+  ** New procedures for obtaining reference values:
+     value-reference-value and rvalue-reference-value.
+
 *** Changes in GDB 10
 
 * There are new feature names for ARC targets: "org.gnu.gdb.arc.core"
diff --git a/gdb/doc/guile.texi b/gdb/doc/guile.texi
index c7904574002..18782bb7589 100644
--- a/gdb/doc/guile.texi
+++ b/gdb/doc/guile.texi
@@ -801,6 +801,16 @@  The @code{<gdb:value>} object @code{scm-val} is identical to that
 corresponding to @code{val}.
 @end deffn
 
+@deffn {Scheme Procedure} value-reference-value value
+Return a new @code{<gdb:value>} object which is a reference to the value
+encapsulated by @code{<gdb:value>} object @var{value}.
+@end deffn
+
+@deffn {Scheme Procedure} rvalue-reference-value value
+Return a new @code{<gdb:value>} object which is an rvalue reference to
+the value encapsulated by @code{<gdb:value>} object @var{value}.
+@end deffn
+
 @deffn {Scheme Procedure} value-field value field-name
 Return field @var{field-name} from @code{<gdb:value>} object @var{value}.
 @end deffn
diff --git a/gdb/guile/scm-value.c b/gdb/guile/scm-value.c
index f50e8b5b46c..2ab193f044a 100644
--- a/gdb/guile/scm-value.c
+++ b/gdb/guile/scm-value.c
@@ -488,6 +488,38 @@  gdbscm_value_referenced_value (SCM self)
     });
 }
 
+static SCM
+gdbscm_reference_value (SCM self, enum type_code refcode)
+{
+  value_smob *v_smob
+    = vlscm_get_value_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
+  struct value *value = v_smob->value;
+
+  return gdbscm_wrap ([=]
+    {
+      scoped_value_mark free_values;
+
+      struct value *res_val = value_ref (value, refcode);
+      return vlscm_scm_from_value (res_val);
+    });
+}
+
+/* (value-reference-value <gdb:value>) -> <gdb:value> */
+
+static SCM
+gdbscm_value_reference_value (SCM self)
+{
+  return gdbscm_reference_value (self, TYPE_CODE_REF);
+}
+
+/* (rvalue-reference-value <gdb:value>) -> <gdb:value> */
+
+static SCM
+gdbscm_rvalue_reference_value (SCM self)
+{
+  return gdbscm_reference_value (self, TYPE_CODE_RVALUE_REF);
+}
+
 /* (value-type <gdb:value>) -> <gdb:type> */
 
 static SCM
@@ -1352,6 +1384,16 @@  For example, for a value which is a reference to an 'int' pointer ('int *'),\n\
 value-dereference will result in a value of type 'int' while\n\
 value-referenced-value will result in a value of type 'int *'." },
 
+  { "value-reference-value", 1, 0, 0,
+    as_a_scm_t_subr (gdbscm_value_reference_value),
+    "\
+Return a <gdb:value> object which is a reference to the given value." },
+
+  { "rvalue-reference-value", 1, 0, 0,
+    as_a_scm_t_subr (gdbscm_rvalue_reference_value),
+    "\
+Return a <gdb:value> object which is an rvalue reference to the given value." },
+
   { "value-field", 2, 0, 0, as_a_scm_t_subr (gdbscm_value_field),
     "\
 Return the specified field of the value.\n\
diff --git a/gdb/testsuite/gdb.guile/scm-value.exp b/gdb/testsuite/gdb.guile/scm-value.exp
index 191af1d71a6..883c4bea72e 100644
--- a/gdb/testsuite/gdb.guile/scm-value.exp
+++ b/gdb/testsuite/gdb.guile/scm-value.exp
@@ -173,6 +173,16 @@  proc test_value_in_inferior {} {
 	"get string beyond null"
     gdb_test "gu (print nullst)" \
 	"= divide\\\\000et"
+
+    gdb_scm_test_silent_cmd "gu (define argv-ref (value-reference-value argv))" \
+	"test value-reference-value"
+    gdb_test "gu (equal? argv (value-referenced-value argv-ref))" "#t"
+    gdb_test "gu (eqv? (type-code (value-type argv-ref)) TYPE_CODE_REF)" "#t"
+
+    gdb_scm_test_silent_cmd "gu (define argv-rref (rvalue-reference-value argv))" \
+	"test rvalue-reference-value"
+    gdb_test "gu (equal? argv (value-referenced-value argv-rref))" "#t"
+    gdb_test "gu (eqv? (type-code (value-type argv-rref)) TYPE_CODE_RVALUE_REF)" "#t"
 }
 
 proc test_strings {} {