Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid generated code for allocation_size for empty record #45

Closed
artemyarulin opened this issue Sep 18, 2024 · 3 comments · Fixed by #48
Closed

Invalid generated code for allocation_size for empty record #45

artemyarulin opened this issue Sep 18, 2024 · 3 comments · Fixed by #48

Comments

@artemyarulin
Copy link
Contributor

For the UDL

namespace A {};
dictionary B {};

If I run a latest released generator (v0.6.2+v0.25.0) uniffi-bindgen-cpp foo.udl --out-dir build it will create a A.cpp with this code at end end

void FfiConverterTypeB::write(RustStream &stream, const B &val) {
}

int32_t FfiConverterTypeB::allocation_size(const B &val) {
    return 
}

}} // namespace A

Notice missing value after return for allocation_size.

I'm not sure how generator works, but my guess it's because template iterates through all the fields and if there are none then there is no fallback value:

int32_t {{ ffi_converter_name }}::allocation_size(const {{ class_name }} &val) {
return {% for field in rec.fields() %}
{{ field|allocation_size_fn}}(val.{{ field.name()|var_name() }}){% if !loop.last %} +{% else -%};{%- endif %}
{%- endfor %}
}

@Lipt0nas
Copy link
Member

Hey! sorry for the late reply, could you give the branch a try to see if it works as expected?

@artemyarulin
Copy link
Contributor Author

Yeah, that solves it - thanks a lot!

@Lipt0nas
Copy link
Member

Lipt0nas commented Oct 2, 2024

Nice! I'll make a new tag with the changes then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants