-
Notifications
You must be signed in to change notification settings - Fork 114
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
Move allocation functions into javy lib #461
Conversation
@@ -69,6 +71,7 @@ pub fn generate(js: &JS, exports: Vec<Export>) -> Result<Vec<u8>> { | |||
|
|||
// We no longer need these exports so remove them. | |||
module.exports.delete(realloc_export); | |||
module.exports.delete(free_export); |
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'm doing this for consistency with us hiding the realloc function
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.
Generally looks good to me. There are a couple of minor fixes that we could add before landing it.
@@ -40,6 +40,7 @@ pub use config::Config; | |||
pub use quickjs_wasm_rs as quickjs; | |||
pub use runtime::Runtime; | |||
|
|||
pub mod alloc; |
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.
Why don't we instead add [cfg(feature = "export_alloc_fns")]
here and remove the cfg directive from each of the function definitions?
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.
One small reason is if they don't enable the export_alloc_fns
feature, they can still add exported functions in their own crate to call canonical_abi_realloc
and canonical_abi_free
but export them with a name of their own choosing instead of with the export name we chose.
Co-authored-by: Saúl Cabrera <[email protected]>
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.
Discussed the cfg feature offline. I think that a comment will help with some of the confusion here, it feels a bit odd that Rust/Cargo requires a feature/export_name in order to keep those symbols.
This does two things:
javy
crate under the publicly exportedalloc
moduleexport_alloc_fns
which, when enabled, will export the realloc and free functions from the produced Wasm moduleThis will allow users of the Javy crate to share memory allocation and free functions instead of potentially having to write their own. I opted to put the function exports behind a cargo feature because someone using the Javy crate may want to expose their own allocation and free functions instead with their allocation logic and wouldn't want someone calling our functions or if they want to export them under a different name.