PMR support for cetl::unbounded_variant & cetl::pmr::function. - #124
Conversation
Node.js 16 actions are deprecated. Please update the following actions to use Node.js 20: actions/cache@v3
…ation #docs #sonar
thirtytwobits
left a comment
There was a problem hiding this comment.
We also have a cetlpf.hpp in unbounded_variant.hpp we need to remove.
Will use of "cetl/unbounded_variant.hpp" compile if IsPmr is false and no pmr types are included? I would expect this. That is, if we don't require PMR then we should require inclusion of PMR types.
| # include "cetl/cetl.hpp" | ||
| #endif | ||
|
|
||
| #include "cetl/pf17/cetlpf.hpp" |
There was a problem hiding this comment.
Don't include polyfill headers in primary hpp files. The use of any cetlpf.hpp is optional.
| // | ||
| value_size_ = size_bytes; | ||
|
|
||
| return inplace_buffer_; |
There was a problem hiding this comment.
should we not check that size_bytes is <= Footprint and return null if not?
There was a problem hiding this comment.
No, for non-pmr there is no such thing as "null" storage. Please see static assert at make_handlers - this method is one of the core entry points when it come to creation of a new unbounded variable. So it won't compile (and there is compile test to ensure this, see test_unbounded_variant_footprint_set.cpp).
There are also two other static asserts on attempt to read an arbitrary value (see get_ptr overloads, and corresponding test_unbounded_variant_footprint_get_[non_]const.cpp compile tests).
Sorry Scott, but when it comes to "include or not to include" of these two...
... I'm quite confused when which... so far I tried to do as it's in other files.
pmr types are included regardless of IsPmr. I believe it's inevitable ( |
…erface deleter. "just in case" b/c `std::unique_ptr` is not allowing invalid casting in the first place, but I believe such change makes it more explicit (and it was asked for in the first draft review).
…4_pmr_fun_ubvar_/valueless_2
The polyfill headers are completely optional in CETL so nothing in CETL should include them, they should include other things from CETL. As for byte, you'll just have to use uint8_t internally. I don't think we're providing The ideal CETL type only includes |
If PMR types are always required then we shouldn't also need the "isPMR" parameter. Instead we should just model the default storage as a memory_resource we define locally. |
…4_pmr_fun_ubvar_/valueless_fun #verification #docs #sonar
pavel-kirienko
left a comment
There was a problem hiding this comment.
As we discussed, it is desirable to eliminate the use of PMR from the deleter, or at least (this may be a better option) provide a new non-PMR deleter that does not have the up-converting constructor and which is used by default while allowing the user to switch to the other one in case of great necessity.
| /// and `reset` (or `reset(Pmr*)`) method to recover from it. | ||
| /// | ||
| template <typename Result, typename... Args, std::size_t Footprint, typename Pmr = void> | ||
| inline void swap(cetl::pmr::function<Result(Args...), Footprint, Pmr>& lhs, |
There was a problem hiding this comment.
inline is redundant for function templates, they are inline by default.
| /// and depending on which stage of swapping the failure happened | ||
| /// it could affect (invalidate) either of `lhs` or `rhs` function. | ||
| /// Use `valueless_by_exception()` method to check if a function is in such failure state, | ||
| /// and `reset` (or `reset(Pmr*)`) method to recover from it. |
There was a problem hiding this comment.
| /// and `reset` (or `reset(Pmr*)`) method to recover from it. | |
| /// and `reset` (or `reset(Pmr*)`) method (or assign a new value) to recover from it. |
| other.handler_ptr_ = get_if<handler_t>(&other.any_handler_); | ||
| } | ||
|
|
||
| /// True if the function is valueless b/c of an exception. |
There was a problem hiding this comment.
| /// True if the function is valueless b/c of an exception. | |
| /// True if the function is valueless b/c of an exception or OOM. |
OOM doesn't necessarily cause an exception
| return (base::get_value_size() > 0UL) && (nullptr != value_destroyer_); | ||
| } | ||
|
|
||
| /// True if the variant is valueless b/c of an exception. |
There was a problem hiding this comment.
| /// True if the variant is valueless b/c of an exception. | |
| /// True if the variant is valueless b/c of an exception or OOM. |
|


IsPmrsupport tocetl::unbounded_variant.cetl::pmr::function(akastd::functionbut with PMR instead of c++ heap).cetl::pmr::InterfacePtrand itsInterfaceFactrory::make_uniquestd::unique_ptrbut with custom PMR-based allocator and deleter