mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-01-18 14:04:24 +08:00
make serial_ops const
I noticed that the serial_ops vtable is not const, but really it ought to be. This patch constifies it, removing the only mutable field in the process. Tested by rebuilding on x86-64 Fedora 18, both natively and using the mingw cross tools. 2013-12-19 Tom Tromey <tromey@redhat.com> * serial.c (serial_ops_p): New typedef. (serial_ops_list): Now a VEC. (serial_interface_lookup): Return const. Use VEC_iterate. (serial_add_interface): Make parameter const. (serial_open): Update. (serial_fdopen_ops): Make 'ops' const. (serial_pipe): Update. * ser-tcp.c (_initialize_ser_tcp): Update. * ser-pipe.c (_initialize_ser_pipe): Update. * ser-unix.c (_initialize_ser_hardwire): Update. * ser-mingw.c (_initialize_ser_windows): Update. * ser-go32.c (dos_ops): Now const. Update. * serial.h (struct serial) <ops>: Now const. (struct serial_ops) <next>: Remove. (serial_add_interface): Make parameter const.
This commit is contained in:
parent
d493b2839b
commit
fcd488ca4e
@ -1,3 +1,21 @@
|
||||
2013-12-19 Tom Tromey <tromey@redhat.com>
|
||||
|
||||
* serial.c (serial_ops_p): New typedef.
|
||||
(serial_ops_list): Now a VEC.
|
||||
(serial_interface_lookup): Return const. Use VEC_iterate.
|
||||
(serial_add_interface): Make parameter const.
|
||||
(serial_open): Update.
|
||||
(serial_fdopen_ops): Make 'ops' const.
|
||||
(serial_pipe): Update.
|
||||
* ser-tcp.c (_initialize_ser_tcp): Update.
|
||||
* ser-pipe.c (_initialize_ser_pipe): Update.
|
||||
* ser-unix.c (_initialize_ser_hardwire): Update.
|
||||
* ser-mingw.c (_initialize_ser_windows): Update.
|
||||
* ser-go32.c (dos_ops): Now const. Update.
|
||||
* serial.h (struct serial) <ops>: Now const.
|
||||
(struct serial_ops) <next>: Remove.
|
||||
(serial_add_interface): Make parameter const.
|
||||
|
||||
2013-12-18 Yufeng Zhang <yufeng.zhang@arm.com>
|
||||
|
||||
* aarch64-linux-nat.c (aarch64_linux_set_debug_regs): Set
|
||||
|
@ -848,10 +848,9 @@ dos_sendbreak (struct serial *scb)
|
||||
}
|
||||
|
||||
|
||||
static struct serial_ops dos_ops =
|
||||
static const struct serial_ops dos_ops =
|
||||
{
|
||||
"hardwire",
|
||||
0,
|
||||
dos_open,
|
||||
dos_close,
|
||||
NULL, /* fdopen, not implemented */
|
||||
|
@ -1232,7 +1232,6 @@ _initialize_ser_windows (void)
|
||||
ops = XMALLOC (struct serial_ops);
|
||||
memset (ops, 0, sizeof (struct serial_ops));
|
||||
ops->name = "hardwire";
|
||||
ops->next = 0;
|
||||
ops->open = ser_windows_open;
|
||||
ops->close = ser_windows_close;
|
||||
|
||||
@ -1268,7 +1267,6 @@ _initialize_ser_windows (void)
|
||||
memset (ops, 0, sizeof (struct serial_ops));
|
||||
|
||||
ops->name = "terminal";
|
||||
ops->next = 0;
|
||||
|
||||
ops->close = ser_console_close;
|
||||
ops->get_tty_state = ser_console_get_tty_state;
|
||||
@ -1287,7 +1285,6 @@ _initialize_ser_windows (void)
|
||||
ops = XMALLOC (struct serial_ops);
|
||||
memset (ops, 0, sizeof (struct serial_ops));
|
||||
ops->name = "pipe";
|
||||
ops->next = 0;
|
||||
ops->open = pipe_windows_open;
|
||||
ops->close = pipe_windows_close;
|
||||
ops->fdopen = pipe_windows_fdopen;
|
||||
@ -1323,7 +1320,6 @@ _initialize_ser_windows (void)
|
||||
ops = XMALLOC (struct serial_ops);
|
||||
memset (ops, 0, sizeof (struct serial_ops));
|
||||
ops->name = "tcp";
|
||||
ops->next = 0;
|
||||
ops->open = net_windows_open;
|
||||
ops->close = net_windows_close;
|
||||
ops->readchar = ser_base_readchar;
|
||||
|
@ -213,7 +213,6 @@ _initialize_ser_pipe (void)
|
||||
|
||||
memset (ops, 0, sizeof (struct serial_ops));
|
||||
ops->name = "pipe";
|
||||
ops->next = 0;
|
||||
ops->open = pipe_open;
|
||||
ops->close = pipe_close;
|
||||
ops->readchar = ser_base_readchar;
|
||||
|
@ -385,7 +385,6 @@ _initialize_ser_tcp (void)
|
||||
ops = XMALLOC (struct serial_ops);
|
||||
memset (ops, 0, sizeof (struct serial_ops));
|
||||
ops->name = "tcp";
|
||||
ops->next = 0;
|
||||
ops->open = net_open;
|
||||
ops->close = net_close;
|
||||
ops->readchar = ser_base_readchar;
|
||||
|
@ -912,7 +912,6 @@ _initialize_ser_hardwire (void)
|
||||
|
||||
memset (ops, 0, sizeof (struct serial_ops));
|
||||
ops->name = "hardwire";
|
||||
ops->next = 0;
|
||||
ops->open = hardwire_open;
|
||||
ops->close = hardwire_close;
|
||||
/* FIXME: Don't replace this with the equivalent ser_base*() until
|
||||
|
27
gdb/serial.c
27
gdb/serial.c
@ -30,9 +30,12 @@ extern void _initialize_serial (void);
|
||||
|
||||
static unsigned int global_serial_debug_p;
|
||||
|
||||
/* Linked list of serial I/O handlers. */
|
||||
typedef const struct serial_ops *serial_ops_p;
|
||||
DEF_VEC_P (serial_ops_p);
|
||||
|
||||
static struct serial_ops *serial_ops_list = NULL;
|
||||
/* Serial I/O handlers. */
|
||||
|
||||
VEC (serial_ops_p) *serial_ops_list = NULL;
|
||||
|
||||
/* Pointer to list of scb's. */
|
||||
|
||||
@ -44,7 +47,7 @@ static struct serial *scb_base;
|
||||
static char *serial_logfile = NULL;
|
||||
static struct ui_file *serial_logfp = NULL;
|
||||
|
||||
static struct serial_ops *serial_interface_lookup (const char *);
|
||||
static const struct serial_ops *serial_interface_lookup (const char *);
|
||||
static void serial_logchar (struct ui_file *stream,
|
||||
int ch_type, int ch, int timeout);
|
||||
static const char logbase_hex[] = "hex";
|
||||
@ -143,12 +146,13 @@ serial_log_command (const char *cmd)
|
||||
}
|
||||
|
||||
|
||||
static struct serial_ops *
|
||||
static const struct serial_ops *
|
||||
serial_interface_lookup (const char *name)
|
||||
{
|
||||
struct serial_ops *ops;
|
||||
const struct serial_ops *ops;
|
||||
int i;
|
||||
|
||||
for (ops = serial_ops_list; ops; ops = ops->next)
|
||||
for (i = 0; VEC_iterate (serial_ops_p, serial_ops_list, i, ops); ++i)
|
||||
if (strcmp (name, ops->name) == 0)
|
||||
return ops;
|
||||
|
||||
@ -156,10 +160,9 @@ serial_interface_lookup (const char *name)
|
||||
}
|
||||
|
||||
void
|
||||
serial_add_interface (struct serial_ops *optable)
|
||||
serial_add_interface (const struct serial_ops *optable)
|
||||
{
|
||||
optable->next = serial_ops_list;
|
||||
serial_ops_list = optable;
|
||||
VEC_safe_push (serial_ops_p, serial_ops_list, optable);
|
||||
}
|
||||
|
||||
/* Return the open serial device for FD, if found, or NULL if FD is
|
||||
@ -183,7 +186,7 @@ struct serial *
|
||||
serial_open (const char *name)
|
||||
{
|
||||
struct serial *scb;
|
||||
struct serial_ops *ops;
|
||||
const struct serial_ops *ops;
|
||||
const char *open_name = name;
|
||||
|
||||
if (strcmp (name, "pc") == 0)
|
||||
@ -246,7 +249,7 @@ serial_open (const char *name)
|
||||
interface ops OPS. */
|
||||
|
||||
static struct serial *
|
||||
serial_fdopen_ops (const int fd, struct serial_ops *ops)
|
||||
serial_fdopen_ops (const int fd, const struct serial_ops *ops)
|
||||
{
|
||||
struct serial *scb;
|
||||
|
||||
@ -584,7 +587,7 @@ serial_done_wait_handle (struct serial *scb)
|
||||
int
|
||||
serial_pipe (struct serial *scbs[2])
|
||||
{
|
||||
struct serial_ops *ops;
|
||||
const struct serial_ops *ops;
|
||||
int fildes[2];
|
||||
|
||||
ops = serial_interface_lookup ("pipe");
|
||||
|
@ -228,7 +228,7 @@ struct serial
|
||||
If != -1, this descriptor should be non-blocking or
|
||||
ops->avail should be non-NULL. */
|
||||
int error_fd;
|
||||
struct serial_ops *ops; /* Function vector */
|
||||
const struct serial_ops *ops; /* Function vector */
|
||||
void *state; /* Local context info for open FD */
|
||||
serial_ttystate ttystate; /* Not used (yet) */
|
||||
int bufcnt; /* Amount of data remaining in receive
|
||||
@ -251,7 +251,6 @@ struct serial
|
||||
struct serial_ops
|
||||
{
|
||||
char *name;
|
||||
struct serial_ops *next;
|
||||
int (*open) (struct serial *, const char *name);
|
||||
void (*close) (struct serial *);
|
||||
int (*fdopen) (struct serial *, int fd);
|
||||
@ -301,7 +300,7 @@ struct serial_ops
|
||||
|
||||
/* Add a new serial interface to the interface list. */
|
||||
|
||||
extern void serial_add_interface (struct serial_ops * optable);
|
||||
extern void serial_add_interface (const struct serial_ops * optable);
|
||||
|
||||
/* File in which to record the remote debugging session. */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user