Skip to content

Commit

Permalink
Move callback interface name to a filter function
Browse files Browse the repository at this point in the history
Signed-off-by: Martynas Gurskas <martynas.gurskas@nordsec.com>
  • Loading branch information
Lipt0nas committed Feb 18, 2025
1 parent 2d4b763 commit 364771d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
9 changes: 7 additions & 2 deletions bindgen/src/bindings/cpp/gen_cpp/callback_interface.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use uniffi_bindgen::{interface::Literal, ComponentInterface};

use crate::bindings::cpp::{gen_cpp::filters::CppCodeOracle, CodeType};
use crate::bindings::cpp::{
gen_cpp::filters::callback_interface_name, gen_cpp::filters::CppCodeOracle, CodeType,
};

#[derive(Debug)]
pub(crate) struct CallbackInterfaceCodeType {
Expand All @@ -27,6 +29,9 @@ impl CodeType for CallbackInterfaceCodeType {
}

fn initialization_fn(&self) -> Option<String> {
Some(format!("uniffi::UniffiCallbackInterface{}::init", self.id))
Some(format!(
"uniffi::{}::init",
callback_interface_name(&self.id).unwrap()
))
}
}
4 changes: 4 additions & 0 deletions bindgen/src/bindings/cpp/gen_cpp/filters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ pub(crate) fn ffi_struct_name(nm: &str) -> Result<String> {
Ok(format!("Uniffi{}", nm))
}

pub(crate) fn callback_interface_name(nm: &str) -> Result<String> {
Ok(format!("UniffiCallbackInterface{}", nm))
}

pub(crate) fn canonical_name(as_ct: &impl AsCodeType) -> Result<String> {
Ok(as_ct.as_codetype().canonical_name())
}
Expand Down
8 changes: 5 additions & 3 deletions bindgen/src/bindings/cpp/gen_cpp/object.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use uniffi_bindgen::{backend::Literal, interface::ObjectImpl, ComponentInterface};

use crate::bindings::cpp::{gen_cpp::filters::CppCodeOracle, CodeType};
use crate::bindings::cpp::{
gen_cpp::filters::callback_interface_name, gen_cpp::filters::CppCodeOracle, CodeType,
};

#[derive(Debug)]
pub(crate) struct ObjectCodeType {
Expand Down Expand Up @@ -30,8 +32,8 @@ impl CodeType for ObjectCodeType {
fn initialization_fn(&self) -> Option<String> {
self.imp.has_callback_interface().then(|| {
format!(
"uniffi::UniffiCallbackInterface{}::init",
self.canonical_name()
"uniffi::{}::init",
callback_interface_name(&self.canonical_name()).unwrap()
)
})
}
Expand Down
2 changes: 1 addition & 1 deletion bindgen/src/bindings/cpp/templates/callback.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{%- let class_name = type_name|class_name %}
{%- let canonical_type_name = typ|canonical_name %}
{%- let trait_impl=format!("UniffiCallbackInterface{}", canonical_type_name) %}
{%- let trait_impl = canonical_type_name|callback_interface_name %}

{% call macros::docstring_value(interface_docstring, 0) %}
struct {{ interface_name }} {
Expand Down
2 changes: 1 addition & 1 deletion bindgen/src/bindings/cpp/templates/callback_iface_tmpl.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{%- let ffi_converter_name = typ|ffi_converter_name %}
{%- let class_name = ffi_converter_name|class_name %}
{%- let canonical_type_name = typ|canonical_name %}
{%- let trait_impl=format!("UniffiCallbackInterface{}", canonical_type_name) %}
{%- let trait_impl = canonical_type_name|callback_interface_name %}

{%- for (ffi_callback, method) in vtable_methods.iter() %}
{% call macros::ffi_return_type(ffi_callback) %} {{ trait_impl}}::{{ method.name()|var_name }}({% call macros::arg_list_ffi_decl_xx(ffi_callback) %}) {
Expand Down
2 changes: 1 addition & 1 deletion bindgen/src/bindings/cpp/templates/obj_conv.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{%- let obj = ci|get_object_definition(name) %}
{%- let canonical_type_name = typ|canonical_name %}
{%- let trait_impl=format!("UniffiCallbackInterface{}", canonical_type_name) %}
{%- let trait_impl = canonical_type_name|callback_interface_name %}

{%- let is_error = ci.is_name_used_as_error(name) %}
{%- if is_error %}
Expand Down

0 comments on commit 364771d

Please # to comment.