| 1 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 |
|
| 5 |
use uniffi_meta; |
| 6 |
|
| 7 |
use super::*; |
| 8 |
|
| 9 |
pub fn pass(module: &mut Module) -> Result<()> { |
| 10 |
let crate_name = module.crate_name.clone(); |
| 11 |
let module_name = module.name.clone(); |
| 12 |
let mut ffi_definitions = vec![]; |
| 13 |
module.visit_mut(|int: &mut Interface| { |
| 14 |
int.ffi_func_clone = |
| 15 |
RustFfiFunctionName(uniffi_meta::clone_fn_symbol_name(&crate_name, &int.name)); |
| 16 |
int.ffi_func_free = |
| 17 |
RustFfiFunctionName(uniffi_meta::free_fn_symbol_name(&crate_name, &int.name)); |
| 18 |
ffi_definitions.push( |
| 19 |
FfiFunction { |
| 20 |
name: int.ffi_func_clone.clone(), |
| 21 |
is_async: false, |
| 22 |
arguments: vec![FfiArgument { |
| 23 |
name: "ptr".to_string(), |
| 24 |
ty: FfiType::RustArcPtr { |
| 25 |
module_name: module_name.clone(), |
| 26 |
object_name: int.name.to_string(), |
| 27 |
}, |
| 28 |
}], |
| 29 |
return_type: FfiReturnType { |
| 30 |
ty: Some(FfiType::RustArcPtr { |
| 31 |
module_name: module_name.clone(), |
| 32 |
object_name: int.name.to_string(), |
| 33 |
}), |
| 34 |
}, |
| 35 |
has_rust_call_status_arg: true, |
| 36 |
kind: FfiFunctionKind::ObjectClone, |
| 37 |
..FfiFunction::default() |
| 38 |
} |
| 39 |
.into(), |
| 40 |
); |
| 41 |
ffi_definitions.push( |
| 42 |
FfiFunction { |
| 43 |
name: int.ffi_func_free.clone(), |
| 44 |
is_async: false, |
| 45 |
arguments: vec![FfiArgument { |
| 46 |
name: "ptr".to_string(), |
| 47 |
ty: FfiType::RustArcPtr { |
| 48 |
module_name: module_name.clone(), |
| 49 |
object_name: int.name.to_string(), |
| 50 |
}, |
| 51 |
}], |
| 52 |
return_type: FfiReturnType { ty: None }, |
| 53 |
has_rust_call_status_arg: true, |
| 54 |
kind: FfiFunctionKind::ObjectFree, |
| 55 |
..FfiFunction::default() |
| 56 |
} |
| 57 |
.into(), |
| 58 |
); |
| 59 |
}); |
| 60 |
module.ffi_definitions.extend(ffi_definitions); |
| 61 |
Ok(()) |
| 62 |
} |