This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFA 01/22] Change selttest.c to use use std::vector
On Tue, Sep 27, 2016 at 09:55:28AM -0600, Tom Tromey wrote:
> >>>>> "Trevor" == Trevor Saunders <tbsaunde@tbsaunde.org> writes:
>
> Trevor> I'd agree, hopefully we can throw VEC in the trash some day. Relatedly
> Trevor> we should probably move gcc's hash table stuff to include/ sooner rather
> Trevor> than later so we can similarly get rid of htab.
>
> That would be nice; though we could probably use std::set and std::map
> in gdb as well. One wrinkle with hash tables is that they're sometimes
> allocated on obstacks; would gcc's handle this?
No, they don't support that at the moment, though I suppose it would
be fine for keys or values to point into obstacks. Is there a good
reason for this other than using obstacks to provide a sort of automatic
memory management?
> >> for (auto f : tests)
>
> Trevor> its debatable, but imho its not necessarily obvious what the type of the
> Trevor> local is when you use auto to iterate over vectors especially when they
> Trevor> are members or globals like here.
>
> Yeah, that's one drawback.
> Often one actually wants "auto &f" in there.
yeah, and not having that can sometimes be bad.
> >> +static std::vector<self_test_function *> tests;
>
> Trevor> should we use a pointer to avoid the static initializer?
>
> I was on the fence about this one.
> On the one hand, static initializers can be very bad.
> On the other hand, this one in particular doesn't seem like it could
> cause problems.
yeah, I think its just zeroing some memory and then registering a static
destructor. So its silly that its necessary at all, but whether to
avoid it or not is just a perf question.
Trev
> >> - 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)
>
> Trevor> I believe you can "cheat" here and just use the function pointer type,
> Trevor> because the sane implementation of iterators over vectors is pointers.
>
> Yeah, or just loop using an int and index into the vector.
> I'll see if that looks cleaner.
>
> Tom