Skip to content

Commit

Permalink
Use lazy_static
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanson committed Sep 30, 2024
1 parent e97f8a3 commit 6f99252
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 12 deletions.
49 changes: 47 additions & 2 deletions contracts/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions contracts/ckb-std-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ edition = "2021"
ckb-std = { path = "../../", features = ["build-with-clang", "dlopen-c", "log"] }
blake2b-ref = { version = "0.3", default-features = false }
bytes = { version = "1.7", default-features = false }
lazy_static = { version = "1.5.0", default-features = false, features = ["spin_no_std"] }
log = { version = "0.4", default-features = false }
spin = { version = "0.9" }
29 changes: 19 additions & 10 deletions contracts/ckb-std-tests/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ use ckb_std::{dynamic_loading, dynamic_loading_c_impl};
use core::ffi::c_void;
#[cfg(target_arch = "riscv64")]
use core::mem::size_of_val;
#[cfg(target_arch = "riscv64")]
use lazy_static::lazy_static;
#[cfg(target_arch = "riscv64")]
use spin::Mutex;

fn new_blake2b() -> Blake2b {
const CKB_HASH_PERSONALIZATION: &[u8] = b"ckb-default-hash";
Expand Down Expand Up @@ -795,6 +799,19 @@ fn test_log() {
ckb_std::log::error!("this is error");
}

#[cfg(target_arch = "riscv64")]
lazy_static! {
// Context should not be dropped.
static ref old_context: Mutex<ContextTypeOld> = {
#[allow(deprecated)]
Mutex::new(unsafe { ContextTypeOld::new() })
};
// Context should not be dropped.
static ref new_context: Mutex<ContextType> = {
Mutex::new(unsafe { ContextType::new() })
};
}

pub fn main() -> Result<(), Error> {
test_basic();
test_load_data();
Expand All @@ -805,18 +822,10 @@ pub fn main() -> Result<(), Error> {
test_query();
test_calc_data_hash();

// Context should not be dropped.
#[cfg(target_arch = "riscv64")]
#[allow(deprecated)]
let mut old_context = unsafe { ContextTypeOld::new() };
#[cfg(target_arch = "riscv64")]
test_dynamic_loading(&mut old_context);

// Context should not be dropped.
#[cfg(target_arch = "riscv64")]
let mut context = unsafe { ContextType::new() };
test_dynamic_loading(&mut old_context.lock());
#[cfg(target_arch = "riscv64")]
test_dynamic_loading_c_impl(&mut context);
test_dynamic_loading_c_impl(&mut new_context.lock());

test_vm_version();
test_current_cycles();
Expand Down
2 changes: 2 additions & 0 deletions test/simulator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ path = "src/exec_callee.rs"
ckb-std = { path = "../..", default-features=false, features = ["allocator", "calc-hash", "ckb-types", "libc", "native-simulator"] }
blake2b-ref = { version = "0.3", default-features = false }
bytes = { version = "1.6.0", default-features = false }
lazy_static = { version = "1.5.0", default-features = false, features = ["spin_no_std"] }
log = { version = "0.4.17", default-features = false }
spin = { version = "0.9" }

[dev-dependencies]
libloading = "0.8.4"

0 comments on commit 6f99252

Please sign in to comment.