Describe the bug
The zenoh-c API proposes two patterns for opaque mapping Rust structures to C:
z_owned_xxx_t - the "owned" type is created by constructing function and have to be dropped with destructor in the end of it's lifetime, as it may contain external references (allocated memory, handles, etc). Most of types are like this: e.g. z_owned_sample_t for rust's Sample
z_xxx_t for bitwise copyable types. The examples are z_id_t for ZenohId and z_timestamp_t
Recently the type z_source_info_t was made instead of z_owned_source_info_t. This change is potentially dangerous as on the rust side the corresponding SourceInfo type doesn't implement Copy trait and therefore in some future update can be modified to hold non-copy field (e.g. store some long string on the heap). This will make C API incompatible with rust one.
Solution:
- add "#[derive(Copy)]" to
SourceInfo on the rust side to explicily guarantee that SourceInfo will be always bitwise copyable
- add to the macro
decl_c_type!(copy ... validation, that the corresponding rust type implements Copy trait to avoid such deviations in future
To reproduce
=
System info
=
Describe the bug
The zenoh-c API proposes two patterns for opaque mapping Rust structures to C:
z_owned_xxx_t- the "owned" type is created by constructing function and have to be dropped with destructor in the end of it's lifetime, as it may contain external references (allocated memory, handles, etc). Most of types are like this: e.g.z_owned_sample_tfor rust'sSamplez_xxx_tfor bitwise copyable types. The examples arez_id_tforZenohIdandz_timestamp_tRecently the type
z_source_info_twas made instead ofz_owned_source_info_t. This change is potentially dangerous as on the rust side the correspondingSourceInfotype doesn't implementCopytrait and therefore in some future update can be modified to hold non-copy field (e.g. store some long string on the heap). This will make C API incompatible with rust one.Solution:
SourceInfoon the rust side to explicily guarantee thatSourceInfowill be always bitwise copyabledecl_c_type!(copy ...validation, that the corresponding rust type implementsCopytrait to avoid such deviations in futureTo reproduce
=
System info
=