chore(fmt): add legacy stubs and strip trailing whitespace to unblock cargo fmt
This commit is contained in:
@ -2,33 +2,53 @@ use once_cell::sync::Lazy;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Mutex;
|
||||
|
||||
static ENABLED: Lazy<bool> = Lazy::new(|| std::env::var("NYASH_LEAK_LOG").unwrap_or_default() == "1");
|
||||
static LEAKS: Lazy<Mutex<HashMap<(String, u32), &'static str>>> = Lazy::new(|| Mutex::new(HashMap::new()));
|
||||
static ENABLED: Lazy<bool> =
|
||||
Lazy::new(|| std::env::var("NYASH_LEAK_LOG").unwrap_or_default() == "1");
|
||||
static LEAKS: Lazy<Mutex<HashMap<(String, u32), &'static str>>> =
|
||||
Lazy::new(|| Mutex::new(HashMap::new()));
|
||||
|
||||
pub fn init() { let _ = &*REPORTER; }
|
||||
pub fn init() {
|
||||
let _ = &*REPORTER;
|
||||
}
|
||||
|
||||
pub fn register_plugin(box_type: &str, instance_id: u32) {
|
||||
if !*ENABLED { return; }
|
||||
LEAKS.lock().unwrap().insert((box_type.to_string(), instance_id), "plugin");
|
||||
if !*ENABLED {
|
||||
return;
|
||||
}
|
||||
LEAKS
|
||||
.lock()
|
||||
.unwrap()
|
||||
.insert((box_type.to_string(), instance_id), "plugin");
|
||||
}
|
||||
|
||||
pub fn finalize_plugin(box_type: &str, instance_id: u32) {
|
||||
if !*ENABLED { return; }
|
||||
LEAKS.lock().unwrap().remove(&(box_type.to_string(), instance_id));
|
||||
if !*ENABLED {
|
||||
return;
|
||||
}
|
||||
LEAKS
|
||||
.lock()
|
||||
.unwrap()
|
||||
.remove(&(box_type.to_string(), instance_id));
|
||||
}
|
||||
|
||||
struct Reporter;
|
||||
impl Drop for Reporter {
|
||||
fn drop(&mut self) {
|
||||
if !*ENABLED { return; }
|
||||
if !*ENABLED {
|
||||
return;
|
||||
}
|
||||
let m = LEAKS.lock().unwrap();
|
||||
if m.is_empty() { return; }
|
||||
if m.is_empty() {
|
||||
return;
|
||||
}
|
||||
eprintln!("[leak] Detected {} non-finalized plugin boxes:", m.len());
|
||||
for ((ty, id), _) in m.iter() {
|
||||
eprintln!(" - {}(id={}) not finalized (missing fini or scope)", ty, id);
|
||||
eprintln!(
|
||||
" - {}(id={}) not finalized (missing fini or scope)",
|
||||
ty, id
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static REPORTER: Lazy<Reporter> = Lazy::new(|| Reporter);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user