Skip to content
This repository was archived by the owner on Mar 24, 2022. It is now read-only.

Commit 085146d

Browse files
authored
Merge pull request #376 from data-pup/misc-instance-lints
miscellaneous lint fixes in `Instance`
2 parents 0c4f0a3 + 22fd235 commit 085146d

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

lucet-runtime/lucet-runtime-internals/src/instance.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use std::ops::{Deref, DerefMut};
2626
use std::ptr::{self, NonNull};
2727
use std::sync::Arc;
2828

29-
pub const LUCET_INSTANCE_MAGIC: u64 = 746932922;
29+
pub const LUCET_INSTANCE_MAGIC: u64 = 746_932_922;
3030

3131
thread_local! {
3232
/// The host context.
@@ -79,7 +79,7 @@ pub fn new_instance_handle(
7979
embed_ctx: CtxMap,
8080
) -> Result<InstanceHandle, Error> {
8181
let inst = NonNull::new(instance)
82-
.ok_or(lucet_format_err!("instance pointer is null; this is a bug"))?;
82+
.ok_or_else(|| lucet_format_err!("instance pointer is null; this is a bug"))?;
8383

8484
lucet_ensure!(
8585
unsafe { inst.as_ref().magic } != LUCET_INSTANCE_MAGIC,
@@ -564,12 +564,9 @@ impl Instance {
564564
///
565565
/// On success, returns the number of pages that existed before the call.
566566
pub fn grow_memory(&mut self, additional_pages: u32) -> Result<u32, Error> {
567-
let additional_bytes =
568-
additional_pages
569-
.checked_mul(WASM_PAGE_SIZE)
570-
.ok_or(lucet_format_err!(
571-
"additional pages larger than wasm address space",
572-
))?;
567+
let additional_bytes = additional_pages
568+
.checked_mul(WASM_PAGE_SIZE)
569+
.ok_or_else(|| lucet_format_err!("additional pages larger than wasm address space",))?;
573570
let orig_len = self
574571
.alloc
575572
.expand_heap(additional_bytes, self.module.as_ref())?;
@@ -750,7 +747,7 @@ impl Instance {
750747

751748
let mut inst = Instance {
752749
magic: LUCET_INSTANCE_MAGIC,
753-
embed_ctx: embed_ctx,
750+
embed_ctx,
754751
module,
755752
ctx: Context::new(),
756753
state: State::Ready,
@@ -976,8 +973,9 @@ impl Instance {
976973
// handler.
977974

978975
// Run the C-style fatal handler, if it exists.
979-
self.c_fatal_handler
980-
.map(|h| unsafe { h(self as *mut Instance) });
976+
if let Some(h) = self.c_fatal_handler {
977+
unsafe { h(self as *mut Instance) }
978+
}
981979

982980
// If there is no C-style fatal handler, or if it (erroneously) returns,
983981
// call the Rust handler that we know will not return

0 commit comments

Comments
 (0)