Skip to content

Commit

Permalink
Address first pass review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jhugman committed Nov 10, 2020
1 parent f844e0c commit ea97dc1
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 22 deletions.
2 changes: 1 addition & 1 deletion uniffi_bindgen/src/bindings/gecko_js/gen_gecko_js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ mod filters {
FFIType::RustBuffer => context.ffi_rustbuffer_type(),
FFIType::RustError => context.ffi_rusterror_type(),
FFIType::ForeignBytes => context.ffi_foreignbytes_type(),
FFIType::ForeignCallback => unimplemented!("Callback interfaces are not unimplemented"),
FFIType::ForeignCallback => unimplemented!("Callback interfaces are not implemented"),
})
}

Expand Down
4 changes: 2 additions & 2 deletions uniffi_bindgen/src/bindings/kotlin/templates/Helpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ inline fun <T : FFIObject, R> T.use(block: (T) -> R) =
}
}

typealias Handle = Long
class ConcurrentHandleMap<T>(
internal typealias Handle = Long
internal class ConcurrentHandleMap<T>(
private val leftMap: MutableMap<Handle, T> = mutableMapOf(),
private val rightMap: MutableMap<T, Handle> = mutableMapOf()
) {
Expand Down
2 changes: 1 addition & 1 deletion uniffi_bindgen/src/bindings/python/gen_python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ mod filters {
FFIType::RustBuffer => "RustBuffer".to_string(),
FFIType::RustError => "ctypes.POINTER(RustError)".to_string(),
FFIType::ForeignBytes => "ForeignBytes".to_string(),
FFIType::ForeignCallback => unimplemented!("Callback interfaces are not unimplemented"),
FFIType::ForeignCallback => unimplemented!("Callback interfaces are not implemented"),
})
}

Expand Down
2 changes: 1 addition & 1 deletion uniffi_bindgen/src/bindings/swift/gen_swift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ mod filters {
FFIType::RustBuffer => "RustBuffer".into(),
FFIType::RustError => "NativeRustError".into(),
FFIType::ForeignBytes => "ForeignBytes".into(),
FFIType::ForeignCallback => unimplemented!("Callback interfaces are not unimplemented"),
FFIType::ForeignCallback => unimplemented!("Callback interfaces are not implemented"),
})
}

Expand Down
9 changes: 1 addition & 8 deletions uniffi_bindgen/src/interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,7 @@ impl<'ci> ComponentInterface {
}

/// Get an Callback interface definition by name, or None if no such interface is defined.
pub fn get_foreign_callback_interface_definition(
&self,
name: &str,
) -> Option<&CallbackInterface> {
pub fn get_callback_interface_definition(&self, name: &str) -> Option<&CallbackInterface> {
// TODO: probably we could store these internally in a HashMap to make this easier?
self.callback_interfaces.iter().find(|o| o.name == name)
}
Expand Down Expand Up @@ -1108,10 +1105,6 @@ impl CallbackInterface {
type_: FFIType::ForeignCallback,
}];
self.ffi_init_callback.return_type = None;

// for meth in self.methods.iter_mut() {
// meth.derive_ffi_func(ci_prefix, &self.name)?
// }
Ok(())
}
}
Expand Down
18 changes: 9 additions & 9 deletions uniffi_bindgen/src/templates/CallbackInterfaceTemplate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,27 @@ impl {{ trait_name }} for {{ trait_impl }} {

{#- Packing args into a RustBuffer #}
{% if meth.arguments().len() == 0 -%}
let in_rbuf = uniffi::RustBuffer::new();
let args_rbuf = uniffi::RustBuffer::new();
{% else -%}
let mut in_buf = Vec::new();
let mut args_buf = Vec::new();
{% for arg in meth.arguments() -%}
{{ arg.name()|write_rs("&mut in_buf", arg.type_()) -}};
{{ arg.name()|write_rs("&mut args_buf", arg.type_()) -}};
{% endfor -%}
let in_rbuf = uniffi::RustBuffer::from_vec(in_buf);
let args_rbuf = uniffi::RustBuffer::from_vec(args_buf);
{% endif -%}

{#- Calling into foreign code. #}
let _out_rbuf = unsafe { callback(self.handle, {{ loop.index }}, in_rbuf) };
let ret_rbuf = unsafe { callback(self.handle, {{ loop.index }}, args_rbuf) };

{#- Unpacking the RustBuffer to return to Rust #}
{% match meth.return_type() -%}
{% when Some with (return_type) -%}
let vec = _out_rbuf.destroy_into_vec();
let mut out_buf = vec.as_slice();
let rval = {{ "&mut out_buf"|read_rs(return_type) }};
let vec = ret_rbuf.destroy_into_vec();
let mut ret_buf = vec.as_slice();
let rval = {{ "&mut ret_buf"|read_rs(return_type) }};
rval
{%- else -%}
uniffi::RustBuffer::destroy(_out_rbuf);
uniffi::RustBuffer::destroy(ret_rbuf);
{%- endmatch %}
}
{%- endfor %}
Expand Down

0 comments on commit ea97dc1

Please sign in to comment.