Skip to content

Commit

Permalink
Deduplicate ffi arg list in callbacks
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Fetti <daniel.fetti@nordsec.com>
  • Loading branch information
arg0d authored and dfetti committed Jan 15, 2025
1 parent 8425cb6 commit 6c6a01d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bindgen/templates/CallbackInterfaceTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
class {{ foreign_callback }} {
{%- for (ffi_callback, meth) in vtable_methods.iter() %}

static {% call cs::func_return_type(ffi_callback) %} {{ meth.name()|var_name }}({% call cs::arg_list_ffi_decl_xx(ffi_callback) %}) {
static {% call cs::ffi_return_type(ffi_callback) %} {{ meth.name()|var_name }}({% call cs::arg_list_ffi_decl_xx(ffi_callback) %}) {

}
{%- endfor %}
Expand Down
9 changes: 2 additions & 7 deletions bindgen/templates/NamespaceLibraryTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@ static class _UniFFILib {
{%- match def %}
{%- when FfiDefinition::CallbackFunction(callback) %}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate {% if callback.return_type().is_some() %}{{ callback.return_type().unwrap()|ffi_type_name }}{% else %}void{% endif %} {{ callback.name()|ffi_callback_name }}(
{%- for arg in callback.arguments() %}
{{ arg.type_().borrow()|ffi_type_name }} {{ arg.name().borrow()|var_name }}{%- if !loop.last || callback.has_rust_call_status_arg() -%},{%- endif -%}
{%- endfor %}
{%- if callback.has_rust_call_status_arg() %}
ref UniffiRustCallStatus uniffiCallStatus
{%- endif %}
public delegate {% call cs::ffi_return_type(callback) %} {{ callback.name()|ffi_callback_name }}(
{% call cs::arg_list_ffi_decl_xx(callback) %}
);
{%- when FfiDefinition::Struct(ffi_struct) %}
[StructLayout(LayoutKind.Sequential)]
Expand Down
2 changes: 1 addition & 1 deletion bindgen/templates/macros.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
{%- if func.has_rust_call_status_arg() %}ref UniffiRustCallStatus _uniffi_out_err{% endif %}
{%- endmacro -%}

{%- macro func_return_type(func) %}
{%- macro ffi_return_type(func) %}
{%- match func.return_type() %}
{%- when Some(return_type) %}{{ return_type|ffi_type_name }}
{%- when None %}{{ "void" }}
Expand Down

0 comments on commit 6c6a01d

Please sign in to comment.