Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH c++ 11/12] target.c: Add a cast and change a type
@ 2015-10-26 10:23 Simon Marchi
  2015-10-26 10:38 ` [PATCH c++ 12/12] ada-lang.h: Add cast in GROW_VECT Simon Marchi
  2015-10-27  9:54 ` [PATCH c++ 11/12] target.c: Add a cast and change a type Simon Marchi
  0 siblings, 2 replies; 7+ messages in thread
From: Simon Marchi @ 2015-10-26 10:23 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

Fixes some errors in C++ build.

gdb/ChangeLog:

	* target.c (memory_xfer_partial): Change type of buf to gdb_byte
	pointer.
	(simple_search_memory): Cast return of memmem.
---
 gdb/target.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/gdb/target.c b/gdb/target.c
index b8b1e9b..d7653c4 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -1235,7 +1235,7 @@ memory_xfer_partial (struct target_ops *ops, enum target_object object,
     }
   else
     {
-      void *buf;
+      gdb_byte *buf;
       struct cleanup *old_chain;
 
       /* A large write request is likely to be partially satisfied
@@ -1245,7 +1245,7 @@ memory_xfer_partial (struct target_ops *ops, enum target_object object,
 	 subset of it.  Cap writes to 4KB to mitigate this.  */
       len = min (4096, len);
 
-      buf = xmalloc (len);
+      buf = (gdb_byte *) xmalloc (len);
       old_chain = make_cleanup (xfree, buf);
       memcpy (buf, writebuf, len);
 
@@ -2391,8 +2391,8 @@ simple_search_memory (struct target_ops *ops,
       gdb_byte *found_ptr;
       unsigned nr_search_bytes = min (search_space_len, search_buf_size);
 
-      found_ptr = memmem (search_buf, nr_search_bytes,
-			  pattern, pattern_len);
+      found_ptr = (gdb_byte *) memmem (search_buf, nr_search_bytes,
+				       pattern, pattern_len);
 
       if (found_ptr != NULL)
 	{
-- 
2.6.2


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH c++ 12/12] ada-lang.h: Add cast in GROW_VECT
  2015-10-26 10:23 [PATCH c++ 11/12] target.c: Add a cast and change a type Simon Marchi
@ 2015-10-26 10:38 ` Simon Marchi
  2015-10-26 23:09   ` Pedro Alves
  2015-10-27  9:54 ` [PATCH c++ 11/12] target.c: Add a cast and change a type Simon Marchi
  1 sibling, 1 reply; 7+ messages in thread
From: Simon Marchi @ 2015-10-26 10:38 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

The assignment requires a cast in C++.

gdb/ChangeLog:

	* ada-lang.h (GROW_VECT): Add cast.
---
 gdb/ada-lang.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h
index 62896f1..32c4b55 100644
--- a/gdb/ada-lang.h
+++ b/gdb/ada-lang.h
@@ -147,7 +147,7 @@ struct ada_task_info
    least M objects, updating V and S as necessary.  */
 
 #define GROW_VECT(v, s, m)                                    \
-   if ((s) < (m)) (v) = grow_vect (v, &(s), m, sizeof *(v));
+   if ((s) < (m)) (v) = (typeof (v)) grow_vect (v, &(s), m, sizeof *(v));
 
 extern void *grow_vect (void *, size_t *, size_t, int);
 
-- 
2.6.2


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH c++ 12/12] ada-lang.h: Add cast in GROW_VECT
  2015-10-26 10:38 ` [PATCH c++ 12/12] ada-lang.h: Add cast in GROW_VECT Simon Marchi
@ 2015-10-26 23:09   ` Pedro Alves
  2015-10-27  9:54     ` Simon Marchi
  0 siblings, 1 reply; 7+ messages in thread
From: Pedro Alves @ 2015-10-26 23:09 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

On 10/26/2015 03:49 AM, Simon Marchi wrote:
> The assignment requires a cast in C++.
> 
> gdb/ChangeLog:
> 
> 	* ada-lang.h (GROW_VECT): Add cast.
> ---
>  gdb/ada-lang.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h
> index 62896f1..32c4b55 100644
> --- a/gdb/ada-lang.h
> +++ b/gdb/ada-lang.h
> @@ -147,7 +147,7 @@ struct ada_task_info
>     least M objects, updating V and S as necessary.  */
>  
>  #define GROW_VECT(v, s, m)                                    \
> -   if ((s) < (m)) (v) = grow_vect (v, &(s), m, sizeof *(v));
> +   if ((s) < (m)) (v) = (typeof (v)) grow_vect (v, &(s), m, sizeof *(v));
>  

typeof in C is a GCC extension.  Probably not all compilers support it.

In my branch I just have:

  #define GROW_VECT(v, s, m)                                    \
 -   if ((s) < (m)) (v) = grow_vect (v, &(s), m, sizeof *(v));
 +   if ((s) < (m)) (v) = (char *) grow_vect (v, &(s), m, sizeof *(v));

Because that works for all current uses of GROW_VECT.

If we wanted to make this work for random types, then we could add
a type parameter to the GROW_VECT macro, like:

- #define GROW_VECT(v, s, m)                                    \
-   if ((s) < (m)) (v) = grow_vect (v, &(s), m, sizeof *(v));
+ #define GROW_VECT(t, v, s, m)                                    \
+   if ((s) < (m)) (v) = (t *) grow_vect (v, &(s), m, sizeof *(v));

Not sure it's worth it though.  It then raises the question of
"why not replace this home grown GROW_VECT stuff with a VEC instead".

Thanks,
Pedro Alves


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH c++ 12/12] ada-lang.h: Add cast in GROW_VECT
  2015-10-26 23:09   ` Pedro Alves
@ 2015-10-27  9:54     ` Simon Marchi
  2015-10-27 14:55       ` Pedro Alves
  0 siblings, 1 reply; 7+ messages in thread
From: Simon Marchi @ 2015-10-27  9:54 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches

On 26/10/15 12:50 PM, Pedro Alves wrote:
> On 10/26/2015 03:49 AM, Simon Marchi wrote:
>> The assignment requires a cast in C++.
>>
>> gdb/ChangeLog:
>>
>> 	* ada-lang.h (GROW_VECT): Add cast.
>> ---
>>  gdb/ada-lang.h | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h
>> index 62896f1..32c4b55 100644
>> --- a/gdb/ada-lang.h
>> +++ b/gdb/ada-lang.h
>> @@ -147,7 +147,7 @@ struct ada_task_info
>>     least M objects, updating V and S as necessary.  */
>>  
>>  #define GROW_VECT(v, s, m)                                    \
>> -   if ((s) < (m)) (v) = grow_vect (v, &(s), m, sizeof *(v));
>> +   if ((s) < (m)) (v) = (typeof (v)) grow_vect (v, &(s), m, sizeof *(v));
>>  
> 
> typeof in C is a GCC extension.  Probably not all compilers support it.
> 
> In my branch I just have:
> 
>   #define GROW_VECT(v, s, m)                                    \
>  -   if ((s) < (m)) (v) = grow_vect (v, &(s), m, sizeof *(v));
>  +   if ((s) < (m)) (v) = (char *) grow_vect (v, &(s), m, sizeof *(v));
> 
> Because that works for all current uses of GROW_VECT.
> 
> If we wanted to make this work for random types, then we could add
> a type parameter to the GROW_VECT macro, like:
> 
> - #define GROW_VECT(v, s, m)                                    \
> -   if ((s) < (m)) (v) = grow_vect (v, &(s), m, sizeof *(v));
> + #define GROW_VECT(t, v, s, m)                                    \
> +   if ((s) < (m)) (v) = (t *) grow_vect (v, &(s), m, sizeof *(v));
> 
> Not sure it's worth it though.  It then raises the question of
> "why not replace this home grown GROW_VECT stuff with a VEC instead".
> 
> Thanks,
> Pedro Alves

I thought about changing it for a proper VEC, but it's not really in the scope of
the C++ changes.  If I side-track on things like this, it will take an eternity!
And I feel that at this moment, it would be a risk of introducing bugs without
added value.

Is it ok if I simply push your version that adds the (char *) in the macro?  It
seems like the most efficient fix given the situation.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH c++ 11/12] target.c: Add a cast and change a type
  2015-10-26 10:23 [PATCH c++ 11/12] target.c: Add a cast and change a type Simon Marchi
  2015-10-26 10:38 ` [PATCH c++ 12/12] ada-lang.h: Add cast in GROW_VECT Simon Marchi
@ 2015-10-27  9:54 ` Simon Marchi
  1 sibling, 0 replies; 7+ messages in thread
From: Simon Marchi @ 2015-10-27  9:54 UTC (permalink / raw)
  To: gdb-patches

I pushed this one, I consider it obvious enough.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH c++ 12/12] ada-lang.h: Add cast in GROW_VECT
  2015-10-27  9:54     ` Simon Marchi
@ 2015-10-27 14:55       ` Pedro Alves
  2015-10-27 16:00         ` Simon Marchi
  0 siblings, 1 reply; 7+ messages in thread
From: Pedro Alves @ 2015-10-27 14:55 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

On 10/27/2015 02:34 AM, Simon Marchi wrote:
> On 26/10/15 12:50 PM, Pedro Alves wrote:

>> typeof in C is a GCC extension.  Probably not all compilers support it.
>>
>> In my branch I just have:
>>
>>   #define GROW_VECT(v, s, m)                                    \
>>  -   if ((s) < (m)) (v) = grow_vect (v, &(s), m, sizeof *(v));
>>  +   if ((s) < (m)) (v) = (char *) grow_vect (v, &(s), m, sizeof *(v));
>>
>> Because that works for all current uses of GROW_VECT.
>>
>> If we wanted to make this work for random types, then we could add
>> a type parameter to the GROW_VECT macro, like:
>>
>> - #define GROW_VECT(v, s, m)                                    \
>> -   if ((s) < (m)) (v) = grow_vect (v, &(s), m, sizeof *(v));
>> + #define GROW_VECT(t, v, s, m)                                    \
>> +   if ((s) < (m)) (v) = (t *) grow_vect (v, &(s), m, sizeof *(v));
>>
>> Not sure it's worth it though.  It then raises the question of
>> "why not replace this home grown GROW_VECT stuff with a VEC instead".

> I thought about changing it for a proper VEC, but it's not really in the scope of
> the C++ changes.  If I side-track on things like this, it will take an eternity!
> And I feel that at this moment, it would be a risk of introducing bugs without
> added value.
> 
> Is it ok if I simply push your version that adds the (char *) in the macro?  It
> seems like the most efficient fix given the situation.

It's certainly fine with me.

Thanks,
Pedro Alves


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH c++ 12/12] ada-lang.h: Add cast in GROW_VECT
  2015-10-27 14:55       ` Pedro Alves
@ 2015-10-27 16:00         ` Simon Marchi
  0 siblings, 0 replies; 7+ messages in thread
From: Simon Marchi @ 2015-10-27 16:00 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

On 27/10/15 08:13 AM, Pedro Alves wrote:
> It's certainly fine with me.
> 
> Thanks,
> Pedro Alves

Ok, pushed.


From a480de357b17b1b2057b8375284079ccafae39db Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@polymtl.ca>
Date: Tue, 27 Oct 2015 09:27:40 -0400
Subject: [PATCH] ada-lang.h: Add cast in GROW_VECT

The assignment requires a cast in C++.  We only use this macro for
vectors of chars, so adding (char *) diretly will do for now.

gdb/ChangeLog:

	* ada-lang.h (GROW_VECT): Add cast.
---
 gdb/ChangeLog  | 4 ++++
 gdb/ada-lang.h | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 27ea4f6..7b78890 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,7 @@
+2015-10-27  Simon Marchi  <simon.marchi@polymtl.ca>
+
+	* ada-lang.h (GROW_VECT): Add cast.
+
 2015-10-26  Doug Evans  <xdje42@gmail.com>
 
 	* symtab.h (struct general_symbol_info> <ada_mangled>: Update comment.
diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h
index 62896f1..7c527cc 100644
--- a/gdb/ada-lang.h
+++ b/gdb/ada-lang.h
@@ -147,7 +147,7 @@ struct ada_task_info
    least M objects, updating V and S as necessary.  */
 
 #define GROW_VECT(v, s, m)                                    \
-   if ((s) < (m)) (v) = grow_vect (v, &(s), m, sizeof *(v));
+   if ((s) < (m)) (v) = (char *) grow_vect (v, &(s), m, sizeof *(v));
 
 extern void *grow_vect (void *, size_t *, size_t, int);
 
-- 
2.6.1



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-10-27 13:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-26 10:23 [PATCH c++ 11/12] target.c: Add a cast and change a type Simon Marchi
2015-10-26 10:38 ` [PATCH c++ 12/12] ada-lang.h: Add cast in GROW_VECT Simon Marchi
2015-10-26 23:09   ` Pedro Alves
2015-10-27  9:54     ` Simon Marchi
2015-10-27 14:55       ` Pedro Alves
2015-10-27 16:00         ` Simon Marchi
2015-10-27  9:54 ` [PATCH c++ 11/12] target.c: Add a cast and change a type Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox