Make open_fds an std::vector

Simple replacement of VEC with std::vector.

gdb/ChangeLog:

	* common/filestuff.c: Include <algorithm>.
	(open_fds): Change type to std::vector<int>.
	(do_mark_open_fd): Adjust.
	(unmark_fd_no_cloexec): Adjust.
	(do_close): Adjust.
This commit is contained in:
Simon Marchi 2017-11-17 13:02:24 -05:00 committed by Simon Marchi
parent 5c63242595
commit 37269bc92c
2 changed files with 19 additions and 19 deletions

View File

@ -1,3 +1,11 @@
2017-11-17 Simon Marchi <simon.marchi@polymtl.ca>
* common/filestuff.c: Include <algorithm>.
(open_fds): Change type to std::vector<int>.
(do_mark_open_fd): Adjust.
(unmark_fd_no_cloexec): Adjust.
(do_close): Adjust.
2017-11-17 Simon Marchi <simon.marchi@polymtl.ca> 2017-11-17 Simon Marchi <simon.marchi@polymtl.ca>
* breakpoint.c (output_thread_groups): Take an std::vector. * breakpoint.c (output_thread_groups): Take an std::vector.

View File

@ -23,6 +23,7 @@
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <algorithm>
#ifdef USE_WIN32API #ifdef USE_WIN32API
#include <winsock2.h> #include <winsock2.h>
@ -146,11 +147,10 @@ fdwalk (int (*func) (void *, int), void *arg)
/* A VEC holding all the fds open when notice_open_fds was called. We /* A vector holding all the fds open when notice_open_fds was called. We
don't use a hashtab because libiberty isn't linked into gdbserver; don't use a hashtab because we don't expect there to be many open fds. */
and anyway we don't expect there to be many open fds. */
static VEC (int) *open_fds; static std::vector<int> open_fds;
/* An fdwalk callback function used by notice_open_fds. It puts the /* An fdwalk callback function used by notice_open_fds. It puts the
given file descriptor into the vec. */ given file descriptor into the vec. */
@ -158,7 +158,7 @@ static VEC (int) *open_fds;
static int static int
do_mark_open_fd (void *ignore, int fd) do_mark_open_fd (void *ignore, int fd)
{ {
VEC_safe_push (int, open_fds, fd); open_fds.push_back (fd);
return 0; return 0;
} }
@ -183,18 +183,12 @@ mark_fd_no_cloexec (int fd)
void void
unmark_fd_no_cloexec (int fd) unmark_fd_no_cloexec (int fd)
{ {
int i, val; auto it = std::remove (open_fds.begin (), open_fds.end (), fd);
for (i = 0; VEC_iterate (int, open_fds, i, val); ++i) if (it != open_fds.end ())
{ open_fds.erase (it);
if (fd == val) else
{ gdb_assert_not_reached (_("fd not found in open_fds"));
VEC_unordered_remove (int, open_fds, i);
return;
}
}
gdb_assert_not_reached (_("fd not found in open_fds"));
} }
/* Helper function for close_most_fds that closes the file descriptor /* Helper function for close_most_fds that closes the file descriptor
@ -203,9 +197,7 @@ unmark_fd_no_cloexec (int fd)
static int static int
do_close (void *ignore, int fd) do_close (void *ignore, int fd)
{ {
int i, val; for (int val : open_fds)
for (i = 0; VEC_iterate (int, open_fds, i, val); ++i)
{ {
if (fd == val) if (fd == val)
{ {