Several fixes for new memory model.
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Deukhoofd 2020-12-11 15:12:17 +01:00
parent 0e6ae18a32
commit efdce7b74c
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
5 changed files with 24 additions and 13 deletions

View File

@ -15,12 +15,14 @@ namespace ArbUt {
public: public:
/// @brief Initialise a BorrowedPtr with a specific raw pointer. /// @brief Initialise a BorrowedPtr with a specific raw pointer.
inline BorrowedPtr<T>(__attribute__((nonnull)) T* ptr) : _raw(ptr) { AssertNotNull(ptr); }; inline BorrowedPtr<T>(T* ptr) : _raw(ptr) { AssertNotNull(ptr); };
/// @brief Initialise a BorrowedPtr from a copy. /// @brief Initialise a BorrowedPtr from a copy.
inline BorrowedPtr<T>(const BorrowedPtr<T>& other) : _raw(other._raw){}; inline BorrowedPtr<T>(const BorrowedPtr<T>& other) : _raw(other._raw){};
/// @brief Initialise a BorrowedPtr with a std unique_ptr. /// @brief Initialise a BorrowedPtr with a std unique_ptr.
inline BorrowedPtr<T>(const std::unique_ptr<T>& other) : _raw(other.get()){}; inline BorrowedPtr<T>(const std::unique_ptr<T>& other) : _raw(other.get()){};
BorrowedPtr<T>(std::nullptr_t) = delete;
~BorrowedPtr() noexcept = default; ~BorrowedPtr() noexcept = default;
/// @brief Copy operator. /// @brief Copy operator.
@ -31,13 +33,14 @@ namespace ArbUt {
return *this; return *this;
} }
inline BorrowedPtr<T>& operator=(__attribute__((nonnull)) T* rhs) { inline BorrowedPtr<T>& operator=(T* rhs) {
if (_raw == &rhs) if (_raw == &rhs)
return *this; return *this;
AssertNotNull(rhs); AssertNotNull(rhs);
_raw = rhs; _raw = rhs;
return *this; return *this;
} }
inline BorrowedPtr<T>& operator=(std::nullptr_t) = delete;
/// @brief Operator for access into underlying pointer. /// @brief Operator for access into underlying pointer.
/// @warning Note that this asserts that the underlying pointer is not null first, to prevent segfaults. /// @warning Note that this asserts that the underlying pointer is not null first, to prevent segfaults.

View File

@ -14,6 +14,8 @@ namespace ArbUt {
T* _raw; T* _raw;
public: public:
/// @brief Initialise a BorrowedPtr with a nullptr.
inline OptionalBorrowedPtr<T>() : _raw(nullptr) {}
/// @brief Initialise a BorrowedPtr with a specific raw pointer. /// @brief Initialise a BorrowedPtr with a specific raw pointer.
inline OptionalBorrowedPtr<T>(T* ptr) : _raw(ptr){}; inline OptionalBorrowedPtr<T>(T* ptr) : _raw(ptr){};
/// @brief Initialise a BorrowedPtr from a copy. /// @brief Initialise a BorrowedPtr from a copy.

View File

@ -13,8 +13,10 @@ namespace ArbUt {
T* _raw; T* _raw;
public: public:
/// @brief Initialise a BorrowedPtr with a nullptr.
inline OptionalUniquePtr<T>() : _raw(nullptr) {}
/// @brief Initialise a OptionalUniquePtr with a specific raw pointer. /// @brief Initialise a OptionalUniquePtr with a specific raw pointer.
inline OptionalUniquePtr<T>(__attribute__((nonnull)) T* ptr) : _raw(ptr){}; inline OptionalUniquePtr<T>(T* ptr) : _raw(ptr){};
/// @brief Initialise a OptionalUniquePtr from a copy. /// @brief Initialise a OptionalUniquePtr from a copy.
inline OptionalUniquePtr<T>(const OptionalUniquePtr<T>& other) : _raw(other._raw){}; inline OptionalUniquePtr<T>(const OptionalUniquePtr<T>& other) : _raw(other._raw){};
/// @brief Initialise a OptionalUniquePtr with a std unique_ptr. /// @brief Initialise a OptionalUniquePtr with a std unique_ptr.
@ -33,7 +35,6 @@ namespace ArbUt {
inline OptionalUniquePtr<T>& operator=(__attribute__((nonnull)) T* rhs) { inline OptionalUniquePtr<T>& operator=(__attribute__((nonnull)) T* rhs) {
if (_raw == &rhs) if (_raw == &rhs)
return *this; return *this;
AssertNotNull(rhs);
_raw = rhs; _raw = rhs;
return *this; return *this;
} }

View File

@ -14,7 +14,7 @@ namespace ArbUt {
public: public:
/// @brief Initialise a ScopedPtr with a specific raw pointer. /// @brief Initialise a ScopedPtr with a specific raw pointer.
inline ScopedPtr<T>(__attribute__((nonnull)) T* ptr) : _raw(ptr){}; inline ScopedPtr<T>(T* ptr) : _raw(ptr){};
/// @brief Initialise a ScopedPtr from a copy. /// @brief Initialise a ScopedPtr from a copy.
inline ScopedPtr<T>(const ScopedPtr<T>& other) : _raw(other._raw){}; inline ScopedPtr<T>(const ScopedPtr<T>& other) : _raw(other._raw){};
/// @brief Initialise a ScopedPtr with a std unique_ptr. /// @brief Initialise a ScopedPtr with a std unique_ptr.
@ -30,7 +30,7 @@ namespace ArbUt {
return *this; return *this;
} }
inline ScopedPtr<T>& operator=(__attribute__((nonnull)) T* rhs) { inline ScopedPtr<T>& operator=(T* rhs) {
if (_raw == &rhs) if (_raw == &rhs)
return *this; return *this;
AssertNotNull(rhs); AssertNotNull(rhs);

View File

@ -5,7 +5,8 @@
namespace ArbUt { namespace ArbUt {
/// @brief A unique pointer is used to indicate a pointer that is owned by its holder, and will be deleted when its /// @brief A unique pointer is used to indicate a pointer that is owned by its holder, and will be deleted when its
/// owner is deleted. As with all Arbutils pointers, this cannot be assigned null. Use an OptionalUniquePtr for pointers that can be null. /// owner is deleted. As with all Arbutils pointers, this cannot be assigned null. Use an OptionalUniquePtr for
/// pointers that can be null.
/// @details A unique pointer is used to indicate a pointer that is owned by an object, and that needs to be deleted /// @details A unique pointer is used to indicate a pointer that is owned by an object, and that needs to be deleted
/// when its owner is deleted. /// when its owner is deleted.
template <class T> class UniquePtr { template <class T> class UniquePtr {
@ -14,31 +15,35 @@ namespace ArbUt {
public: public:
/// @brief Initialise a UniquePtr with a specific raw pointer. /// @brief Initialise a UniquePtr with a specific raw pointer.
inline UniquePtr<T>(__attribute__((nonnull)) T* ptr) : _raw(ptr) { AssertNotNull(ptr); }; inline UniquePtr<T>(T* ptr) : _raw(ptr) { AssertNotNull(ptr); };
/// @brief Initialise a UniquePtr from a copy. /// @brief Initialise a UniquePtr from a copy.
inline UniquePtr<T>(const UniquePtr<T>& other) : _raw(other._raw){}; inline UniquePtr<T>(const UniquePtr<T>& other) : _raw(other._raw){};
/// @brief Initialise a UniquePtr with a std unique_ptr. /// @brief Initialise a UniquePtr with a std unique_ptr.
inline UniquePtr<T>(const std::unique_ptr<T>& other) : _raw(other.get()){}; inline UniquePtr<T>(const std::unique_ptr<T>& other) : _raw(other.get()){};
~UniquePtr() noexcept{ UniquePtr<T>(std::nullptr_t) = delete;
delete _raw;
} ~UniquePtr() noexcept { delete _raw; }
/// @brief Copy operator. /// @brief Copy operator.
inline UniquePtr<T>& operator=(const UniquePtr<T>& rhs) { inline UniquePtr<T>& operator=(const UniquePtr<T>& rhs) {
if (this == &rhs) if (this == &rhs)
return *this; return *this;
delete _raw;
_raw = rhs._raw; _raw = rhs._raw;
return *this; return *this;
} }
inline UniquePtr<T>& operator=(__attribute__((nonnull)) T* rhs) { inline UniquePtr<T>& operator=(T* rhs) {
if (_raw == &rhs) if (_raw == &rhs) {
return *this; return *this;
}
delete _raw;
AssertNotNull(rhs); AssertNotNull(rhs);
_raw = rhs; _raw = rhs;
return *this; return *this;
} }
inline UniquePtr<T>& operator=(std::nullptr_t) = delete;
/// @brief Operator for access into underlying pointer. /// @brief Operator for access into underlying pointer.
/// @warning Note that this asserts that the underlying pointer is not null first, to prevent segfaults. /// @warning Note that this asserts that the underlying pointer is not null first, to prevent segfaults.