-
Notifications
You must be signed in to change notification settings - Fork 7
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
variant: extended API to support (optional) referenced strings and bytes #43
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Signed-off-by: Eduardo Silva <[email protected]>
When creating variants as strings or bytes, upon creation the bytes for those data types are allocated in a new memory buffer, it's a copy of what the caller passed as a reference. There are cases where due to performance and optimization reasons the caller might want to keep a reference to the original buffer rather than a full copy. This patch adds a new flag called 'referenced' that can be used by the new API changes coming in the new series of patches. Signed-off-by: Eduardo Silva <[email protected]>
The following patch does prototype changes for functions that create variants of string and byte types, as well it adds two new functions to set the size/lengths of the buffers. The new prototypes are as follows: - struct cfl_variant *cfl_variant_create_from_string_s(char *value, size_t value_size, int referenced) - struct cfl_variant *cfl_variant_create_from_bytes(char *value, size_t length, int referenced) the new `referenced` flag marks if the caller desires to keep a reference to the original buffer rather a full copy in a new buffer. Also this patch adds two new functions to set and retrieve the size of such buffers: - void cfl_variant_size_set(struct cfl_variant *var, size_t size); - size_t cfl_variant_size_get(struct cfl_variant *var); Signed-off-by: Eduardo Silva <[email protected]>
The following patch adjust the code to use the new Variant API prototypes and also changes some specific kvlist functions to reflect the functionality. The following functions have been modified: int cfl_kvlist_insert_bytes(struct cfl_kvlist *list, char *key, char *value, size_t value_length); size_t value_length, int referenced); int cfl_kvlist_insert_bytes_s(struct cfl_kvlist *list, char *key, size_t key_size, char *value, size_t value_length); size_t value_length, int referenced); int cfl_kvlist_insert_string_s(struct cfl_kvlist *list, char *key, size_t key_size, char *value, size_t value_size); char *value, size_t value_size, int referenced); Signed-off-by: Eduardo Silva <[email protected]>
Signed-off-by: Eduardo Silva <[email protected]>
Signed-off-by: Eduardo Silva <[email protected]>
Signed-off-by: Eduardo Silva <[email protected]>
This patch adjust the following functions to manipulate the new 'referenced' field from variants: int cfl_array_append_string_s(struct cfl_array *array, char *str, size_t str_len, int referenced) int cfl_array_append_bytes(struct cfl_array *array, char *value, size_t length, int referenced) It also adds an extra check for the array size when it's resizable. Signed-off-by: Eduardo Silva <[email protected]>
Signed-off-by: Eduardo Silva <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note: this PR bumps CFL to v0.5.0
This PR extends the variants functionality to support
referenced
values. When adding strings or bytes as variants, the current API creates a copy of those, however there are cases where the caller control its own buffer only wants to have a reference but not a new copy to avoid memory duplication; this is the case of an optimization we are doing in Fluent Bit.This is a refactor that affects variants, kvlist and arrays, the following is a summary of the new APIs that changed (these are the latest versions):
variants
This PR also adds two new functions to set and retrieve the size of such buffers:
kvlist
array
In addition to the changes in array, I have added a new unit test for the array API.
These are breaking changes that once this library is updated, we will need changes also in CMetrics and CTraces