Skip to content

Commit

Permalink
Address second review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jhugman committed Aug 5, 2020
1 parent 2c31600 commit 8fbd373
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
19 changes: 11 additions & 8 deletions uniffi/src/bindings/kotlin/templates/ObjectTemplate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ class {{ obj.name()|class_name_kt }}(
/**
* Disconnect the object from the underlying Rust object.
*
* It can be called exactly once.
* It can be called more than once, but once called, interacting with the object
* causes an `IllegalStateException`.
*
* Clients **must** call this method once done with the object, or cause a memory leak.
*
* Once this method is called, interacting with the object causes an `IllegalStateException`.
*/
override fun destroy() {
callWithHandle {
super.destroy() // poison the handle so no-one else can use it before we tell rust.
{% call kt::to_rs_call_with_prefix("it", obj.ffi_object_free()) %}
try {
callWithHandle {
super.destroy() // poison the handle so no-one else can use it before we tell rust.
{% call kt::to_rs_call_with_prefix("it", obj.ffi_object_free()) %}
}
} catch (e: IllegalStateException) {
// The user called this more than once. Better than less than once.
}
}

Expand All @@ -30,8 +33,8 @@ class {{ obj.name()|class_name_kt }}(
{%- when Some with (return_type) -%}
fun {{ meth.name()|fn_name_kt }}({% call kt::arg_list_decl(meth.arguments()) %}): {{ return_type|type_kt }} {
val _retval = callWithHandle {
{% // Use it here, kotlin's anonymous argument for lambas/closures.
-%}
{# // Use it here, kotlin's anonymous argument for lambas/closures.
-#}
{% call kt::to_rs_call_with_prefix("it", meth.ffi_func()) %}
}
return {{ "_retval"|lift_kt(return_type) }}
Expand Down
8 changes: 2 additions & 6 deletions uniffi/src/interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,12 +416,8 @@ impl FFIFunction {
pub fn return_type(&self) -> Option<&TypeReference> {
self.return_type.as_ref()
}
pub fn method_arguments(&self) -> Vec<&Argument> {
let args = self.arguments.get(1..self.arguments.len());
match args {
None => Vec::new(),
Some(args) => args.iter().collect(),
}
pub fn method_arguments(&self) -> &[Argument] {
self.arguments.get(1..self.arguments.len()).unwrap_or_default()
}
}

Expand Down
3 changes: 1 addition & 2 deletions uniffi/src/templates/ObjectTemplate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ lazy_static::lazy_static! {
pub extern "C" fn {{ ffi_free.name() }}(
{%- call rs::arg_list_rs_decl(ffi_free.arguments()) %}) {
log::debug!("{{ ffi_free.name() }}");
let _retval = {{ handle_map }}.delete_u64(handle);
let _ = {{ handle_map }}.delete_u64(handle);
}


{%- for cons in obj.constructors() %}

#[no_mangle]
Expand Down

0 comments on commit 8fbd373

Please sign in to comment.