[20/23] Revert 'Remove unused struct serial::name field'

Message ID 20190906232807.6191-21-palves@redhat.com
State New, archived
Headers

Commit Message

Pedro Alves Sept. 6, 2019, 11:28 p.m. UTC
  This commit reverts:

 commit 5f5219fc34f7557296272230123a3837960a6f09
 Author:     Pedro Alves <palves@redhat.com>
 AuthorDate: Tue Apr 12 16:49:30 2016 +0100

     Remove unused struct serial::name field

The following patches will add uses for the field.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	Revert:
	2016-04-12  Pedro Alves  <palves@redhat.com>
	* serial.c (serial_open, serial_fdopen_ops, do_serial_close):
	Remove references to name.
	* serial.h (struct serial) <name>: Delete.
---
 gdb/serial.c | 4 ++++
 gdb/serial.h | 1 +
 2 files changed, 5 insertions(+)
  

Comments

Terekhov, Mikhail via Gdb-patches Sept. 6, 2019, 11:47 p.m. UTC | #1
Have you considered making this an std::string to avoid needing the manual
xfree?

On Fri, Sep 6, 2019, 18:29 Pedro Alves <palves@redhat.com> wrote:

> This commit reverts:
>
>  commit 5f5219fc34f7557296272230123a3837960a6f09
>  Author:     Pedro Alves <palves@redhat.com>
>  AuthorDate: Tue Apr 12 16:49:30 2016 +0100
>
>      Remove unused struct serial::name field
>
> The following patches will add uses for the field.
>
> gdb/ChangeLog:
> yyyy-mm-dd  Pedro Alves  <palves@redhat.com>
>
>         Revert:
>         2016-04-12  Pedro Alves  <palves@redhat.com>
>         * serial.c (serial_open, serial_fdopen_ops, do_serial_close):
>         Remove references to name.
>         * serial.h (struct serial) <name>: Delete.
> ---
>  gdb/serial.c | 4 ++++
>  gdb/serial.h | 1 +
>  2 files changed, 5 insertions(+)
>
> diff --git a/gdb/serial.c b/gdb/serial.c
> index a881bbc97c..0ed3d37406 100644
> --- a/gdb/serial.c
> +++ b/gdb/serial.c
> @@ -247,6 +247,7 @@ serial_open_ops_1 (const struct serial_ops *ops, const
> char *open_name)
>        return NULL;
>      }
>
> +  scb->name = open_name != NULL ? xstrdup (open_name) : NULL;
>    scb->next = scb_base;
>    scb_base = scb;
>
> @@ -291,6 +292,7 @@ serial_fdopen_ops (const int fd, const struct
> serial_ops *ops)
>
>    scb = new_serial (ops);
>
> +  scb->name = NULL;
>    scb->next = scb_base;
>    scb_base = scb;
>
> @@ -330,6 +332,8 @@ do_serial_close (struct serial *scb, int really_close)
>    if (really_close)
>      scb->ops->close (scb);
>
> +  xfree (scb->name);
> +
>    /* For serial_is_open.  */
>    scb->bufp = NULL;
>
> diff --git a/gdb/serial.h b/gdb/serial.h
> index b75b3666e7..d58ab660e9 100644
> --- a/gdb/serial.h
> +++ b/gdb/serial.h
> @@ -240,6 +240,7 @@ struct serial
>                                    buffer.  -ve for sticky errors.  */
>      unsigned char *bufp;       /* Current byte */
>      unsigned char buf[BUFSIZ]; /* Da buffer itself */
> +    char *name;                        /* The name of the device or host
> */
>      struct serial *next;       /* Pointer to the next `struct serial *' */
>      int debug_p;               /* Trace this serial devices operation.  */
>      int async_state;           /* Async internal state.  */
> --
> 2.14.5
>
>
  
Pedro Alves Sept. 8, 2019, 7:30 p.m. UTC | #2
On 9/7/19 12:47 AM, Christian Biesinger via gdb-patches wrote:
> Have you considered making this an std::string to avoid needing the manual
> xfree?
> 

struct serial hasn't been C++fied yet, it is still allocated with
malloc (XCNEW), so we can't use std::string without further changes.

So I stuck with just reverting the original patch as is, thinking that
a change to use std::string or something like that could be done along
other C++ification changes.

Thanks,
Pedro Alves

> On Fri, Sep 6, 2019, 18:29 Pedro Alves <palves@redhat.com> wrote:
> 
>> This commit reverts:
>>
>>  commit 5f5219fc34f7557296272230123a3837960a6f09
>>  Author:     Pedro Alves <palves@redhat.com>
>>  AuthorDate: Tue Apr 12 16:49:30 2016 +0100
>>
>>      Remove unused struct serial::name field
>>
>> The following patches will add uses for the field.
>>
>> gdb/ChangeLog:
>> yyyy-mm-dd  Pedro Alves  <palves@redhat.com>
>>
>>         Revert:
>>         2016-04-12  Pedro Alves  <palves@redhat.com>
>>         * serial.c (serial_open, serial_fdopen_ops, do_serial_close):
>>         Remove references to name.
>>         * serial.h (struct serial) <name>: Delete.
>> ---
>>  gdb/serial.c | 4 ++++
>>  gdb/serial.h | 1 +
>>  2 files changed, 5 insertions(+)
>>
>> diff --git a/gdb/serial.c b/gdb/serial.c
>> index a881bbc97c..0ed3d37406 100644
>> --- a/gdb/serial.c
>> +++ b/gdb/serial.c
>> @@ -247,6 +247,7 @@ serial_open_ops_1 (const struct serial_ops *ops, const
>> char *open_name)
>>        return NULL;
>>      }
>>
>> +  scb->name = open_name != NULL ? xstrdup (open_name) : NULL;
>>    scb->next = scb_base;
>>    scb_base = scb;
>>
>> @@ -291,6 +292,7 @@ serial_fdopen_ops (const int fd, const struct
>> serial_ops *ops)
>>
>>    scb = new_serial (ops);
>>
>> +  scb->name = NULL;
>>    scb->next = scb_base;
>>    scb_base = scb;
>>
>> @@ -330,6 +332,8 @@ do_serial_close (struct serial *scb, int really_close)
>>    if (really_close)
>>      scb->ops->close (scb);
>>
>> +  xfree (scb->name);
>> +
>>    /* For serial_is_open.  */
>>    scb->bufp = NULL;
>>
>> diff --git a/gdb/serial.h b/gdb/serial.h
>> index b75b3666e7..d58ab660e9 100644
>> --- a/gdb/serial.h
>> +++ b/gdb/serial.h
>> @@ -240,6 +240,7 @@ struct serial
>>                                    buffer.  -ve for sticky errors.  */
>>      unsigned char *bufp;       /* Current byte */
>>      unsigned char buf[BUFSIZ]; /* Da buffer itself */
>> +    char *name;                        /* The name of the device or host
>> */
>>      struct serial *next;       /* Pointer to the next `struct serial *' */
>>      int debug_p;               /* Trace this serial devices operation.  */
>>      int async_state;           /* Async internal state.  */
>> --
>> 2.14.5
>>
>>
  

Patch

diff --git a/gdb/serial.c b/gdb/serial.c
index a881bbc97c..0ed3d37406 100644
--- a/gdb/serial.c
+++ b/gdb/serial.c
@@ -247,6 +247,7 @@  serial_open_ops_1 (const struct serial_ops *ops, const char *open_name)
       return NULL;
     }
 
+  scb->name = open_name != NULL ? xstrdup (open_name) : NULL;
   scb->next = scb_base;
   scb_base = scb;
 
@@ -291,6 +292,7 @@  serial_fdopen_ops (const int fd, const struct serial_ops *ops)
 
   scb = new_serial (ops);
 
+  scb->name = NULL;
   scb->next = scb_base;
   scb_base = scb;
 
@@ -330,6 +332,8 @@  do_serial_close (struct serial *scb, int really_close)
   if (really_close)
     scb->ops->close (scb);
 
+  xfree (scb->name);
+
   /* For serial_is_open.  */
   scb->bufp = NULL;
 
diff --git a/gdb/serial.h b/gdb/serial.h
index b75b3666e7..d58ab660e9 100644
--- a/gdb/serial.h
+++ b/gdb/serial.h
@@ -240,6 +240,7 @@  struct serial
 				   buffer.  -ve for sticky errors.  */
     unsigned char *bufp;	/* Current byte */
     unsigned char buf[BUFSIZ];	/* Da buffer itself */
+    char *name;			/* The name of the device or host */
     struct serial *next;	/* Pointer to the next `struct serial *' */
     int debug_p;		/* Trace this serial devices operation.  */
     int async_state;		/* Async internal state.  */