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

feat(ext/ffi): add support for buffer arguments #12335

Merged
merged 29 commits into from
Oct 5, 2021

Conversation

bartlomieju
Copy link
Member

Forks from #11648

ext/ffi/lib.rs Outdated Show resolved Hide resolved
test_ffi/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines +33 to +34
const buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
dylib.symbols.print_buffer(buffer, buffer.length);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a bit unhandy... I wonder if we could just sniff out length automatically in case of ArrayBuffer. Though I think users would still have to declare two parameters... @piscisaureus thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we could just sniff out length automatically in case of ArrayBuffer

It's possible of course to sniff out the length automatically on the JS/Rust side (for Uint8Array too, btw).
However C has no standard data type for passing a (pointer, length) tuple.
So I'd just leave it as-is, FFI users can provide their own convenience wrappers.

Copy link
Member

@piscisaureus piscisaureus left a comment

Choose a reason for hiding this comment

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

LGTM

@bartlomieju bartlomieju merged commit 3faf75a into denoland:main Oct 5, 2021
@bartlomieju bartlomieju deleted the ffi_buffer branch October 5, 2021 22:27
bartlomieju added a commit to bartlomieju/deno that referenced this pull request Oct 6, 2021
bartlomieju added a commit to bartlomieju/deno that referenced this pull request Oct 10, 2021
This commit adds support for passing buffer arguments across 
FFI boundary.


Co-authored-by: eliassjogreen <[email protected]>
Co-authored-by: Bert Belder <[email protected]>
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.

3 participants