-
Notifications
You must be signed in to change notification settings - Fork 191
Profile C, C++ APIs: alloc, free, get_name, get_homedir. #5492
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
base: main
Are you sure you want to change the base?
Conversation
} | ||
}; | ||
|
||
struct ordinary_rest_profile { |
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.
The RAII here looks pretty much like what the CPP API would eventually do. Instead of a test support class perhaps this should just be a class in the CPP API?
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.
This is a test support class for the C API test. It will eventually be used such that an ordinary_rest_profile
can be initialized at the top of a test case, and the internal tiledb_rest_profile_alloc
and tiledb_rest_profile_free
logic is handled for the duration of that test case. This is on par with most other C API objects' unit tests.
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 had made the same question back when the ordinary_
classes were introduced (#5225 (comment)) and did not agree with the conclusion that the C and C++ API have to be tested separately in all cases, considering that the C++ API is itself a very thin layer over the C API and the ordinary_
classes are duplicate code.
We need a few tests to directly call the C API for testing argument validation edge cases, but I don't see any problem at all with using the C++ API1 for our functional tests.
Footnotes
-
or even another language if hypothetically all language APIs were in the same repo ↩
/** | ||
* Notes to reviewer: | ||
* This test is segfaulting. I suspect it's something to do with the | ||
* destruction of the underlying object. I had a lot of trouble getting | ||
* the behavior on L91 of tiledb/sm/cpp_api/profile_experimental.h to work, | ||
* which may be a conrtibuting factor. | ||
* | ||
* Please see my other notes to reviewer on L127 of | ||
* tiledb/sm/rest/rest_profile.h for important information regarding the | ||
* get_homedir() method. | ||
*/ |
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.
Highlighting
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.
Which part of this is giving the SEGV? The section that is not commented out, or one of the sections that is?
const char* homedir; | ||
rc = tiledb_profile_get_homedir(profile, &homedir); | ||
REQUIRE(tiledb_status(rc) == TILEDB_OK); | ||
// Validate homedir is non-empty. The path may not be resolved when using | ||
// the default homedir (per the RestProfile::homedir() invariant). | ||
// #TODO REQUIRE(homedir[0] != '\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.
Highlighting
* @invariant Use of home_directory() may cause unexpected behavior | ||
* from this method. Depending on where in the stack the method is invoked, | ||
* the path may be unresolved. | ||
* | ||
* #TODO Note to reviewer: we probably need to just change the constuctor to | ||
* take in a std::string_view to ensure the home_directory() path ref doesn't | ||
* go out of scope. We may also decide to just scrap this method entirely. | ||
* It's not in the original design but I thought it useful in prod. |
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.
Highlighting
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 don't understand what going out of scope means here. Don't we store homedir_
by value? And what do you mean by the path being unresolved?
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.
Left some comments. Please also add a tiledb_error_t*
parameter at the end of every new C API except free
.
* @invariant Use of home_directory() may cause unexpected behavior | ||
* from this method. Depending on where in the stack the method is invoked, | ||
* the path may be unresolved. | ||
* | ||
* #TODO Note to reviewer: we probably need to just change the constuctor to | ||
* take in a std::string_view to ensure the home_directory() path ref doesn't | ||
* go out of scope. We may also decide to just scrap this method entirely. | ||
* It's not in the original design but I thought it useful in prod. |
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 don't understand what going out of scope means here. Don't we store homedir_
by value? And what do you mean by the path being unresolved?
* | ||
* @return std::string The path to the local $HOME directory. | ||
*/ | ||
inline std::string homedir() { |
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.
inline std::string homedir() { | |
inline const std::string& homedir() const { |
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.
std::string_view
seems like a better choice. Agree with const
.
* Returns the name of this profile. | ||
* | ||
* @return std::string The name of this profile. | ||
*/ | ||
inline std::string name() { |
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.
inline std::string name() { | |
inline const std::string& name() const { |
@@ -139,7 +145,7 @@ RestProfile::RestProfile(const std::string& name) { | |||
* or perhaps stop using `sudo`. | |||
*/ | |||
auto homedir = home_directory(); | |||
if (homedir.empty()) { | |||
if (homedir[0] == '\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.
Why was this changed? The old version looks better.
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.
If homedir
were const char *
this would avoid a std::string
construction, but as far as I can tell homedir
is already a std::string
here? In which case I agree empty()
would be better.
Initial
Profile
C and C++ API implementation phases.C API:
Defines the internal structure of a
tiledb_profile_handle_t
object, as well as methodstiledb_profile_alloc
,tiledb_profile_free
,tiledb_profile_get_name
, andtiledb_profile_get_homedir
. The objectordinary_profile_t
has also been defined, wrapping the in-test allocator, for use in future unit tests.C++ API:
Defines the internal structure of a
TileDB::Profile
object, as well as methodsstatic free
,get_name
, andget_homedir
. Unit testtest-cppapi-profile.cc
has been defined, for future testing as the class expands.TYPE: C_API | CPP_API
DESC:
Profile
C, C++ APIs:alloc
,free
,get_name
,get_homedir
.[sc-64982]