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

Replaced some raw pointers with smart pointers #122

Closed
wants to merge 1 commit into from

Conversation

HJLebbink
Copy link
Member

No description provided.

@kobalicek
Copy link
Contributor

I'm not sure about this.

I think that if it's guaranteed that some object won't outlive something else, we don't need std::unique_ptr nor std::shared_ptr. I mean there is nothing in C++ that would be reference counted and non-atomic, so the question is, do we really want to use atomically incremented shared pointers in this project, even when the API around it is not thread safe?

What I mean is that both unique_ptr and shared_ptr are owning. So for example:

minio::creds::StaticProvider provider;
minio::s3::Client client(base_url, &provider);

can be changed to:

minio::creds::StaticProvider provider;
minio::s3::Client client(base_url, provider); // reference instead of pointer.

It would be the same and you won't need a dynamic memory allocation for the provider.

So my question is, do we mind more allocations just to remove * from some functions / members or is it okay to just use a reference?

Because for example in the provider example - do we want to share providers across clients? If so, then unique_ptr is not the right pointer and shared_ptr would be better I think.

@HJLebbink HJLebbink force-pushed the feature/replace-raw-ptr branch from 6776253 to 914702e Compare March 20, 2024 07:32
@HJLebbink
Copy link
Member Author

Eradicating pointers to class Client and StaticProvider is a good thing, because these classes is passed around in function calls, the StaticProvider is currently not copyable AFAICT. Currently, the solution is to use raw pointer; I don't think it currently triggers bugs, but it is (in the current form) hard to make a class with a client, and have the constructor initialize this client, simply because StaticProvider has no default constructor (or is not copyable, etc). Some simple managed pointers fixes this. @piotr-topnotch what would be the least intrusive update to make Client 'usable'?

@balamurugana
Copy link
Member

As I am not able to understand what bugs we are trying to address here. I am sharing my thoughts WRT current code.

In higher level, Client and BaseClient are not thread-safe, particularly region_map_ and Fetch() method of Provider. WRT StaticProvider is kind of thread-safe i.e. it returns copy of Credentials at the time of Fetch(). Note that null credential provider is a valid/supported value for anonymous access.

Lifetime of provider has to be maintained along with Client or BaseClient. It is user's responsibility. I do not recommend sharing of Provider with different Client or BaseClient. Each client needs to be created with individual credential providers. Otherwise we need to make Provider thread-safe.

@HJLebbink HJLebbink closed this Apr 5, 2024
@HJLebbink
Copy link
Member Author

will revisit this later

@HJLebbink HJLebbink deleted the feature/replace-raw-ptr branch December 11, 2024 19:56
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.

3 participants