diff --git a/Cargo.toml b/Cargo.toml index 01e7577f..dc79f1e9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -239,6 +239,7 @@ members = [ ] exclude = [ "plugins/nyash-file", + "plugins/nyash-test-multibox", ] [profile.release] diff --git a/plugins/nyash-console-plugin/src/lib.rs b/plugins/nyash-console-plugin/src/lib.rs index f4ffc3af..47024eb2 100644 --- a/plugins/nyash-console-plugin/src/lib.rs +++ b/plugins/nyash-console-plugin/src/lib.rs @@ -178,16 +178,7 @@ unsafe fn write_tlv_void(out: *mut u8, out_len: *mut usize) -> i32 { } // ===== Entry points ===== -#[no_mangle] -pub extern "C" fn nyash_plugin_abi() -> u32 { - 1 -} - -#[no_mangle] -pub extern "C" fn nyash_plugin_init() -> i32 { - eprintln!("[ConsoleBox] Plugin initialized"); - NYB_SUCCESS -} +// legacy v1 abi/init removed /* legacy v1 entry removed #[no_mangle] diff --git a/plugins/nyash-counter-plugin/src/lib.rs b/plugins/nyash-counter-plugin/src/lib.rs index 1c40c83b..aaa264a0 100644 --- a/plugins/nyash-counter-plugin/src/lib.rs +++ b/plugins/nyash-counter-plugin/src/lib.rs @@ -35,15 +35,7 @@ static INSTANCES: Lazy>> = Lazy::new(|| Mutex::new(HashMap::new())); static INSTANCE_COUNTER: AtomicU32 = AtomicU32::new(1); -#[no_mangle] -pub extern "C" fn nyash_plugin_abi() -> u32 { - 1 -} - -#[no_mangle] -pub extern "C" fn nyash_plugin_init() -> i32 { - NYB_SUCCESS -} +// legacy v1 abi/init removed /* legacy v1 entry removed #[no_mangle] diff --git a/plugins/nyash-egui-plugin/src/lib.rs b/plugins/nyash-egui-plugin/src/lib.rs index 3f81d2ae..58dd3d70 100644 --- a/plugins/nyash-egui-plugin/src/lib.rs +++ b/plugins/nyash-egui-plugin/src/lib.rs @@ -111,16 +111,7 @@ pub static nyash_typebox_EguiBox: NyashTypeBoxFfi = NyashTypeBoxFfi { capabilities: 0, }; -// ===== Plugin entry points ===== -#[no_mangle] -pub extern "C" fn nyash_plugin_abi() -> u32 { - 1 -} - -#[no_mangle] -pub extern "C" fn nyash_plugin_init() -> i32 { - OK -} +// legacy v1 abi/init removed /* legacy v1 entry removed #[no_mangle] diff --git a/plugins/nyash-encoding-plugin/src/lib.rs b/plugins/nyash-encoding-plugin/src/lib.rs index fc3084b6..980b998a 100644 --- a/plugins/nyash-encoding-plugin/src/lib.rs +++ b/plugins/nyash-encoding-plugin/src/lib.rs @@ -32,15 +32,7 @@ struct EncInstance; // stateless static INST: Lazy>> = Lazy::new(|| Mutex::new(HashMap::new())); static NEXT_ID: AtomicU32 = AtomicU32::new(1); -#[no_mangle] -pub extern "C" fn nyash_plugin_abi() -> u32 { - 1 -} - -#[no_mangle] -pub extern "C" fn nyash_plugin_init() -> i32 { - OK -} +// legacy v1 abi/init removed /* legacy v1 entry removed #[no_mangle] diff --git a/plugins/nyash-filebox-plugin/src/lib.rs b/plugins/nyash-filebox-plugin/src/lib.rs index 20197360..a59164da 100644 --- a/plugins/nyash-filebox-plugin/src/lib.rs +++ b/plugins/nyash-filebox-plugin/src/lib.rs @@ -70,19 +70,7 @@ static INSTANCE_COUNTER: AtomicU32 = AtomicU32::new(1); // ============ Plugin Entry Points ============ -/// ABI version -#[no_mangle] -pub extern "C" fn nyash_plugin_abi() -> u32 { - 1 // BID-1 support -} - -/// Plugin initialization (optional - global setup) -#[no_mangle] -pub extern "C" fn nyash_plugin_init() -> i32 { - // グローバル初期化(Lazy staticのため特に必要なし) - eprintln!("[FileBox] Plugin initialized"); - NYB_SUCCESS -} +// legacy v1 abi/init removed /// Method invocation - 仮実装 /* legacy v1 entry removed diff --git a/plugins/nyash-integer-plugin/src/lib.rs b/plugins/nyash-integer-plugin/src/lib.rs index cafde800..e480c7b7 100644 --- a/plugins/nyash-integer-plugin/src/lib.rs +++ b/plugins/nyash-integer-plugin/src/lib.rs @@ -35,15 +35,7 @@ struct IntInstance { static INST: Lazy>> = Lazy::new(|| Mutex::new(HashMap::new())); static NEXT_ID: AtomicU32 = AtomicU32::new(1); -#[no_mangle] -pub extern "C" fn nyash_plugin_abi() -> u32 { - 1 -} - -#[no_mangle] -pub extern "C" fn nyash_plugin_init() -> i32 { - OK -} +// legacy v1 abi/init removed /* legacy v1 entry removed #[no_mangle] diff --git a/plugins/nyash-map-plugin/src/lib.rs b/plugins/nyash-map-plugin/src/lib.rs index c34f13dd..f38ee256 100644 --- a/plugins/nyash-map-plugin/src/lib.rs +++ b/plugins/nyash-map-plugin/src/lib.rs @@ -48,15 +48,7 @@ struct MapInstance { static INSTANCES: Lazy>> = Lazy::new(|| Mutex::new(HashMap::new())); static INSTANCE_COUNTER: AtomicU32 = AtomicU32::new(1); -#[no_mangle] -pub extern "C" fn nyash_plugin_abi() -> u32 { - 1 -} - -#[no_mangle] -pub extern "C" fn nyash_plugin_init() -> i32 { - NYB_SUCCESS -} +// legacy v1 abi/init removed /* legacy v1 entry removed #[no_mangle] diff --git a/plugins/nyash-math-plugin/src/lib.rs b/plugins/nyash-math-plugin/src/lib.rs index a533dbdd..50da03af 100644 --- a/plugins/nyash-math-plugin/src/lib.rs +++ b/plugins/nyash-math-plugin/src/lib.rs @@ -81,15 +81,7 @@ mod tlv { } } -#[no_mangle] -pub extern "C" fn nyash_plugin_abi() -> u32 { - 1 -} - -#[no_mangle] -pub extern "C" fn nyash_plugin_init() -> i32 { - OK -} +// legacy v1 abi/init removed /* legacy v1 entry removed #[no_mangle] diff --git a/plugins/nyash-net-plugin/src/lib.rs b/plugins/nyash-net-plugin/src/lib.rs index d9b78f20..077b1dfd 100644 --- a/plugins/nyash-net-plugin/src/lib.rs +++ b/plugins/nyash-net-plugin/src/lib.rs @@ -162,24 +162,7 @@ struct SockConnState { struct SockClientState; -#[no_mangle] -pub extern "C" fn nyash_plugin_abi() -> u32 { - 1 -} - -#[no_mangle] -pub extern "C" fn nyash_plugin_init() -> i32 { - // Force initialize logging - let _ = *LOG_ON; - let _ = &*LOG_PATH; - netlog!( - "Net plugin initialized, LOG_ON={}, LOG_PATH={}", - *LOG_ON, - *LOG_PATH - ); - eprintln!("Net plugin: LOG_ON={}, LOG_PATH={}", *LOG_ON, *LOG_PATH); - OK -} +// legacy v1 abi/init removed /* legacy v1 entry removed #[no_mangle] diff --git a/plugins/nyash-path-plugin/src/lib.rs b/plugins/nyash-path-plugin/src/lib.rs index 078c292a..f0d0b619 100644 --- a/plugins/nyash-path-plugin/src/lib.rs +++ b/plugins/nyash-path-plugin/src/lib.rs @@ -34,10 +34,7 @@ static NEXT_ID: AtomicU32 = AtomicU32::new(1); // legacy v1 entry points removed /* -#[no_mangle] -pub extern "C" fn nyash_plugin_abi() -> u32 { 1 } -#[no_mangle] -pub extern "C" fn nyash_plugin_init() -> i32 { OK } +// legacy v1 abi/init removed #[no_mangle] pub extern "C" fn nyash_plugin_invoke( type_id: u32, diff --git a/plugins/nyash-python-compiler-plugin/src/lib.rs b/plugins/nyash-python-compiler-plugin/src/lib.rs index 29667eae..6bf1afd2 100644 --- a/plugins/nyash-python-compiler-plugin/src/lib.rs +++ b/plugins/nyash-python-compiler-plugin/src/lib.rs @@ -13,15 +13,7 @@ const METHOD_FINI: u32 = u32::MAX; static NEXT_ID: Lazy> = Lazy::new(|| Mutex::new(1)); -#[no_mangle] -pub extern "C" fn nyash_plugin_abi() -> u32 { - 1 -} - -#[no_mangle] -pub extern "C" fn nyash_plugin_init() -> i32 { - NYB_SUCCESS -} +// legacy v1 abi/init removed /* legacy v1 entry removed #[no_mangle] diff --git a/plugins/nyash-python-plugin/src/lib.rs b/plugins/nyash-python-plugin/src/lib.rs index 7858c3e6..2b13058c 100644 --- a/plugins/nyash-python-plugin/src/lib.rs +++ b/plugins/nyash-python-plugin/src/lib.rs @@ -343,15 +343,7 @@ fn ensure_cpython() -> Result<(), ()> { Ok(()) } -#[no_mangle] -pub extern "C" fn nyash_plugin_abi() -> u32 { - 1 -} - -#[no_mangle] -pub extern "C" fn nyash_plugin_init() -> i32 { - NYB_SUCCESS -} +// legacy v1 abi/init removed /* legacy v1 entry removed #[no_mangle] diff --git a/plugins/nyash-regex-plugin/src/lib.rs b/plugins/nyash-regex-plugin/src/lib.rs index 907e8bc9..62e7c719 100644 --- a/plugins/nyash-regex-plugin/src/lib.rs +++ b/plugins/nyash-regex-plugin/src/lib.rs @@ -36,15 +36,7 @@ struct RegexInstance { static INST: Lazy>> = Lazy::new(|| Mutex::new(HashMap::new())); static NEXT_ID: AtomicU32 = AtomicU32::new(1); -#[no_mangle] -pub extern "C" fn nyash_plugin_abi() -> u32 { - 1 -} - -#[no_mangle] -pub extern "C" fn nyash_plugin_init() -> i32 { - OK -} +// legacy v1 abi/init removed /* legacy v1 entry removed #[no_mangle] diff --git a/plugins/nyash-string-plugin/src/lib.rs b/plugins/nyash-string-plugin/src/lib.rs index 166d2c44..3311959c 100644 --- a/plugins/nyash-string-plugin/src/lib.rs +++ b/plugins/nyash-string-plugin/src/lib.rs @@ -36,15 +36,7 @@ struct StrInstance { static INST: Lazy>> = Lazy::new(|| Mutex::new(HashMap::new())); static NEXT_ID: AtomicU32 = AtomicU32::new(1); -#[no_mangle] -pub extern "C" fn nyash_plugin_abi() -> u32 { - 1 -} - -#[no_mangle] -pub extern "C" fn nyash_plugin_init() -> i32 { - OK -} +// legacy v1 abi/init removed /* legacy v1 entry removed #[no_mangle] diff --git a/plugins/nyash-test-multibox/Cargo.toml b/plugins/nyash-test-multibox/Cargo.toml deleted file mode 100644 index 36f0e7f8..00000000 --- a/plugins/nyash-test-multibox/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "nyash-test-multibox" -version = "0.1.0" -edition = "2021" - -[lib] -crate-type = ["cdylib", "staticlib"] - -[dependencies] diff --git a/plugins/nyash-test-multibox/libnyash_test_multibox.a b/plugins/nyash-test-multibox/libnyash_test_multibox.a deleted file mode 100644 index ac2c398c..00000000 Binary files a/plugins/nyash-test-multibox/libnyash_test_multibox.a and /dev/null differ diff --git a/plugins/nyash-test-multibox/src/lib.rs b/plugins/nyash-test-multibox/src/lib.rs deleted file mode 100644 index 77db05b9..00000000 --- a/plugins/nyash-test-multibox/src/lib.rs +++ /dev/null @@ -1,362 +0,0 @@ -//! Test Multi-Box Plugin for Nyash -//! -//! Provides TestBoxA and TestBoxB to demonstrate multi-box plugin support - -use std::collections::HashMap; -use std::os::raw::c_char; -use std::ptr; -use std::sync::Mutex; - -// ============ FFI Types ============ - -#[repr(C)] -pub struct NyashHostVtable { - pub alloc: unsafe extern "C" fn(size: usize) -> *mut u8, - pub free: unsafe extern "C" fn(ptr: *mut u8), - pub wake: unsafe extern "C" fn(handle: u64), - pub log: unsafe extern "C" fn(level: i32, msg: *const c_char), -} - -#[repr(C)] -pub struct NyashMethodInfo { - pub method_id: u32, - pub name: *const c_char, - pub signature: u32, -} - -unsafe impl Sync for NyashMethodInfo {} - -#[repr(C)] -pub struct NyashPluginInfo { - pub type_id: u32, - pub type_name: *const c_char, - pub method_count: usize, - pub methods: *const NyashMethodInfo, -} - -unsafe impl Sync for NyashPluginInfo {} - -// Error codes -const NYB_SUCCESS: i32 = 0; -const NYB_E_INVALID_ARGS: i32 = -4; -const NYB_E_INVALID_HANDLE: i32 = -8; - -// Method IDs -const METHOD_BIRTH: u32 = 0; -const METHOD_HELLO: u32 = 1; -const METHOD_GREET: u32 = 2; -const METHOD_FINI: u32 = u32::MAX; - -// Type IDs -const TYPE_ID_TESTBOX_A: u32 = 200; -const TYPE_ID_TESTBOX_B: u32 = 201; - -// Global state -static mut HOST_VTABLE: Option<&'static NyashHostVtable> = None; -static mut INSTANCES: Option>> = None; -static mut INSTANCE_COUNTER: u32 = 1; - -enum TestInstance { - BoxA { message: String }, - BoxB { counter: i32 }, -} - -// ============ Plugin Info for Each Box Type ============ - -static TESTBOX_A_NAME: &[u8] = b"TestBoxA\0"; -static TESTBOX_B_NAME: &[u8] = b"TestBoxB\0"; - -static METHOD_HELLO_NAME: &[u8] = b"hello\0"; -static METHOD_GREET_NAME: &[u8] = b"greet\0"; -static METHOD_BIRTH_NAME: &[u8] = b"birth\0"; -static METHOD_FINI_NAME: &[u8] = b"fini\0"; - -static TESTBOX_A_METHODS: [NyashMethodInfo; 3] = [ - NyashMethodInfo { - method_id: METHOD_BIRTH, - name: METHOD_BIRTH_NAME.as_ptr() as *const c_char, - signature: 0, - }, - NyashMethodInfo { - method_id: METHOD_HELLO, - name: METHOD_HELLO_NAME.as_ptr() as *const c_char, - signature: 0, - }, - NyashMethodInfo { - method_id: METHOD_FINI, - name: METHOD_FINI_NAME.as_ptr() as *const c_char, - signature: 0, - }, -]; - -static TESTBOX_B_METHODS: [NyashMethodInfo; 3] = [ - NyashMethodInfo { - method_id: METHOD_BIRTH, - name: METHOD_BIRTH_NAME.as_ptr() as *const c_char, - signature: 0, - }, - NyashMethodInfo { - method_id: METHOD_GREET, - name: METHOD_GREET_NAME.as_ptr() as *const c_char, - signature: 0, - }, - NyashMethodInfo { - method_id: METHOD_FINI, - name: METHOD_FINI_NAME.as_ptr() as *const c_char, - signature: 0, - }, -]; - -static TESTBOX_A_INFO: NyashPluginInfo = NyashPluginInfo { - type_id: TYPE_ID_TESTBOX_A, - type_name: TESTBOX_A_NAME.as_ptr() as *const c_char, - method_count: 3, - methods: TESTBOX_A_METHODS.as_ptr(), -}; - -static TESTBOX_B_INFO: NyashPluginInfo = NyashPluginInfo { - type_id: TYPE_ID_TESTBOX_B, - type_name: TESTBOX_B_NAME.as_ptr() as *const c_char, - method_count: 3, - methods: TESTBOX_B_METHODS.as_ptr(), -}; - -// ============ Plugin Entry Points ============ - -#[no_mangle] -pub extern "C" fn nyash_plugin_abi() -> u32 { - 1 // BID-1 ABI version -} - -#[no_mangle] -pub extern "C" fn nyash_plugin_init( - host: *const NyashHostVtable, - _info: *mut std::ffi::c_void, // For v2, we use get_box_info instead -) -> i32 { - if host.is_null() { - return NYB_E_INVALID_ARGS; - } - - unsafe { - HOST_VTABLE = Some(&*host); - INSTANCES = Some(Mutex::new(HashMap::new())); - - // Log initialization - log_info("Multi-box test plugin initialized"); - } - - NYB_SUCCESS -} - -// ============ Multi-Box v2 Functions ============ - -#[no_mangle] -pub extern "C" fn nyash_plugin_get_box_count() -> u32 { - 2 // TestBoxA and TestBoxB -} - -#[no_mangle] -pub extern "C" fn nyash_plugin_get_box_info(index: u32) -> *const NyashPluginInfo { - match index { - 0 => &TESTBOX_A_INFO as *const NyashPluginInfo, - 1 => &TESTBOX_B_INFO as *const NyashPluginInfo, - _ => ptr::null(), - } -} - -#[no_mangle] -pub extern "C" fn nyash_plugin_get_type_id(box_name: *const c_char) -> u32 { - if box_name.is_null() { - return 0; - } - - unsafe { - let name = std::ffi::CStr::from_ptr(box_name).to_string_lossy(); - match name.as_ref() { - "TestBoxA" => TYPE_ID_TESTBOX_A, - "TestBoxB" => TYPE_ID_TESTBOX_B, - _ => 0, - } - } -} - -// ============ Method Invocation ============ - -#[no_mangle] -pub extern "C" fn nyash_plugin_invoke( - type_id: u32, - method_id: u32, - instance_id: u32, - _args: *const u8, - _args_len: usize, - result: *mut u8, - result_len: *mut usize, -) -> i32 { - unsafe { - match (type_id, method_id) { - // TestBoxA methods - (TYPE_ID_TESTBOX_A, METHOD_BIRTH) => create_instance_a(result, result_len), - (TYPE_ID_TESTBOX_A, METHOD_HELLO) => hello_method(instance_id, result, result_len), - (TYPE_ID_TESTBOX_A, METHOD_FINI) => destroy_instance(instance_id), - - // TestBoxB methods - (TYPE_ID_TESTBOX_B, METHOD_BIRTH) => create_instance_b(result, result_len), - (TYPE_ID_TESTBOX_B, METHOD_GREET) => greet_method(instance_id, result, result_len), - (TYPE_ID_TESTBOX_B, METHOD_FINI) => destroy_instance(instance_id), - - _ => NYB_E_INVALID_ARGS, - } - } -} - -// ============ Method Implementations ============ - -unsafe fn create_instance_a(result: *mut u8, result_len: *mut usize) -> i32 { - if let Some(ref mutex) = INSTANCES { - if let Ok(mut map) = mutex.lock() { - let id = INSTANCE_COUNTER; - INSTANCE_COUNTER += 1; - - map.insert( - id, - TestInstance::BoxA { - message: "Hello from TestBoxA!".to_string(), - }, - ); - - // Return instance ID - if *result_len >= 4 { - let bytes = id.to_le_bytes(); - ptr::copy_nonoverlapping(bytes.as_ptr(), result, 4); - *result_len = 4; - - log_info(&format!("Created TestBoxA instance {}", id)); - return NYB_SUCCESS; - } - } - } - NYB_E_INVALID_ARGS -} - -unsafe fn create_instance_b(result: *mut u8, result_len: *mut usize) -> i32 { - if let Some(ref mutex) = INSTANCES { - if let Ok(mut map) = mutex.lock() { - let id = INSTANCE_COUNTER; - INSTANCE_COUNTER += 1; - - map.insert(id, TestInstance::BoxB { counter: 0 }); - - // Return instance ID - if *result_len >= 4 { - let bytes = id.to_le_bytes(); - ptr::copy_nonoverlapping(bytes.as_ptr(), result, 4); - *result_len = 4; - - log_info(&format!("Created TestBoxB instance {}", id)); - return NYB_SUCCESS; - } - } - } - NYB_E_INVALID_ARGS -} - -unsafe fn hello_method(instance_id: u32, result: *mut u8, result_len: *mut usize) -> i32 { - if let Some(ref mutex) = INSTANCES { - if let Ok(map) = mutex.lock() { - if let Some(TestInstance::BoxA { message }) = map.get(&instance_id) { - // Return message as TLV string - write_tlv_string(message, result, result_len) - } else { - NYB_E_INVALID_HANDLE - } - } else { - NYB_E_INVALID_ARGS - } - } else { - NYB_E_INVALID_ARGS - } -} - -unsafe fn greet_method(instance_id: u32, result: *mut u8, result_len: *mut usize) -> i32 { - if let Some(ref mutex) = INSTANCES { - if let Ok(mut map) = mutex.lock() { - if let Some(TestInstance::BoxB { counter }) = map.get_mut(&instance_id) { - *counter += 1; - let message = format!("Greeting #{} from TestBoxB!", counter); - - // Return message as TLV string - write_tlv_string(&message, result, result_len) - } else { - NYB_E_INVALID_HANDLE - } - } else { - NYB_E_INVALID_ARGS - } - } else { - NYB_E_INVALID_ARGS - } -} - -unsafe fn destroy_instance(instance_id: u32) -> i32 { - if let Some(ref mutex) = INSTANCES { - if let Ok(mut map) = mutex.lock() { - if map.remove(&instance_id).is_some() { - log_info(&format!("Destroyed instance {}", instance_id)); - NYB_SUCCESS - } else { - NYB_E_INVALID_HANDLE - } - } else { - NYB_E_INVALID_ARGS - } - } else { - NYB_E_INVALID_ARGS - } -} - -// ============ Helper Functions ============ - -unsafe fn write_tlv_string(s: &str, result: *mut u8, result_len: *mut usize) -> i32 { - let bytes = s.as_bytes(); - let needed = 8 + bytes.len(); // header(4) + entry(4) + string - - if *result_len < needed { - return NYB_E_INVALID_ARGS; - } - - // TLV header - *result = 1; // version low - *result.offset(1) = 0; // version high - *result.offset(2) = 1; // argc low - *result.offset(3) = 0; // argc high - - // String entry - *result.offset(4) = 6; // Tag::String - *result.offset(5) = 0; // padding - let len_bytes = (bytes.len() as u16).to_le_bytes(); - *result.offset(6) = len_bytes[0]; - *result.offset(7) = len_bytes[1]; - - // String data - ptr::copy_nonoverlapping(bytes.as_ptr(), result.offset(8), bytes.len()); - - *result_len = needed; - NYB_SUCCESS -} - -unsafe fn log_info(message: &str) { - if let Some(vtable) = HOST_VTABLE { - if let Ok(c_str) = std::ffi::CString::new(message) { - (vtable.log)(1, c_str.as_ptr()); - } - } -} - -#[no_mangle] -pub extern "C" fn nyash_plugin_shutdown() { - unsafe { - log_info("Multi-box test plugin shutting down"); - INSTANCES = None; - HOST_VTABLE = None; - } -} diff --git a/plugins/nyash-toml-plugin/src/lib.rs b/plugins/nyash-toml-plugin/src/lib.rs index b2910341..7f588b0d 100644 --- a/plugins/nyash-toml-plugin/src/lib.rs +++ b/plugins/nyash-toml-plugin/src/lib.rs @@ -30,15 +30,7 @@ struct TomlInstance { static INST: Lazy>> = Lazy::new(|| Mutex::new(HashMap::new())); static NEXT_ID: AtomicU32 = AtomicU32::new(1); -#[no_mangle] -pub extern "C" fn nyash_plugin_abi() -> u32 { - 1 -} - -#[no_mangle] -pub extern "C" fn nyash_plugin_init() -> i32 { - OK -} +// legacy v1 abi/init removed /* legacy v1 entry removed #[no_mangle]