-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
RFC: Compatible evolution of T** params to unique_ptr<T>* #8900
base: main
Are you sure you want to change the base?
Conversation
Summary: Adds a compatibility layer in public APIs such that allocating out parameters such as `DB** dbptr` can now accept either DB** or unique_ptr<DB>. Test Plan: small test case added, CI etc.
@@ -156,7 +159,7 @@ class DB { | |||
// | |||
// Caller must delete *dbptr when it is no longer needed. | |||
static Status Open(const Options& options, const std::string& name, | |||
DB** dbptr); | |||
UniquePtrOut<DB> dbptr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm all for making the ownership semantics clear in the public API. However, I'm a bit concerned about introducing a custom smart pointer-like type, since there are a lot of ways it could be accidentally misused by application code. (I realize UniquePtrOut
is only meant to be implicitly constructed when Open
is called with a pointer to either a raw or a smart pointer but there's no way we can guarantee that.)
An alternative solution to consider: introduce new overloads that take unique_ptr
s and turn the current methods into thin wrappers around the unique_ptr
versions. (We could allocate a unique_ptr
on the stack in the wrapper, call the smart pointer version, and then call release
on the unique_ptr
and copy the raw pointer value to the out parameter.) In addition, we could mark the raw pointer versions deprecated and remove them in 7.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was hoping to avoid "overload bloat." Perhaps it is the lesser of evils.
I agree with Levi on providing an overload that follows good practice for now. Deleting old one might be hard but at least people who want to follow the best practice can start to use the new one. Another question is that, if we are changing DB::Open(), do we want to split DB options and Open options? There are options create_if_missing, create_missing_column_families, error_if_exists, etc that are weird to be thinking about as an DB option and it doesn't make sense to persistent them to OPTIONS files. There might be more of these in the future. If we are going to change to a better API, we can think about whether there are other ways we should improve this function. |
I suggested something similar (OpenOptions) in #8660. Previously I also suggested allowing "DBPlugin" options in #6661 (which might be OpenOptions or DBOptions) that could help unify the Open API for the various Stackable DBs. |
Summary: Adds a compatibility layer in public APIs such that out params
transferring ownership such as
DB** dbptr
can now accept eitherDB**
or
unique_ptr<DB>*
.Test Plan: small test case added, CI etc.