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.
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: ffi string and buffer support #11648
feat: ffi string and buffer support #11648
Changes from 5 commits
5d71bc8
24a13d4
746f8be
6c775fb
1f92c47
b73e4b6
2a9f0da
e080158
e716539
39e5e37
4d132fa
838a94c
5f4d9d4
fc34425
b88f389
2f1ac45
9bb4271
32cc817
b2c622f
f7bdcd3
2d659e8
5587fbd
9483ca7
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This introduces a memory leak in most cases.
My suggestion: remove string support from the FFI interface.
To pass strings, the user can use TextEncoder/TextDecoder to create a Buffer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed for the JS -> rust part but how are you going to get rust strings to javascript? passing writable buffer? how do you get its size? what if it doesn't fit? and how many copying/translating is expected to be there? and what about
String
vs.&str
? and lastly, what is scope of Denodlopen
? is it eventually going to be like python ctypes? because then we should somehow support *const c_char return type because there are libs returning those.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW: here's how
![image](https://user-images.githubusercontent.com/3526922/134245048-ec4c5154-3e1e-4dbc-b75f-f485b4df114d.png)
ffi-napi
does it, the string leaks too but you can usefinally
to release itThe rust part is here:
![image](https://user-images.githubusercontent.com/3526922/134245233-d40e12f8-f129-49c1-9ac3-6c396ba18553.png)
Link to the article: http://jakegoulding.com/rust-ffi-omnibus/string_return/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe this can be used in a safe way without leaking memory.