Merge branch 'master' into fix-c-api-trampoline

This commit is contained in:
Ivan Enderlin
2020-10-19 09:22:13 +02:00
287 changed files with 8940 additions and 4040 deletions

View File

@@ -97,7 +97,7 @@ impl Module {
/// # }
/// ```
#[allow(unreachable_code)]
pub fn new(store: &Store, bytes: impl AsRef<[u8]>) -> Result<Module, CompileError> {
pub fn new(store: &Store, bytes: impl AsRef<[u8]>) -> Result<Self, CompileError> {
#[cfg(feature = "wat")]
let bytes = wat::parse_bytes(bytes.as_ref()).map_err(|e| {
CompileError::Wasm(WasmError::Generic(format!(
@@ -106,15 +106,15 @@ impl Module {
)))
})?;
Module::from_binary(store, bytes.as_ref())
Self::from_binary(store, bytes.as_ref())
}
/// Creates a new WebAssembly module from a file path.
pub fn from_file(store: &Store, file: impl AsRef<Path>) -> Result<Module, IoCompileError> {
pub fn from_file(store: &Store, file: impl AsRef<Path>) -> Result<Self, IoCompileError> {
let file_ref = file.as_ref();
let canonical = file_ref.canonicalize()?;
let wasm_bytes = std::fs::read(file_ref)?;
let mut module = Module::new(store, &wasm_bytes)?;
let mut module = Self::new(store, &wasm_bytes)?;
// Set the module name to the absolute path of the filename.
// This is useful for debugging the stack traces.
let filename = canonical.as_path().to_str().unwrap();
@@ -127,9 +127,9 @@ impl Module {
/// Opposed to [`Module::new`], this function is not compatible with
/// the WebAssembly text format (if the "wat" feature is enabled for
/// this crate).
pub fn from_binary(store: &Store, binary: &[u8]) -> Result<Module, CompileError> {
Module::validate(store, binary)?;
unsafe { Module::from_binary_unchecked(store, binary) }
pub fn from_binary(store: &Store, binary: &[u8]) -> Result<Self, CompileError> {
Self::validate(store, binary)?;
unsafe { Self::from_binary_unchecked(store, binary) }
}
/// Creates a new WebAssembly module skipping any kind of validation.
@@ -142,8 +142,8 @@ impl Module {
pub unsafe fn from_binary_unchecked(
store: &Store,
binary: &[u8],
) -> Result<Module, CompileError> {
let module = Module::compile(store, binary)?;
) -> Result<Self, CompileError> {
let module = Self::compile(store, binary)?;
Ok(module)
}
@@ -252,7 +252,7 @@ impl Module {
}
fn from_artifact(store: &Store, artifact: Arc<dyn Artifact>) -> Self {
Module {
Self {
store: store.clone(),
artifact,
}
@@ -410,6 +410,16 @@ impl Module {
pub fn info(&self) -> &ModuleInfo {
&self.artifact.module_ref()
}
/// Gets the [`Artifact`] used internally by the Module.
///
/// This API is hidden because it's not necessarily stable;
/// this functionality is required for some core functionality though, like
/// the object file engine.
#[doc(hidden)]
pub fn artifact(&self) -> &Arc<dyn Artifact> {
&self.artifact
}
}
impl fmt::Debug for Module {