Skip to content

Commit

Permalink
Replace lazy_static with once_cell
Browse files Browse the repository at this point in the history
  • Loading branch information
OpenByteDev committed Jul 5, 2022
1 parent 83289d4 commit 2a58493
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ repository = "https://github.com/OpenByteDev/dlopen2"
edition = "2021"

[dependencies]
lazy_static = ">= 1.3.0"
dlopen_derive = { path = "rust-dlopen-derive", version = "0.1" }
once_cell = "1.12"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["winnt", "minwindef", "winerror", "libloaderapi", "errhandlingapi", "dbghelp", "processthreadsapi", "basetsd"] }
Expand Down
10 changes: 3 additions & 7 deletions src/raw/unix.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
use super::super::err::Error;
use super::common::{AddressInfo, OverlappingSymbol};
use lazy_static::lazy_static;
use libc::{
c_int, c_void, dladdr, dlclose, dlerror, dlopen, dlsym, Dl_info, RTLD_LAZY, RTLD_LOCAL,
};
use once_cell::sync::Lazy;
use std::ffi::{CStr, OsStr};
use std::io::{Error as IoError, ErrorKind};
use std::os::unix::ffi::OsStrExt;
use std::ptr::{null, null_mut};
use std::sync::Mutex;

const DEFAULT_FLAGS: c_int = RTLD_LOCAL | RTLD_LAZY;

use std::sync::Mutex;

// calls to dlerror are not thread-safe, so we guard them
// with a mutex

lazy_static! {
static ref DLERROR_MUTEX: Mutex<()> = Mutex::new(());
}
static DLERROR_MUTEX: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));

pub type Handle = *mut c_void;

Expand Down
14 changes: 7 additions & 7 deletions src/raw/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::utils;

use super::super::err::Error;
use super::common::{AddressInfo, OverlappingSymbol};
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use std::ffi::{CStr, OsStr, OsString};
use std::io::{Error as IoError, ErrorKind};
use std::mem::size_of;
Expand Down Expand Up @@ -34,13 +34,13 @@ struct SetErrorModeData {
pub previous: DWORD,
}

lazy_static! {
static ref SET_ERR_MODE_DATA: Mutex<SetErrorModeData> = Mutex::new(SetErrorModeData {
static SET_ERR_MODE_DATA: Lazy<Mutex<SetErrorModeData>> = Lazy::new(|| {
Mutex::new(SetErrorModeData {
count: 0,
previous: 0
});
static ref OBTAINERS_COUNT: Mutex<usize> = Mutex::new(0);
}
previous: 0,
})
});
static OBTAINERS_COUNT: Lazy<Mutex<usize>> = Lazy::new(|| Mutex::new(0));

pub type Handle = HMODULE;

Expand Down

0 comments on commit 2a58493

Please sign in to comment.