Skip to content

fix potential API inconsistency for z_source_info_t and other copyable types #1174

@milyin

Description

@milyin

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

=

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions