Skip to content

Commit

Permalink
fix: don't use _z_noop_move in svec
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Nov 2, 2024
1 parent a9e3dc6 commit a617600
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 35 deletions.
5 changes: 1 addition & 4 deletions include/zenoh-pico/collections/bytes.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ inline size_t _z_arc_slice_size(const _z_arc_slice_t *s) {
(void)s;
return sizeof(_z_arc_slice_t);
}
static inline void _z_arc_slice_elem_move(void *dst, void *src) {
_z_arc_slice_move((_z_arc_slice_t *)dst, (_z_arc_slice_t *)src);
}
_Z_ELEM_DEFINE(_z_arc_slice, _z_arc_slice_t, _z_arc_slice_size, _z_arc_slice_drop, _z_arc_slice_copy)
_Z_ELEM_DEFINE(_z_arc_slice, _z_arc_slice_t, _z_arc_slice_size, _z_arc_slice_drop, _z_arc_slice_copy, _z_arc_slice_move)
_Z_SVEC_DEFINE(_z_arc_slice, _z_arc_slice_t)

/*-------- Bytes --------*/
Expand Down
5 changes: 3 additions & 2 deletions include/zenoh-pico/collections/element.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ typedef void (*z_element_move_f)(void *dst, void *src);
typedef void *(*z_element_clone_f)(const void *e);
typedef bool (*z_element_eq_f)(const void *left, const void *right);

#define _Z_ELEM_DEFINE(name, type, elem_size_f, elem_clear_f, elem_copy_f) \
#define _Z_ELEM_DEFINE(name, type, elem_size_f, elem_clear_f, elem_copy_f, elem_move_f) \
typedef bool (*name##_eq_f)(const type *left, const type *right); \
static inline void name##_elem_clear(void *e) { elem_clear_f((type *)e); } \
static inline void name##_elem_free(void **e) { \
Expand All @@ -41,6 +41,7 @@ typedef bool (*z_element_eq_f)(const void *left, const void *right);
*e = NULL; \
} \
} \
static inline void name##_elem_move(void *dst, void *src) { elem_move_f((type *)dst, (type *)src); } \
static inline void name##_elem_copy(void *dst, const void *src) { elem_copy_f((type *)dst, (type *)src); } \
static inline void *name##_elem_clone(const void *src) { \
type *dst = (type *)z_malloc(elem_size_f((type *)src)); \
Expand Down Expand Up @@ -72,6 +73,6 @@ static inline void _z_noop_move(void *dst, void *src) {
_ZP_UNUSED(src);
}

_Z_ELEM_DEFINE(_z_noop, _z_noop_t, _z_noop_size, _z_noop_clear, _z_noop_copy)
_Z_ELEM_DEFINE(_z_noop, _z_noop_t, _z_noop_size, _z_noop_clear, _z_noop_copy, _z_noop_move)

#endif /* ZENOH_PICO_COLLECTIONS_ELEMENT_H */
6 changes: 2 additions & 4 deletions include/zenoh-pico/collections/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ bool _z_str_eq(const char *left, const char *right);
size_t _z_str_size(const char *src);
void _z_str_copy(char *dst, const char *src);
void _z_str_n_copy(char *dst, const char *src, size_t size);
_Z_ELEM_DEFINE(_z_str, char, _z_str_size, _z_noop_clear, _z_str_copy)
_Z_ELEM_DEFINE(_z_str, char, _z_str_size, _z_noop_clear, _z_str_copy, _z_noop_move)

_Z_VEC_DEFINE(_z_str, char)
_Z_LIST_DEFINE(_z_str, char)
Expand Down Expand Up @@ -97,9 +97,7 @@ bool _z_string_equals(const _z_string_t *left, const _z_string_t *right);
_z_string_t _z_string_convert_bytes(const _z_slice_t *bs);
_z_string_t _z_string_preallocate(const size_t len);

_Z_ELEM_DEFINE(_z_string, _z_string_t, _z_string_len, _z_string_clear, _z_string_copy)

static inline void _z_string_elem_move(void *dst, void *src) { _z_string_move((_z_string_t *)dst, (_z_string_t *)src); }
_Z_ELEM_DEFINE(_z_string, _z_string_t, _z_string_len, _z_string_clear, _z_string_copy, _z_string_move)
_Z_SVEC_DEFINE(_z_string, _z_string_t)
_Z_LIST_DEFINE(_z_string, _z_string_t)
_Z_INT_MAP_DEFINE(_z_string, _z_string_t)
Expand Down
2 changes: 1 addition & 1 deletion include/zenoh-pico/link/endpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ z_result_t _z_locator_from_string(_z_locator_t *lc, _z_string_t *s);

size_t _z_locator_size(_z_locator_t *lc);
void _z_locator_clear(_z_locator_t *lc);
_Z_ELEM_DEFINE(_z_locator, _z_locator_t, _z_locator_size, _z_locator_clear, _z_noop_copy)
_Z_ELEM_DEFINE(_z_locator, _z_locator_t, _z_locator_size, _z_locator_clear, _z_noop_copy, _z_noop_move)

/*------------------ Locator array ------------------*/
_Z_ARRAY_DEFINE(_z_locator, _z_locator_t)
Expand Down
4 changes: 2 additions & 2 deletions include/zenoh-pico/net/reply.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static inline _z_reply_data_t _z_reply_data_init(void) {
void _z_reply_data_clear(_z_reply_data_t *rd);
z_result_t _z_reply_data_copy(_z_reply_data_t *dst, const _z_reply_data_t *src);

_Z_ELEM_DEFINE(_z_reply_data, _z_reply_data_t, _z_noop_size, _z_reply_data_clear, _z_noop_copy)
_Z_ELEM_DEFINE(_z_reply_data, _z_reply_data_t, _z_noop_size, _z_reply_data_clear, _z_noop_copy, _z_noop_move)
_Z_LIST_DEFINE(_z_reply_data, _z_reply_data_t)

/**
Expand Down Expand Up @@ -102,7 +102,7 @@ typedef struct _z_pending_reply_t {
bool _z_pending_reply_eq(const _z_pending_reply_t *one, const _z_pending_reply_t *two);
void _z_pending_reply_clear(_z_pending_reply_t *res);

_Z_ELEM_DEFINE(_z_pending_reply, _z_pending_reply_t, _z_noop_size, _z_pending_reply_clear, _z_noop_copy)
_Z_ELEM_DEFINE(_z_pending_reply, _z_pending_reply_t, _z_noop_size, _z_pending_reply_clear, _z_noop_copy, _z_noop_move)
_Z_LIST_DEFINE(_z_pending_reply, _z_pending_reply_t)

#endif /* ZENOH_PICO_REPLY_NETAPI_H */
2 changes: 1 addition & 1 deletion include/zenoh-pico/protocol/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ z_result_t _z_hello_copy(_z_hello_t *dst, const _z_hello_t *src);

bool _z_hello_check(const _z_hello_t *hello);

_Z_ELEM_DEFINE(_z_hello, _z_hello_t, _z_noop_size, _z_hello_clear, _z_noop_copy)
_Z_ELEM_DEFINE(_z_hello, _z_hello_t, _z_noop_size, _z_hello_clear, _z_noop_copy, _z_noop_move)
_Z_LIST_DEFINE(_z_hello, _z_hello_t)

typedef struct {
Expand Down
2 changes: 1 addition & 1 deletion include/zenoh-pico/protocol/definitions/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ void _z_n_msg_clear(_z_network_message_t *m);
void _z_n_msg_free(_z_network_message_t **m);
inline static void _z_msg_clear(_z_zenoh_message_t *msg) { _z_n_msg_clear(msg); }
inline static void _z_msg_free(_z_zenoh_message_t **msg) { _z_n_msg_free(msg); }
_Z_ELEM_DEFINE(_z_network_message, _z_network_message_t, _z_noop_size, _z_n_msg_clear, _z_noop_copy)
_Z_ELEM_DEFINE(_z_network_message, _z_network_message_t, _z_noop_size, _z_n_msg_clear, _z_noop_copy, _z_noop_move)
_Z_VEC_DEFINE(_z_network_message, _z_network_message_t)

void _z_msg_fix_mapping(_z_zenoh_message_t *msg, uint16_t mapping);
Expand Down
2 changes: 1 addition & 1 deletion include/zenoh-pico/protocol/ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void _z_msg_ext_copy_unit(_z_msg_ext_unit_t *clone, const _z_msg_ext_unit_t *ext
void _z_msg_ext_copy_zint(_z_msg_ext_zint_t *clone, const _z_msg_ext_zint_t *ext);
void _z_msg_ext_copy_zbuf(_z_msg_ext_zbuf_t *clone, const _z_msg_ext_zbuf_t *ext);

_Z_ELEM_DEFINE(_z_msg_ext, _z_msg_ext_t, _z_noop_size, _z_msg_ext_clear, _z_msg_ext_copy)
_Z_ELEM_DEFINE(_z_msg_ext, _z_msg_ext_t, _z_noop_size, _z_msg_ext_clear, _z_msg_ext_copy, _z_noop_move)
_Z_VEC_DEFINE(_z_msg_ext, _z_msg_ext_t)

#endif /* ZENOH_PICO_PROTOCOL_EXTENSION_H */
2 changes: 1 addition & 1 deletion include/zenoh-pico/protocol/iobuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void _z_iosli_free(_z_iosli_t **ios);
void _z_iosli_copy(_z_iosli_t *dst, const _z_iosli_t *src);
_z_iosli_t *_z_iosli_clone(const _z_iosli_t *src);

_Z_ELEM_DEFINE(_z_iosli, _z_iosli_t, _z_iosli_size, _z_iosli_clear, _z_iosli_copy)
_Z_ELEM_DEFINE(_z_iosli, _z_iosli_t, _z_iosli_size, _z_iosli_clear, _z_iosli_copy, _z_noop_move)
_Z_VEC_DEFINE(_z_iosli, _z_iosli_t)

/*------------------ ZBuf ------------------*/
Expand Down
20 changes: 11 additions & 9 deletions include/zenoh-pico/session/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void _z_resource_clear(_z_resource_t *res);
void _z_resource_copy(_z_resource_t *dst, const _z_resource_t *src);
void _z_resource_free(_z_resource_t **res);

_Z_ELEM_DEFINE(_z_resource, _z_resource_t, _z_noop_size, _z_resource_clear, _z_resource_copy)
_Z_ELEM_DEFINE(_z_resource, _z_resource_t, _z_noop_size, _z_resource_clear, _z_resource_copy, _z_noop_move)
_Z_LIST_DEFINE(_z_resource, _z_resource_t)

// Forward declaration to avoid cyclical include
Expand All @@ -69,9 +69,9 @@ bool _z_subscription_eq(const _z_subscription_t *one, const _z_subscription_t *t
void _z_subscription_clear(_z_subscription_t *sub);

_Z_REFCOUNT_DEFINE(_z_subscription, _z_subscription)
_Z_ELEM_DEFINE(_z_subscriber, _z_subscription_t, _z_noop_size, _z_subscription_clear, _z_noop_copy)
_Z_ELEM_DEFINE(_z_subscriber, _z_subscription_t, _z_noop_size, _z_subscription_clear, _z_noop_copy, _z_noop_move)
_Z_ELEM_DEFINE(_z_subscription_rc, _z_subscription_rc_t, _z_subscription_rc_size, _z_subscription_rc_drop,
_z_subscription_rc_copy)
_z_subscription_rc_copy, _z_noop_move)
_Z_LIST_DEFINE(_z_subscription_rc, _z_subscription_rc_t)

typedef struct {
Expand Down Expand Up @@ -100,9 +100,10 @@ bool _z_session_queryable_eq(const _z_session_queryable_t *one, const _z_session
void _z_session_queryable_clear(_z_session_queryable_t *res);

_Z_REFCOUNT_DEFINE(_z_session_queryable, _z_session_queryable)
_Z_ELEM_DEFINE(_z_session_queryable, _z_session_queryable_t, _z_noop_size, _z_session_queryable_clear, _z_noop_copy)
_Z_ELEM_DEFINE(_z_session_queryable, _z_session_queryable_t, _z_noop_size, _z_session_queryable_clear, _z_noop_copy,
_z_noop_move)
_Z_ELEM_DEFINE(_z_session_queryable_rc, _z_session_queryable_rc_t, _z_noop_size, _z_session_queryable_rc_drop,
_z_noop_copy)
_z_noop_copy, _z_noop_move)
_Z_LIST_DEFINE(_z_session_queryable_rc, _z_session_queryable_rc_t)

// Forward declaration to avoid cyclical includes
Expand Down Expand Up @@ -133,7 +134,7 @@ typedef struct {
bool _z_pending_query_eq(const _z_pending_query_t *one, const _z_pending_query_t *two);
void _z_pending_query_clear(_z_pending_query_t *res);

_Z_ELEM_DEFINE(_z_pending_query, _z_pending_query_t, _z_noop_size, _z_pending_query_clear, _z_noop_copy)
_Z_ELEM_DEFINE(_z_pending_query, _z_pending_query_t, _z_noop_size, _z_pending_query_clear, _z_noop_copy, _z_noop_move)
_Z_LIST_DEFINE(_z_pending_query, _z_pending_query_t)

typedef struct {
Expand Down Expand Up @@ -184,9 +185,10 @@ bool _z_session_interest_eq(const _z_session_interest_t *one, const _z_session_i
void _z_session_interest_clear(_z_session_interest_t *res);

_Z_REFCOUNT_DEFINE(_z_session_interest, _z_session_interest)
_Z_ELEM_DEFINE(_z_session_interest, _z_session_interest_t, _z_noop_size, _z_session_interest_clear, _z_noop_copy)
_Z_ELEM_DEFINE(_z_session_interest, _z_session_interest_t, _z_noop_size, _z_session_interest_clear, _z_noop_copy,
_z_noop_move)
_Z_ELEM_DEFINE(_z_session_interest_rc, _z_session_interest_rc_t, _z_noop_size, _z_session_interest_rc_drop,
_z_noop_copy)
_z_noop_copy, _z_noop_move)
_Z_LIST_DEFINE(_z_session_interest_rc, _z_session_interest_rc_t)

typedef enum {
Expand All @@ -202,7 +204,7 @@ typedef struct {
} _z_declare_data_t;

void _z_declare_data_clear(_z_declare_data_t *data);
_Z_ELEM_DEFINE(_z_declare_data, _z_declare_data_t, _z_noop_size, _z_declare_data_clear, _z_noop_copy)
_Z_ELEM_DEFINE(_z_declare_data, _z_declare_data_t, _z_noop_size, _z_declare_data_clear, _z_noop_copy, _z_noop_move)
_Z_LIST_DEFINE(_z_declare_data, _z_declare_data_t)

#endif /* INCLUDE_ZENOH_PICO_SESSION_SESSION_H */
5 changes: 1 addition & 4 deletions include/zenoh-pico/session/subscription.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ typedef struct {
void *arg;
} _z_subscription_infos_t;

static inline void _z_subscription_infos_elem_move(void *dst, void *src) {
*(_z_subscription_infos_t *)dst = *(_z_subscription_infos_t *)src;
}
_Z_ELEM_DEFINE(_z_subscription_infos, _z_subscription_infos_t, _z_noop_size, _z_noop_clear, _z_noop_copy)
_Z_ELEM_DEFINE(_z_subscription_infos, _z_subscription_infos_t, _z_noop_size, _z_noop_clear, _z_noop_copy, _z_noop_move)
_Z_SVEC_DEFINE(_z_subscription_infos, _z_subscription_infos_t)

typedef struct {
Expand Down
5 changes: 3 additions & 2 deletions include/zenoh-pico/system/link/raweth.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ typedef struct {
void _z_raweth_clear_mapping_entry(_zp_raweth_mapping_entry_t *entry);

_Z_ELEM_DEFINE(_zp_raweth_mapping, _zp_raweth_mapping_entry_t, _z_noop_size, _z_raweth_clear_mapping_entry,
_z_noop_copy)
_z_noop_copy, _z_noop_move)
_Z_ARRAY_DEFINE(_zp_raweth_mapping, _zp_raweth_mapping_entry_t)

typedef struct {
uint8_t _mac[_ZP_MAC_ADDR_LENGTH];
} _zp_raweth_whitelist_entry_t;

_Z_ELEM_DEFINE(_zp_raweth_whitelist, _zp_raweth_whitelist_entry_t, _z_noop_size, _z_noop_clear, _z_noop_copy)
_Z_ELEM_DEFINE(_zp_raweth_whitelist, _zp_raweth_whitelist_entry_t, _z_noop_size, _z_noop_clear, _z_noop_copy,
_z_noop_move)
_Z_ARRAY_DEFINE(_zp_raweth_whitelist, _zp_raweth_whitelist_entry_t)

// Ethernet header structure type
Expand Down
4 changes: 2 additions & 2 deletions include/zenoh-pico/transport/transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void _z_transport_peer_entry_clear(_z_transport_peer_entry_t *src);
void _z_transport_peer_entry_copy(_z_transport_peer_entry_t *dst, const _z_transport_peer_entry_t *src);
bool _z_transport_peer_entry_eq(const _z_transport_peer_entry_t *left, const _z_transport_peer_entry_t *right);
_Z_ELEM_DEFINE(_z_transport_peer_entry, _z_transport_peer_entry_t, _z_transport_peer_entry_size,
_z_transport_peer_entry_clear, _z_transport_peer_entry_copy)
_z_transport_peer_entry_clear, _z_transport_peer_entry_copy, _z_noop_move)
_Z_LIST_DEFINE(_z_transport_peer_entry, _z_transport_peer_entry_t)
_z_transport_peer_entry_list_t *_z_transport_peer_entry_list_insert(_z_transport_peer_entry_list_t *root,
_z_transport_peer_entry_t *entry);
Expand Down Expand Up @@ -139,7 +139,7 @@ typedef struct {
enum { _Z_TRANSPORT_UNICAST_TYPE, _Z_TRANSPORT_MULTICAST_TYPE, _Z_TRANSPORT_RAWETH_TYPE, _Z_TRANSPORT_NONE } _type;
} _z_transport_t;

_Z_ELEM_DEFINE(_z_transport, _z_transport_t, _z_noop_size, _z_noop_clear, _z_noop_copy)
_Z_ELEM_DEFINE(_z_transport, _z_transport_t, _z_noop_size, _z_noop_clear, _z_noop_copy, _z_noop_move)
_Z_LIST_DEFINE(_z_transport, _z_transport_t)

typedef struct {
Expand Down
2 changes: 1 addition & 1 deletion src/collections/vec.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void __z_svec_copy_inner(void *dst, const void *src, z_element_copy_f copy, size
}

void __z_svec_move_inner(void *dst, void *src, z_element_move_f move, size_t num_elements, size_t element_size) {
if (move == NULL) {
if (move == _z_noop_move) {
memcpy(dst, src, num_elements * element_size);
} else {
size_t offset = 0;
Expand Down

0 comments on commit a617600

Please sign in to comment.