-
Notifications
You must be signed in to change notification settings - Fork 31
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
Update wabt submodule #16
Conversation
Ah, yeah, you're right, bindings are now out of date! I think the reason why To start: I see the following way for dealing with this:
|
Alright, so I've followed your bullet point list up to 3) so far. :) Do the higher level bindings look like you'd expect? |
Also, a question about those |
Alright, I'm now at 5). Modules no longer get written to temporary files, but to get rid of tempfile handling entirely I also need to make the input files live in buffers, which currently makes me trace the code paths of |
Yes. |
Alright, I think this PR is now complete. Just to be sure about the |
- Added FFI bindings for WabtWriteScriptResult - Added High-Level wrapper for WabtWriteScriptResult - Changed write_binaries and wat2wasm to only work with in-memory buffers - Removed tempdir dependency - Made ModuleBinary::into_vec() infallible
src/lib.rs
Outdated
self.raw_script, | ||
source_cstr.as_ptr(), | ||
out_cstr.as_ptr(), | ||
std::ptr::null(), |
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.
Could you use ptr::null
?
src/lib.rs
Outdated
} | ||
} | ||
|
||
fn get_module_count(&self) -> usize { |
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.
No need for superfluous get_
src/lib.rs
Outdated
} | ||
} | ||
|
||
fn get_module_filename(&self, index: usize) -> &str { |
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.
No need for superfluous get_
src/script/mod.rs
Outdated
@@ -523,19 +473,27 @@ impl<F32: FromBits<u32>, F64: FromBits<u64>> ScriptParser<F32, F64> { | |||
None => return Ok(None), | |||
}; | |||
|
|||
let get_module = |filename, s: &Self| { | |||
let mut r = None; |
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.
Indent
That not just fine, it is required in order not to introduce a memory leak. |
Ah, now I get it, thanks. :) |
But now I realized one thing: these APIs seems to be not safe. The second call of |
ffi::wabt_write_script_result_release_module_output_buffer( | ||
self.raw_script_result, i) | ||
}; | ||
let name = self.module_filename(i); |
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.
Can we instead of CStr
use String::from_utf8_lossy
? At least it doesn't panic upon issues with utf8
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.
Hm, I found using the lossy
variants dangerous for this, as you might generate name collisions that way, and I was under the assumption that WebAssembly embraced utf8 anyway.
I could also just store the names as CString
or Vec<u8>
there?
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.
That's actually a good idea! We are only using these filenames for matching them with JSON commands, right? Even if we also need these filenames in order to display error messages, I think we can use from_utf8_lossy
here (since error reporting isn't that critcial and it doesn't panic).
src/script/mod.rs
Outdated
@@ -523,19 +473,27 @@ impl<F32: FromBits<u32>, F64: FromBits<u64>> ScriptParser<F32, F64> { | |||
None => return Ok(None), | |||
}; | |||
|
|||
let get_module = |filename, s: &Self| { | |||
let mut r = None; | |||
for &(ref name, ref module) in &s.modules { |
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 looks like a job for a HashMap
!
To clarify: I mean we could collect modules
not into a Vec
but into a HashMap
in WabtWriteScriptResultRelease
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.
Yeah, indeed.
Well done! Thank you very much! |
As a means to fix #15, I've updated the wabt submodule dependency to the current master.
WabtWriteScriptResult
WabtWriteScriptResult
write_binaries
andwat2wasm
to only work with in-memory bufferstempdir
dependencyModuleBinary::into_vec()
infallibleDepends on #17
Closes #9
Closes #15