This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFA 01/22] Change selttest.c to use use std::vector
- From: Tom Tromey <tom at tromey dot com>
- To: gdb-patches at sourceware dot org
- Cc: Tom Tromey <tom at tromey dot com>
- Date: Mon, 26 Sep 2016 22:08:29 -0600
- Subject: [RFA 01/22] Change selttest.c to use use std::vector
- Authentication-results: sourceware.org; auth=none
- References: <1474949330-4307-1-git-send-email-tom@tromey.com>
This patch changes selftest.c to use std::vector rather than VEC.
I think this is a small net plus. Because we're using C++03, we
unfortunately don't all the possible benefits here; namely, iterating
over a vector is still a pain. For reference, in C++11 the loop would
be just:
for (auto f : tests)
...
2016-09-26 Tom Tromey <tom@tromey.com>
* selftest.c: Include <vector>, not "vec.h".
(self_test_function_ptr): Remove.
(tests): Now a std::vector.
(register_self_test, run_self_tests): Update.
---
gdb/ChangeLog | 7 +++++++
gdb/selftest.c | 22 +++++++++-------------
2 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index a9ef3ee..2f28e54 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2016-09-26 Tom Tromey <tom@tromey.com>
+
+ * selftest.c: Include <vector>, not "vec.h".
+ (self_test_function_ptr): Remove.
+ (tests): Now a std::vector.
+ (register_self_test, run_self_tests): Update.
+
2016-09-23 Jon Turney <jon.turney@dronecode.org.uk>
* windows-nat.c (windows_delete_thread): Adjusting call to
diff --git a/gdb/selftest.c b/gdb/selftest.c
index c63c06d..bbd37b5 100644
--- a/gdb/selftest.c
+++ b/gdb/selftest.c
@@ -18,22 +18,18 @@
#include "defs.h"
#include "selftest.h"
-#include "vec.h"
-
-typedef self_test_function *self_test_function_ptr;
-
-DEF_VEC_P (self_test_function_ptr);
+#include <vector>
/* All the tests that have been registered. */
-static VEC (self_test_function_ptr) *tests;
+static std::vector<self_test_function *> tests;
/* See selftest.h. */
void
register_self_test (self_test_function *function)
{
- VEC_safe_push (self_test_function_ptr, tests, function);
+ tests.push_back (function);
}
/* See selftest.h. */
@@ -41,17 +37,17 @@ register_self_test (self_test_function *function)
void
run_self_tests (void)
{
- int i;
- self_test_function_ptr func;
int failed = 0;
- for (i = 0; VEC_iterate (self_test_function_ptr, tests, i, func); ++i)
+ for (std::vector<self_test_function *>::iterator iter = tests.begin ();
+ iter != tests.end ();
+ ++iter)
{
QUIT;
TRY
{
- (*func) ();
+ (*iter) ();
}
CATCH (ex, RETURN_MASK_ERROR)
{
@@ -62,6 +58,6 @@ run_self_tests (void)
END_CATCH
}
- printf_filtered (_("Ran %u unit tests, %d failed\n"),
- VEC_length (self_test_function_ptr, tests), failed);
+ printf_filtered (_("Ran %lu unit tests, %d failed\n"),
+ tests.size (), failed);
}
--
2.7.4