fix: Replace static mut with Lazy for thread safety in FileBoxRegistry
- Eliminate static_mut_refs warnings by using once_cell::sync::Lazy - Make FileMode enum public to fix private_interfaces warning - Reduce warnings from 6 to 3 - Prepare for Rust 2024 edition compatibility
This commit is contained in:
@ -2,8 +2,6 @@
|
||||
mod plugin_impl {
|
||||
|
||||
use crate::bid::{BidError, BidResult, LoadedPlugin};
|
||||
use crate::bid::tlv::{TlvEncoder, TlvDecoder};
|
||||
use crate::bid::types::BidTag;
|
||||
use crate::box_trait::{NyashBox, StringBox, BoolBox, BoxCore, BoxBase};
|
||||
use std::any::Any;
|
||||
use std::fmt;
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
use crate::bid::{BidError, BidResult, NyashHostVtable, NyashPluginInfo, PluginHandle, PLUGIN_ABI_SYMBOL, PLUGIN_INIT_SYMBOL, PLUGIN_INVOKE_SYMBOL, PLUGIN_SHUTDOWN_SYMBOL};
|
||||
#[cfg(all(feature = "plugins", not(target_arch = "wasm32")))]
|
||||
use libloading::{Library, Symbol};
|
||||
use std::ffi::c_void;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
/// Loaded plugin with FFI entry points and metadata
|
||||
|
||||
@ -145,7 +145,9 @@ pub struct PluginMetadata {
|
||||
pub state: PluginState,
|
||||
|
||||
// Keep CStrings alive for C interop
|
||||
#[allow(dead_code)]
|
||||
type_name_holder: Option<CString>,
|
||||
#[allow(dead_code)]
|
||||
method_holders: Vec<(NyashMethodInfo, CString)>,
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
use super::{BidError, BidResult, NyashHostVtable, NyashPluginInfo};
|
||||
use std::os::raw::c_char;
|
||||
|
||||
/// Plugin API function signatures for C FFI
|
||||
///
|
||||
@ -164,7 +163,7 @@ impl HostVtableBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_alloc<F>(mut self, f: F) -> Self
|
||||
pub fn with_alloc<F>(self, _f: F) -> Self
|
||||
where
|
||||
F: Fn(usize) -> *mut std::os::raw::c_void + 'static,
|
||||
{
|
||||
@ -173,14 +172,14 @@ impl HostVtableBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_free<F>(mut self, f: F) -> Self
|
||||
pub fn with_free<F>(self, _f: F) -> Self
|
||||
where
|
||||
F: Fn(*mut std::os::raw::c_void) + 'static,
|
||||
{
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_log<F>(mut self, f: F) -> Self
|
||||
pub fn with_log<F>(self, _f: F) -> Self
|
||||
where
|
||||
F: Fn(&str) + 'static,
|
||||
{
|
||||
|
||||
@ -4,13 +4,11 @@
|
||||
//! Everything is Box philosophy applied to file operations!
|
||||
|
||||
use crate::bid::{BidHandle, BoxTypeId};
|
||||
use crate::bid::{NyashPluginInfo, NyashMethodInfo, NyashHostVtable};
|
||||
use once_cell::sync::Lazy;
|
||||
use std::collections::HashMap;
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::{Read, Write, Seek, SeekFrom};
|
||||
use std::os::raw::{c_char, c_void};
|
||||
use std::io::{Read, Write};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::ffi::{CStr, CString};
|
||||
|
||||
/// FileBox handle management
|
||||
pub struct FileBoxRegistry {
|
||||
@ -21,12 +19,14 @@ pub struct FileBoxRegistry {
|
||||
/// State of an open file
|
||||
struct FileBoxState {
|
||||
file: File,
|
||||
#[allow(dead_code)]
|
||||
path: String,
|
||||
#[allow(dead_code)]
|
||||
mode: FileMode,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
enum FileMode {
|
||||
pub enum FileMode {
|
||||
Read,
|
||||
Write,
|
||||
Append,
|
||||
@ -94,16 +94,12 @@ impl FileBoxRegistry {
|
||||
}
|
||||
|
||||
/// Global registry instance
|
||||
static mut FILEBOX_REGISTRY: Option<Arc<Mutex<FileBoxRegistry>>> = None;
|
||||
static FILEBOX_REGISTRY: Lazy<Arc<Mutex<FileBoxRegistry>>> =
|
||||
Lazy::new(|| Arc::new(Mutex::new(FileBoxRegistry::new())));
|
||||
|
||||
/// Get or create the global registry
|
||||
fn get_registry() -> Arc<Mutex<FileBoxRegistry>> {
|
||||
unsafe {
|
||||
if FILEBOX_REGISTRY.is_none() {
|
||||
FILEBOX_REGISTRY = Some(Arc::new(Mutex::new(FileBoxRegistry::new())));
|
||||
}
|
||||
FILEBOX_REGISTRY.as_ref().unwrap().clone()
|
||||
}
|
||||
FILEBOX_REGISTRY.clone()
|
||||
}
|
||||
|
||||
/// FileBox plugin interface for Nyash
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
use super::Usize;
|
||||
|
||||
/// BID-1 Type System (ChatGPT Enhanced Edition)
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum BidType {
|
||||
|
||||
Reference in New Issue
Block a user