Skip to content

Conversation

@tbrezot
Copy link
Contributor

@tbrezot tbrezot commented Aug 10, 2023

In order to avoid allocating an upper bound on the amount of memory needed in the FFI caller, I propose the following workaround:

  1. the caller allocates the size of a pointer
  2. Rust sets the value of this pointer to a pointer to the allocated buffer
  3. Rust forgets about the buffer (avoids freeing the memory pointer to by the returned pointer)
  4. the caller unwraps the pointer and copies the bytes to a proper structure
  5. the caller free the pointer

This MR applies this method to the FFI API of Findex upsert. The caller implementation can be found in the Java repository. All tests pass on my machine.

I need particular proofreading on the free step (5) and potential incompatibilities with a Flutter/C implementation.

@tbrezot tbrezot force-pushed the feature/ffi_allocate_from_rust branch from 1ff190d to 66e1f4d Compare August 11, 2023 14:38
Base automatically changed from feature/findex_5_0_0 to develop August 16, 2023 12:39
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.

2 participants