Skip to content

Commit

Permalink
Fix empty struct
Browse files Browse the repository at this point in the history
Signed-off-by: Kristupas Antanavičius <[email protected]>
  • Loading branch information
arg0d committed Oct 11, 2024
1 parent 1913e7a commit 6f615b1
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 3 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions bindgen/templates/RecordTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ class {{ rec|ffi_converter_name }}: FfiConverterRustBuffer<{{ type_name }}> {
}

public override int AllocationSize({{ type_name }} value) {
return
return 0
{%- for field in rec.fields() %}
{{ field|allocation_size_fn }}(value.{{ field.name()|var_name }}){% if !loop.last %} +{% endif%}
+ {{ field|allocation_size_fn }}(value.{{ field.name()|var_name }})
{%- endfor -%};
}

Expand Down
16 changes: 16 additions & 0 deletions dotnet-tests/UniffiCS.BindingTests/TestIssue75.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

using uniffi.issue_75;

namespace UniffiCS.BindingTests;

public class ClassIssue75
{
[Fact]
public void TestIssue75()
{
new uniffi.issue_75.EmptyDictionary();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace UniffiCS.BindingTests;

public class TestRegressions
public class ClassIssue76
{
[Fact]
public void TestIssue76()
Expand Down
1 change: 1 addition & 0 deletions fixtures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ crate-type = ["cdylib", "lib"]

[dependencies]
global-methods-class-name = { path = "global-methods-class-name" }
issue-75 = { path = "regressions/issue-75" }
issue-76 = { path = "regressions/issue-76" }
null-to-empty-string = { path = "null-to-empty-string" }
uniffi-cs-custom-types-builtin = { path = "custom-types-builtin" }
Expand Down
18 changes: 18 additions & 0 deletions fixtures/regressions/issue-75/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "issue-75"
version = "1.0.0"
edition = "2021"
publish = false

[lib]
crate-type = ["lib", "cdylib"]
name = "issue_75"

[dependencies]
once_cell = "1.12"
thiserror = "1.0"
uniffi = {path = "../../../3rd-party/uniffi-rs/uniffi", features=["build"]}
uniffi_macros = {path = "../../../3rd-party/uniffi-rs/uniffi_macros"}

[build-dependencies]
uniffi = {path = "../../../3rd-party/uniffi-rs/uniffi", features=["bindgen-tests"]}
3 changes: 3 additions & 0 deletions fixtures/regressions/issue-75/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://github.com/NordSecurity/uniffi-bindgen-cs/issues/75

Empty struct causes invalid code to be generated in `RecordTemplate.cs::AllocationSize`
9 changes: 9 additions & 0 deletions fixtures/regressions/issue-75/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#[derive(uniffi::Record)]
pub struct EmptyDictionary {
}

uniffi::setup_scaffolding!();
1 change: 1 addition & 0 deletions fixtures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ mod uniffi_fixtures {
uniffi_cs_disposable::uniffi_reexport_scaffolding!();
uniffi_cs_optional_parameters::uniffi_reexport_scaffolding!();
stringify::uniffi_reexport_scaffolding!();
issue_75::uniffi_reexport_scaffolding!();
issue_76::uniffi_reexport_scaffolding!();
}

0 comments on commit 6f615b1

Please sign in to comment.