-
Notifications
You must be signed in to change notification settings - Fork 185
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
Add API to dump groups that returns a string handle. #5367
Conversation
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.
Looks good but a test is missing. Let's at least update the existing tests that use the deprecated API to also use the new one.
* Dump a string representation of a group | ||
* Dump a string representation of a group. | ||
* | ||
* Deprecated, use tiledb_group_dump_str instead. |
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.
tiledb_group_dump_str_v2 ?
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.
Oops, thanks!
tiledb_ctx_t* ctx, | ||
tiledb_group_t* group, | ||
char** dump_ascii, | ||
const uint8_t recursive) TILEDB_NOEXCEPT; | ||
|
||
/** | ||
* Dump a string representation of a group. |
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.
We need to mention the caller has the responsibility to free the allocated tiledb_string_t
.
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.
Mentioned.
Feedback addressed. |
ctx.handle_error( | ||
tiledb_group_dump_str(c_ctx, group_.get(), &str, recursive)); | ||
tiledb_group_dump_str_v2(c_ctx, group_.get(), &str, recursive)); |
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 really don't see that much into this code, but don't we need to free it here since we copy it into string? or does the convert_to_string logic frees the string?
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 latter. We move the handle to a class which frees it when it gets destroyed.
TileDB/tiledb/sm/cpp_api/capi_string.h
Lines 102 to 107 in abca93c
inline std::optional<std::string> convert_to_string(tiledb_string_t** handle) { | |
if (*handle == nullptr) { | |
return std::nullopt; | |
} | |
return CAPIString(handle).str(); | |
} |
* @param group The group. | ||
* @param dump_ascii The output string handle. The caller has the responsibility | ||
* to free it. | ||
* @param recursive should we recurse into sub-groups |
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.
* @param recursive should we recurse into sub-groups | |
* @param recursive True if the dump should recurse into subgroups. |
tiledb_ctx_t* ctx, | ||
tiledb_group_t* group, | ||
char** dump_ascii, | ||
const uint8_t recursive) TILEDB_NOEXCEPT; | ||
|
||
/** | ||
* Dump a string representation of a group. | ||
* |
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.
Missing example. The example could highlight the user's responsibility to free dump_ascii
.
tiledb_ctx_t* ctx, | ||
tiledb_group_t* group, | ||
char** dump_ascii, | ||
const uint8_t recursive) TILEDB_NOEXCEPT; | ||
|
||
/** | ||
* Dump a string representation of a group. | ||
* |
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.
It's more clear to add an @note The caller must free the returned char (dump_ascii).
here, before the params, rather than an inline note that could easily be overlooked.
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.
Updated documentation to match other dump APIs.
TileDB/tiledb/api/c_api/dimension/dimension_api_external.h
Lines 298 to 317 in abca93c
/** | |
* Dumps the contents of a dimension in ASCII form to the selected string | |
* output. | |
* | |
* The output string handle must be freed by the user after use. | |
* | |
* **Example:** | |
* | |
* @code{.c} | |
* tiledb_string_t* tdb_string; | |
* tiledb_dimension_dump_str(ctx, dimension, &tdb_string); | |
* // Use the string | |
* tiledb_string_free(&tdb_string); | |
* @endcode | |
* | |
* @param ctx The TileDB context. | |
* @param dimension The dimension. | |
* @param out The output string. | |
* @return `TILEDB_OK` for success and `TILEDB_ERR` for error. | |
*/ |
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.
LGTM
SC-59017
This PR adds a new C API
tiledb_group_dump_str_v2
that dumps a group into atiledb_string_t*
. This allows the string to be safely freed under certain circumstances (such as when debug and release CRT are mixed on Windows).The existing
tiledb_group_dump_str
API was deprecated. Migrating to the new API is straightforward and requires no changes to the public surface of the higher-level APIs. The C++ API and the C groups example are migrated in this PR.TYPE: C_API
DESC: Added
tiledb_group_dump_str_v2
API that returns atiledb_string_t*
. The existingtiledb_group_dump_str
API is deprecated.