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

Added metadata key/value iteration #28

Merged
merged 4 commits into from
Aug 6, 2020

Conversation

alilleybrinker
Copy link

@alilleybrinker alilleybrinker commented Jul 30, 2020

A couple notes:

  • This exposes a #[repr(C)] type called MetadataPair that contains the key and value strings, and has an associated metadata_pair_delete function.
  • The iterator type is opaque on the C side, and contains an owned copy of all hashes, an index for iteration, and a pointer to the Message. If the Message you're iterating over is deallocated, that pointer will be invalid.

@alilleybrinker alilleybrinker added C-enhancement Category: Enhancement New feature or request A-ffi Area: Foreign Function Interface labels Jul 30, 2020
This commit corrects the leaking of strings to C, to use into_raw() to
make sure ownership is transferred. It also adds a `Drop` implementation
for the `MetadataPair` type to ensure the inner strings are freed.
@alilleybrinker
Copy link
Author

This converts some `*mut c_char` into `*const c_char`, modifying
`MetadataPair::drop` to cast back to `*mut c_char` at deletion, with
a comment explaining why this cast is safe.
@alilleybrinker
Copy link
Author

After discussion between @cstepanian and I, we found that the *const to *mut casts are not inherently undefined behavior, as explained in this Rust Clippy issue. This commit does some of these casts to make sure we're exposing *const c_char to the C-side, discouraging any shenanigans with the pointed-to strings, which are the actual keys and values in the Message metadata HashMap.

@alilleybrinker alilleybrinker merged commit 8d0ad03 into pact_matching_ffi Aug 6, 2020
@alilleybrinker alilleybrinker deleted the additional_message_improvements branch August 6, 2020 20:37
alilleybrinker added a commit that referenced this pull request Sep 23, 2020
This commit adds the ability to get and iterate over metadata for Pact messages.
alilleybrinker added a commit that referenced this pull request Nov 4, 2020
This commit adds the ability to get and iterate over metadata for Pact messages.
alilleybrinker added a commit that referenced this pull request Dec 4, 2020
This commit adds the ability to get and iterate over metadata for Pact messages.
alilleybrinker added a commit that referenced this pull request Feb 2, 2021
This commit adds the ability to get and iterate over metadata for Pact messages.
alilleybrinker added a commit that referenced this pull request Apr 22, 2021
This commit adds the ability to get and iterate over metadata for Pact messages.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ffi Area: Foreign Function Interface C-enhancement Category: Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants