diff options
author | DjDeveloper <43033058+DjDeveloperr@users.noreply.github.com> | 2022-01-11 11:51:16 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-11 07:21:16 +0100 |
commit | 5680d33dd91af30d085ecd991e74dd56e367e8ea (patch) | |
tree | a706ec4b60e66b9d79e74cabba3d683e738f4ecc /ext/ffi/lib.rs | |
parent | 91f6c5fc7e6f66f0e963c5cfbec281da4bcfc496 (diff) |
feat(ext/ffi): support alias names for symbol definitions (#13090)
Diffstat (limited to 'ext/ffi/lib.rs')
-rw-r--r-- | ext/ffi/lib.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/ext/ffi/lib.rs b/ext/ffi/lib.rs index c38788d30..2a6799b5f 100644 --- a/ext/ffi/lib.rs +++ b/ext/ffi/lib.rs @@ -78,13 +78,17 @@ impl Resource for DynamicLibraryResource { impl DynamicLibraryResource { fn register( &mut self, - symbol: String, + name: String, foreign_fn: ForeignFunction, ) -> Result<(), AnyError> { + let symbol = match &foreign_fn.name { + Some(symbol) => symbol, + None => &name, + }; // By default, Err returned by this function does not tell // which symbol wasn't exported. So we'll modify the error // message to include the name of symbol. - let fn_ptr = match unsafe { self.lib.symbol::<*const c_void>(&symbol) } { + let fn_ptr = match unsafe { self.lib.symbol::<*const c_void>(symbol) } { Ok(value) => Ok(value), Err(err) => Err(generic_error(format!( "Failed to register symbol {}: {}", @@ -103,7 +107,7 @@ impl DynamicLibraryResource { ); self.symbols.insert( - symbol, + name, Symbol { cif, ptr, @@ -337,6 +341,7 @@ impl From<U32x2> for u64 { #[derive(Deserialize, Debug)] #[serde(rename_all = "camelCase")] struct ForeignFunction { + name: Option<String>, parameters: Vec<NativeType>, result: NativeType, } |