On Mon, 21 Aug 2023 at 21:20, François Dumont <frs.dum...@gmail.com> wrote:
>
> Here is the updated and tested patch.

OK for trunk, thanks.

We could consider it for the branches too (I'm going to remove the
global strings on the gcc-13 branch tomorrow).


>
> On 21/08/2023 20:07, Jonathan Wakely wrote:
> > On Mon, 21 Aug 2023 at 18:05, François Dumont via Libstdc++
> > <libstd...@gcc.gnu.org> wrote:
> >> Hi
> >>
> >> Here is a propocal to fix tests sensitive to libstdc++ internal 
> >> allocations.
> > Surely the enter() and exit() calls should be a constructor and destructor?
> >
> > The constructor could use count() to get the count, and then restore
> > it in the destructor. Something like:
> >
> > --- a/libstdc++-v3/testsuite/util/replacement_memory_operators.h
> > +++ b/libstdc++-v3/testsuite/util/replacement_memory_operators.h
> > @@ -75,12 +75,30 @@ namespace __gnu_test
> >        counter& cntr = get();
> >        cntr._M_increments = cntr._M_decrements = 0;
> >      }
> > +
> > +    struct scope
> > +    {
> > +      scope() : _M_count(counter::count()) { }
> > +      ~scope() { counter::get()._M_count = _M_count; }
> > +
> > +    private:
> > +      std::size_t _M_count;
> > +
> > +#if __cplusplus >= 201103L
> > +      scope(const scope&) = delete;
> > +      scope& operator=(const scope&) = delete;
> > +#else
> > +      scope(const scope&);
> > +      scope& operator=(const scope&);
> > +#endif
> > +    };
> >    };
> >
> >    template<typename Alloc, bool uses_global_new>
> >      bool
> >      check_new(Alloc a = Alloc())
> >      {
> > +      __gnu_test::counter::scope s;
> >        __gnu_test::counter::exceptions(false);
> >        __gnu_test::counter::reset();
> >        (void) a.allocate(10);
> >
> >
> >
> >
> >
> >
> >> Tested by restoring allocation in tzdb.cc.
> >>
> >> As announced I'm also adding a test to detect such allocations. If it is
> >> ok let me know if you prefer to see it in a different place.
> > The test is a good idea. I think 17_intro/no_library_allocation.cc
> > would be a better place for it.
> >
> >>       libstdc++: Fix tests relying on operator new/delete overload
> >>
> >>       Fix tests that are checking for an allocation plan. They are failing 
> >> if
> >>       an allocation is taking place outside the test.
> >>
> >>       libstdc++-v3/ChangeLog
> >>
> >>               * testsuite/util/replacement_memory_operators.h
> >>               (counter::_M_pre_enter_count): New.
> >>               (counter::enter, counter::exit): New static methods to call
> >> on main() enter/exit.
> >>               * testsuite/23_containers/unordered_map/96088.cc (main):
> >>               Call __gnu_test::counter::enter/exit.
> >>               * testsuite/23_containers/unordered_multimap/96088.cc
> >> (main): Likewise.
> >>               * testsuite/23_containers/unordered_multiset/96088.cc
> >> (main): Likewise.
> >>               * testsuite/23_containers/unordered_set/96088.cc (main):
> >> Likewise.
> >>               * testsuite/ext/malloc_allocator/deallocate_local.cc
> >> (main): Likewise.
> >>               * testsuite/ext/new_allocator/deallocate_local.cc (main):
> >> Likewise.
> >>               * testsuite/ext/throw_allocator/deallocate_local.cc (main):
> >> Likewise.
> >>               * testsuite/ext/pool_allocator/allocate_chunk.cc (started):
> >> New global.
> >>               (operator new(size_t)): Check started.
> >>               (main): Set/Unset started.
> >>               * testsuite/ext/no_library_allocation.cc: New test case.
> >>
> >> Ok to commit ?
> >>
> >> François

Reply via email to