DRUMNICORN / Visio

Visio is an AI-powered IDE concept that turns software development into a visual, code-free experience, making programming accessible to everyone.
https://github.com/DRUMNICORN/visio
81 stars 4 forks source link

Implementation of libloading and abi_stable generates Error: Segmentation fault (core dumped) #13

Closed DRUMNICORN closed 1 year ago

DRUMNICORN commented 1 year ago

Error registering plugin

created cherob/issue13

DRUMNICORN commented 1 year ago

nodium: reload [2023-05-18T00:16:26Z DEBUG nodium_console::view] Handle reload [2023-05-18T00:16:26Z DEBUG nodium_console::view] Try to reload plugins [2023-05-18T00:16:26Z DEBUG nodium_plugins::plugins] Reloading plugins [2023-05-18T00:16:26Z DEBUG nodium_plugins::plugins] Plugin path: "plugins/nodium_browser" [2023-05-18T00:16:26Z DEBUG nodium_plugins::plugins] Plugin name: nodium_browser Segmentation fault (core dumped)

DRUMNICORN commented 1 year ago
// plugins/nodium_hello_world/src/lib.rs
use abi_stable::{StableAbi, std_types::RString};
use nodium_pdk::NodiumPlugin;

#[derive(StableAbi)]
#[repr(C)]
pub struct MyPlugin {
    name: RString,
    version: RString,
}

impl NodiumPlugin for MyPlugin {
    fn name(&self) -> RString {
        self.name.clone()
    }

    fn version(&self) -> RString {
        self.version.clone()
    }
}
// libs/pdk/src/plugin.rs
use abi_stable::{StableAbi, std_types::RString};
pub trait NodiumPlugin: StableAbi {
  fn name(&self) -> RString;
  fn version(&self) -> RString;
}
use abi_stable::StableAbi;
use std::path::Path;
use nodium_pdk::NodiumPlugin;

pub unsafe fn extract_plugin(lib_path: &Path) -> Result<Box<dyn NodiumPlugin>, String> {
    let lib = libloading::Library::new(lib_path).map_err(|e| e.to_string())?;
    let plugin: libloading::Symbol<unsafe extern "C" fn() -> *mut c_void> = unsafe {
        lib.get(b"nodium_plugin")
            .map_err(|e| e.to_string())?
    };
    let plugin_ptr = plugin();
    let plugin: Box<dyn NodiumPlugin> = unsafe { Box::from_raw(plugin_ptr as *mut dyn NodiumPlugin) };
    Ok(plugin)
}
DRUMNICORN commented 1 year ago

https://www.phind.com/search?cache=30337729-4521-4750-928e-d94c1c2f3f2d i am now trying "dlopen" crate

DRUMNICORN commented 1 year ago
[2023-05-31T01:58:06Z INFO  nodium_console] Welcome to Nodium!

nodium: list
[2023-05-31T01:58:07Z DEBUG nodium_console] Handle plugin list
[2023-05-31T01:58:07Z DEBUG nodium_console] Try to get plugins, lock app
[2023-05-31T01:58:07Z DEBUG nodium_console] App locked, get plugins
[2023-05-31T01:58:07Z DEBUG nodium_plugins::registry] Plugins amount: 0
[2023-05-31T01:58:07Z DEBUG nodium_console] Plugins: []
nodium: reload
[2023-05-31T01:58:09Z DEBUG nodium_console] Handle reload
[2023-05-31T01:58:09Z DEBUG nodium_console] Try to get plugins, lock app
[2023-05-31T01:58:09Z DEBUG nodium_console] App locked, reload plugins
[2023-05-31T01:58:09Z DEBUG nodium_plugins::plugins] Reloading plugins
[2023-05-31T01:58:09Z DEBUG nodium_plugins::plugins] Plugin path: "plugins/nodium_browser"
[2023-05-31T01:58:09Z DEBUG nodium_plugins::plugins] Plugin name and version: nodium_browser nodium_browser
[2023-05-31T01:58:09Z DEBUG nodium_plugins::plugins] Registering plugin: Crates Browser Plugin
[2023-05-31T01:58:09Z INFO  nodium_plugins::plugins] Plugin registered successfully
nodium: list
[2023-05-31T01:58:10Z DEBUG nodium_console] Handle plugin list
[2023-05-31T01:58:10Z DEBUG nodium_console] Try to get plugins, lock app
[2023-05-31T01:58:10Z DEBUG nodium_console] App locked, get plugins
[2023-05-31T01:58:10Z DEBUG nodium_plugins::registry] Plugins amount: 1
[2023-05-31T01:58:10Z DEBUG nodium_console] Plugins: ["Crates Browser Plugin"]
- Crates Browser Plugin

works with example plugin