Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/allocator #100

Closed
wants to merge 5 commits into from
Closed

Hotfix/allocator #100

wants to merge 5 commits into from

Conversation

bassoy
Copy link
Collaborator

@bassoy bassoy commented Aug 5, 2020

This is a hotfix for issue #96 which should be merged ASAP.

std::allocator<T>::construct/destroy were deprecated in C++17 and removed in C++20, in favor of std::allocator_traits<T>::construct/destroy. (https://en.cppreference.com/w/cpp/memory/allocator_traits/construct). They are gone in gcc10. This fix switches to the the latter for C++17 and greater.
std::iterator was deprecated in C++17 and removed in C++20. I replaced the inheritance with the 5 equivalent typedefs, even though they're not all used by ublas, for compatibility in case clients depend on them.
@bassoy bassoy self-assigned this Aug 5, 2020
include/boost/numeric/ublas/storage.hpp Outdated Show resolved Hide resolved
include/boost/numeric/ublas/storage.hpp Outdated Show resolved Hide resolved
include/boost/numeric/ublas/storage.hpp Outdated Show resolved Hide resolved
include/boost/numeric/ublas/storage.hpp Outdated Show resolved Hide resolved
include/boost/numeric/ublas/storage.hpp Outdated Show resolved Hide resolved
include/boost/numeric/ublas/storage.hpp Outdated Show resolved Hide resolved
@jwakely
Copy link

jwakely commented Aug 5, 2020

You should really have tests that verify the code can be used with a minimal allocator that only provides the members required by a C++11 allocator (i.e. value_type, allocate, deallocate, and ==/!=). All other members should be accessed via allocator_traits to handle the case where the allocator doesn't provide them.

For testing libstdc++ I use:

  template <class Tp>
    struct SimpleAllocator
    {
      typedef Tp value_type;

      SimpleAllocator() noexcept { }

      template <class T>
        SimpleAllocator(const SimpleAllocator<T>&) { }

      Tp *allocate(std::size_t n)
      { return std::allocator<Tp>().allocate(n); }

      void deallocate(Tp *p, std::size_t n)
      { std::allocator<Tp>().deallocate(p, n); }
    };

  template <class T, class U>
    bool operator==(const SimpleAllocator<T>&, const SimpleAllocator<U>&)
    { return true; }
#if __cpp_impl_three_way_comparison < 201907L
  template <class T, class U>
    bool operator!=(const SimpleAllocator<T>&, const SimpleAllocator<U>&)
    { return false; }
#endif

@bassoy
Copy link
Collaborator Author

bassoy commented Aug 5, 2020

You should really have tests that verify the code can be used with a minimal allocator that only provides the members required by a C++11 allocator (i.e. value_type, allocate, deallocate, and ==/!=). All other members should be accessed via allocator_traits to handle the case where the allocator doesn't provide them.

Yes, the code coverage for some Boost.uBlas data types are poor.

For testing libstdc++ I use:

  template <class Tp>
    struct SimpleAllocator
    {
      typedef Tp value_type;

      SimpleAllocator() noexcept { }

      template <class T>
        SimpleAllocator(const SimpleAllocator<T>&) { }

      Tp *allocate(std::size_t n)
      { return std::allocator<Tp>().allocate(n); }

      void deallocate(Tp *p, std::size_t n)
      { std::allocator<Tp>().deallocate(p, n); }
    };

  template <class T, class U>
    bool operator==(const SimpleAllocator<T>&, const SimpleAllocator<U>&)
    { return true; }
#if __cpp_impl_three_way_comparison < 201907L
  template <class T, class U>
    bool operator!=(const SimpleAllocator<T>&, const SimpleAllocator<U>&)
    { return false; }
#endif

Thanks for providing the simple allocator. We are moving from one-/two- to multi-dimensional types (where one- or two dimensions will be special cases) making many of the current types obsoluete and therefore depcretated. Hence, our main focus will be on developing the multi-dimensional type.

@bassoy bassoy requested a review from mclow August 5, 2020 13:02
Copy link
Collaborator

@amitsingh19975 amitsingh19975 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@glenfe
Copy link
Member

glenfe commented Aug 5, 2020

This PR is not good. We don't want to use __cplusplus >= 201103L, if anything we would want to use !defined(BOOST_NO_CXX11_ALLOCATOR) but instead of all of that:

Edit: On top of that, you can't assume size_type and difference_type exist for every Allocator either. The same for max_size().

Just include <boost/core/allocator_access.hpp> and use the appropriate facilities from there. They do the right thing and support minimal allocators. This also avoids having to have conditional code depending on whether allocator_traits is available or not.

@bassoy
Copy link
Collaborator Author

bassoy commented Aug 6, 2020

This PR is not good. We don't want to use __cplusplus >= 201103L, if anything we would want to use !defined(BOOST_NO_CXX11_ALLOCATOR) but instead of all of that:

Just include <boost/core/allocator_access.hpp> and use the appropriate facilities from there. They do the right thing and support minimal allocators. This also avoids having to have conditional code depending on whether allocator_traits is available or not.

Thanks @glenfe
Do we have time left for merging master this into the boost 1.74 release?

@mclow
Copy link
Contributor

mclow commented Aug 6, 2020

The deadline for putting things into the 1.74.0 release was .. yesterday.
As far as I can tell, this hasn't been tested on develop, let alone "is ready to be merged to master". Is that correct?

@glenfe
Copy link
Member

glenfe commented Aug 6, 2020

See glenfe@937da38

I'll PR from my repository after adding some tests for minimal allocators.

@glenfe glenfe self-requested a review August 6, 2020 20:55
@bassoy
Copy link
Collaborator Author

bassoy commented Aug 6, 2020

@glenfe, I just wanted to update the PR using boost::core::allocator_accessor. :-)
Thanks for helping out here.

@bassoy bassoy removed their assignment Aug 6, 2020
@bassoy
Copy link
Collaborator Author

bassoy commented Aug 6, 2020

The deadline for putting things into the 1.74.0 release was .. yesterday.
As far as I can tell, this hasn't been tested on develop, let alone "is ready to be merged to master". Is that correct?

The unbounded_array is unit tested in AppVeyor and Travis. However, the test coverage might not be very high here.

@glenfe
Copy link
Member

glenfe commented Aug 11, 2020

@bassoy See https://github.com/boostorg/ublas/pull/103/files .

@bassoy
Copy link
Collaborator Author

bassoy commented Aug 11, 2020

@bassoy See https://github.com/boostorg/ublas/pull/103/files .

Thanks @glenfe.
Please note that this PR now also includes the boost::allocator_access as suggested and also includes boost::numeric::ublas::forward_iterator_base while the PR #103 includes test cases and some minor modifications in vector.h and storage_sparse.hpp.

To be consistent with the latter modifications, using boost::allocator_size_type and boost::allocator_difference_type I suggest to use these types also in matrix.h and then to merge it with the master branch.

@glenfe
Copy link
Member

glenfe commented Aug 12, 2020

PR #103 adjusts all places which use allocators, not just storage.hpp. What is it missing?

@bassoy
Copy link
Collaborator Author

bassoy commented Aug 12, 2020

PR #103 adjusts all places which use allocators, not just storage.hpp. What is it missing?

For the sake of consistency, using boost::allocator_size_type and boost::allocator_difference_type I suggest to use these types also in matrix.h.

I found three places in matrix.h

typedef typename ALLOC::size_type size_type;

typedef typename ALLOC::size_type size_type;

typedef typename ALLOC::size_type size_type;

@glenfe
Copy link
Member

glenfe commented Aug 12, 2020

@bassoy

For the sake of consistency, using boost::allocator_size_type and boost::allocator_difference_type I suggest to use these types also in matrix.h.

In #103 they are being used also in matrix.hpp.

@glenfe
Copy link
Member

glenfe commented Aug 12, 2020

If you look at #103 carefully, you'll see that it modifies the following files:

  • matrix.hpp
  • storage.hpp
  • storage_sparse.hpp
  • vector.hpp

@bassoy
Copy link
Collaborator Author

bassoy commented Aug 12, 2020

@bassoy

For the sake of consistency, using boost::allocator_size_type and boost::allocator_difference_type I suggest to use these types also in matrix.h.

In #103 they are being used also in matrix.hpp.

Great. I will close this PR and switch to the PR #103

@bassoy bassoy closed this Aug 12, 2020
@bassoy bassoy deleted the hotfix/allocator branch January 4, 2021 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants