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

Add API to dump groups that returns a string handle. #5367

Merged
merged 5 commits into from
Nov 14, 2024

Conversation

teo-tsirpanis
Copy link
Member

SC-59017

This PR adds a new C API tiledb_group_dump_str_v2 that dumps a group into a tiledb_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 a tiledb_string_t*. The existing tiledb_group_dump_str API is deprecated.

@ihnorton ihnorton requested review from bekadavis9, kounelisagis and dudoslav and removed request for kounelisagis November 9, 2024 15:55
Copy link
Member

@ypatia ypatia left a 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.
Copy link
Member

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 ?

Copy link
Member Author

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.
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mentioned.

@teo-tsirpanis
Copy link
Member Author

Feedback addressed.

@teo-tsirpanis teo-tsirpanis requested a review from ypatia November 13, 2024 14:38
ctx.handle_error(
tiledb_group_dump_str(c_ctx, group_.get(), &str, recursive));
tiledb_group_dump_str_v2(c_ctx, group_.get(), &str, recursive));
Copy link
Collaborator

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?

Copy link
Member Author

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.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @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.
*
Copy link
Contributor

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.
*
Copy link
Contributor

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.

Copy link
Member Author

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.

/**
* 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.
*/

Copy link
Contributor

@bekadavis9 bekadavis9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@teo-tsirpanis teo-tsirpanis merged commit 871d2ed into dev Nov 14, 2024
65 checks passed
@teo-tsirpanis teo-tsirpanis deleted the teo/group-dump-str-v2 branch November 14, 2024 15:00
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.

4 participants