From 60ff708b0118fee9d6dbbacf1fe976dff190e66b Mon Sep 17 00:00:00 2001 From: Jean-Roland Gosse Date: Thu, 20 Jun 2024 11:25:49 +0200 Subject: [PATCH] Fix compilation issues (#431) * feat: remove deprecated files * fix: library ignored unix compile options, issue #422 * fix: update deprecated syscalls * fix: previously ignored compilation errors * fix: bad function return type * fix: cast strtoul return value * fix: avoid mask instruction * fix: ptrdiff_t casting * fix: unsigned constants * fix: ext size calculation * fix: ext number calculation * fix: internal int type casting * fix: unix system type casting * chore: run clang * fix: windows compilation * fix: usleep arg type cast * fix: set lease factor as int * fix: lease substraction on unsigned type * build: use debug config by default with cmake * ci: switch tests to dev/1.0.0 zenoh branch * fix: missing end of file * fix: replace ssize_t * fix: missing end of file newline * build: don't set -Wpedantic on unix c99 * fix: missing end of file newline * fix: bad function prototypes * fix: bad return function * fix: bad function prototype * fix: missing end of file newline * fix: remove linux specific type cast * fix: raweth & single thread compilation issues * fix: modularity compilation issues * fix: raweth compilation issues * fix: api test compiler issue * fix: sub memory leak * fix: remove rebase shenanigans * fix: empty struct error --- .github/workflows/build-check.yaml | 2 +- .github/workflows/integration.yaml | 2 +- .github/workflows/multicast.yaml | 2 +- CMakeLists.txt | 73 ++++++++------- examples/unix/c11/z_pull.c | 2 +- include/zenoh-pico/api/handlers.h | 28 +++--- include/zenoh-pico/collections/fifo_mt.h | 6 +- include/zenoh-pico/collections/ring_mt.h | 4 +- include/zenoh-pico/config.h | 2 +- include/zenoh-pico/deprecated/platform.h | 88 ------------------- include/zenoh-pico/link/config/bt.h | 2 +- include/zenoh-pico/link/config/serial.h | 2 +- .../zenoh-pico/protocol/definitions/core.h | 2 +- include/zenoh-pico/session/push.h | 2 +- include/zenoh-pico/session/reply.h | 2 +- include/zenoh-pico/session/resource.h | 2 +- include/zenoh-pico/system/link/raweth.h | 4 +- include/zenoh-pico/system/platform.h | 1 - src/api/api.c | 30 ++++--- src/collections/fifo.c | 2 +- src/collections/fifo_mt.c | 43 ++++----- src/collections/lifo.c | 6 +- src/collections/ring.c | 6 +- src/collections/ring_mt.c | 30 +++---- src/collections/slice.c | 2 +- src/deprecated/platform.c | 63 ------------- src/link/config/ws.c | 3 +- src/link/multicast/udp.c | 4 +- src/link/unicast/tcp.c | 4 +- src/link/unicast/udp.c | 6 +- src/net/encoding.c | 2 +- src/net/primitives.c | 4 +- src/net/sample.c | 2 +- src/net/session.c | 4 +- src/protocol/codec.c | 4 +- src/protocol/codec/declarations.c | 2 + src/protocol/codec/message.c | 13 +-- src/protocol/codec/network.c | 21 ++--- src/protocol/codec/transport.c | 6 +- src/protocol/core.c | 6 +- src/protocol/definitions/network.c | 2 +- src/protocol/definitions/transport.c | 12 ++- src/protocol/iobuf.c | 12 +-- src/protocol/keyexpr.c | 28 +++--- src/session/push.c | 7 +- src/session/reply.c | 6 ++ src/session/resource.c | 4 +- src/session/rx.c | 4 +- src/session/subscription.c | 1 + src/session/utils.c | 2 +- src/system/unix/link/raweth.c | 11 +-- src/system/unix/network.c | 32 ++++--- src/system/unix/system.c | 42 ++++----- src/transport/multicast/lease.c | 85 +++++++++--------- src/transport/raweth/link.c | 12 +-- src/transport/raweth/rx.c | 6 +- src/transport/raweth/tx.c | 10 +-- src/transport/unicast/lease.c | 18 ++-- src/transport/unicast/rx.c | 2 +- src/utils/encoding.c | 2 +- src/utils/pointers.c | 4 +- src/utils/string.c | 10 +-- tests/z_api_alignment_test.c | 2 +- 63 files changed, 346 insertions(+), 457 deletions(-) delete mode 100644 include/zenoh-pico/deprecated/platform.h delete mode 100644 src/deprecated/platform.c diff --git a/.github/workflows/build-check.yaml b/.github/workflows/build-check.yaml index 3e1f3d69d..37fab7d0b 100644 --- a/.github/workflows/build-check.yaml +++ b/.github/workflows/build-check.yaml @@ -77,7 +77,7 @@ jobs: uses: eclipse-zenoh/ci/build-crates-standalone@main with: repo: eclipse-zenoh/zenoh - branch: interests + branch: dev/1.0.0 artifact-patterns: | ^zenohd$ ^libzenoh_plugin_rest.so$ diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index f6a6acb7f..7348f76c0 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -50,4 +50,4 @@ jobs: BUILD_TESTING: OFF # Workaround for Windows as it seems the previous step is being ignored BUILD_MULTICAST: OFF # Workaround for Windows as it seems the previous step is being ignored BUILD_INTEGRATION: ON # Workaround for Windows as it seems the previous step is being ignored - ZENOH_BRANCH: interests + ZENOH_BRANCH: dev/1.0.0 diff --git a/.github/workflows/multicast.yaml b/.github/workflows/multicast.yaml index 1cd04985c..c3b841fed 100644 --- a/.github/workflows/multicast.yaml +++ b/.github/workflows/multicast.yaml @@ -40,7 +40,7 @@ jobs: BUILD_TESTING: OFF BUILD_MULTICAST: ON BUILD_INTEGRATION: OFF - ZENOH_BRANCH: interests + ZENOH_BRANCH: dev/1.0.0 - name: Test debug run: make test diff --git a/CMakeLists.txt b/CMakeLists.txt index cf15dadea..6fe9adbea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,42 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "Generic") endif() endif() +# Language options +if(NOT CMAKE_C_STANDARD) + if(c_std_11 IN_LIST CMAKE_C_COMPILE_FEATURES) + set(CMAKE_C_STANDARD 11) + message(STATUS "Setting C11 as the C Standard") + else() + # C99 pedantic doesn't like unix header anonymous structure + set(CMAKE_C_STANDARD 99) + message(STATUS "Setting C99 as the C Standard") + endif() +endif() +set(CMAKE_C_STANDARD_REQUIRED TRUE) + +# Compile options +if(CMAKE_BUILD_TYPE MATCHES "RELEASE" OR "Release") + if(UNIX) + add_compile_options(-pipe -O3) + elseif(CMAKE_SYSTEM_NAME MATCHES "Generic") + add_compile_options(-pipe -O3) + endif() +else() + if(UNIX) + add_compile_options(-c -Wall -Wextra -Werror -Wshadow -Wunused -Wstrict-prototypes -pipe -g -O0) + # C99 pedantic doesn't like struct anonymous in unix header + if (NOT CMAKE_C_STANDARD STREQUAL "99") + add_compile_options(-Wpedantic) + endif() + # add_compile_options(-Wconversion) + # add_link_options(-fsanitize=address) + elseif(MSVC) + add_compile_options(/W4 /WX /Od /wd4127) + elseif(CMAKE_SYSTEM_NAME MATCHES "Generic") + add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes -pipe -g -O0) + endif() +endif() + set(Libname "zenohpico") if(BUILD_SHARED_LIBS) add_library(${Libname} SHARED) @@ -50,16 +86,6 @@ function(add_definition value) target_compile_definitions(${Libname} PUBLIC ${value}) endfunction() -if(NOT CMAKE_C_STANDARD) - if(c_std_11 IN_LIST CMAKE_C_COMPILE_FEATURES) - set(CMAKE_C_STANDARD 11) - message(STATUS "Setting C11 as the C Standard") - else() - set(CMAKE_C_STANDARD 99) - message(STATUS "Setting C99 as the C Standard") - endif() -endif() -set(CMAKE_C_STANDARD_REQUIRED TRUE) add_definition(ZENOH_C_STANDARD=${CMAKE_C_STANDARD}) # while in development, use timestamp for patch version: @@ -175,31 +201,11 @@ if(CHECK_THREADS) find_package(Threads REQUIRED) endif() -if(CMAKE_BUILD_TYPE MATCHES "DEBUG") - if(UNIX) - # FIXME: seems to not apply to library files, Issue #422 - add_compile_options(-c -Wall -Wextra -Werror -Wshadow -Wpedantic -Wunused -Wstrict-prototypes -pipe -g -O0) - # add_compile_options(-Wconversion) - # add_link_options(-fsanitize=address) - elseif(MSVC) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /std:c11 /experimental:c11atomics") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest /experimental:c11atomics") - add_compile_options(/W4 /WX /Od /wd4127) - elseif(CMAKE_SYSTEM_NAME MATCHES "Generic") - add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes -pipe -g -O0) - endif() -elseif(CMAKE_BUILD_TYPE MATCHES "RELEASE") - if(UNIX) - add_compile_options(-pipe -O3) - elseif(MSVC) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /std:c11 /experimental:c11atomics") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest /experimental:c11atomics") - elseif(CMAKE_SYSTEM_NAME MATCHES "Generic") - add_compile_options(-pipe -O3) - endif() +if(MSVC) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /std:c11 /experimental:c11atomics") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest /experimental:c11atomics") endif() - file(GLOB_RECURSE PublicHeaders "include/zenoh-pico/api/*.h" "include/zenoh-pico/collections/*.h" @@ -216,7 +222,6 @@ target_include_directories(${Libname} PUBLIC ${PROJECT_SOURCE_DIR}/include) file(GLOB_RECURSE Sources "src/api/*.c" "src/collections/*.c" - "src/deprecated/*.c" "src/link/*.c" "src/net/*.c" "src/protocol/*.c" diff --git a/examples/unix/c11/z_pull.c b/examples/unix/c11/z_pull.c index c4bb84cae..4c8083b29 100644 --- a/examples/unix/c11/z_pull.c +++ b/examples/unix/c11/z_pull.c @@ -100,7 +100,7 @@ int main(int argc, char **argv) { z_drop(z_move(sample)); } printf(">> [Subscriber] Nothing to pull... sleep for %zu ms\n", interval); - zp_sleep_ms(interval); + z_sleep_ms(interval); } z_undeclare_subscriber(z_move(sub)); diff --git a/include/zenoh-pico/api/handlers.h b/include/zenoh-pico/api/handlers.h index 681d38f4b..473fa2477 100644 --- a/include/zenoh-pico/api/handlers.h +++ b/include/zenoh-pico/api/handlers.h @@ -37,15 +37,15 @@ \ static inline void _z_##handler_name##_elem_free(void **elem) { \ elem_drop_f((elem_owned_type *)*elem); \ - zp_free(*elem); \ + z_free(*elem); \ *elem = NULL; \ } \ static inline void _z_##handler_name##_elem_move(void *dst, void *src) { \ memcpy(dst, src, sizeof(elem_owned_type)); \ - zp_free(src); \ + z_free(src); \ } \ static inline void _z_##handler_name##_send(const elem_loaned_type *elem, void *context) { \ - elem_owned_type *internal_elem = (elem_owned_type *)zp_malloc(sizeof(elem_owned_type)); \ + elem_owned_type *internal_elem = (elem_owned_type *)z_malloc(sizeof(elem_owned_type)); \ if (internal_elem == NULL) { \ _Z_ERROR("Out of memory"); \ return; \ @@ -115,16 +115,18 @@ /* elem_copy_f */ _z_##item_name##_rc_copy, \ /* elem_drop_f */ z_##item_name##_drop) -#define _Z_CHANNEL_DEFINE_DUMMY(item_name, kind_name) \ - typedef struct { \ - } z_owned_##kind_name##_handler_##item_name##_t; \ - typedef struct { \ - } z_loaned_##kind_name##_handler_##item_name##_t; \ - void *z_##kind_name##_handler_##item_name##_loan(); \ - void *z_##kind_name##_handler_##item_name##_move(); \ - void *z_##kind_name##_handler_##item_name##_drop(); \ - void *z_##kind_name##_handler_##item_name##_recv(); \ - void *z_##kind_name##_handler_##item_name##_try_recv(); +#define _Z_CHANNEL_DEFINE_DUMMY(item_name, kind_name) \ + typedef struct { \ + uint8_t _foo; \ + } z_owned_##kind_name##_handler_##item_name##_t; \ + typedef struct { \ + uint8_t _foo; \ + } z_loaned_##kind_name##_handler_##item_name##_t; \ + void *z_##kind_name##_handler_##item_name##_loan(void); \ + void *z_##kind_name##_handler_##item_name##_move(void); \ + void *z_##kind_name##_handler_##item_name##_drop(void); \ + void *z_##kind_name##_handler_##item_name##_recv(void); \ + void *z_##kind_name##_handler_##item_name##_try_recv(void); // This macro defines: // z_ring_channel_sample_new() diff --git a/include/zenoh-pico/collections/fifo_mt.h b/include/zenoh-pico/collections/fifo_mt.h index 7a302b1a2..14d2848db 100644 --- a/include/zenoh-pico/collections/fifo_mt.h +++ b/include/zenoh-pico/collections/fifo_mt.h @@ -24,9 +24,9 @@ typedef struct { _z_fifo_t _fifo; #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_t _mutex; - zp_condvar_t _cv_not_full; - zp_condvar_t _cv_not_empty; + z_mutex_t _mutex; + z_condvar_t _cv_not_full; + z_condvar_t _cv_not_empty; #endif } _z_fifo_mt_t; diff --git a/include/zenoh-pico/collections/ring_mt.h b/include/zenoh-pico/collections/ring_mt.h index 8d5be2e8f..a52ee62d6 100644 --- a/include/zenoh-pico/collections/ring_mt.h +++ b/include/zenoh-pico/collections/ring_mt.h @@ -24,8 +24,8 @@ typedef struct { _z_ring_t _ring; #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_t _mutex; - zp_condvar_t _cv_not_empty; + z_mutex_t _mutex; + z_condvar_t _cv_not_empty; #endif } _z_ring_mt_t; diff --git a/include/zenoh-pico/config.h b/include/zenoh-pico/config.h index 08d8933b6..d7137b3b2 100644 --- a/include/zenoh-pico/config.h +++ b/include/zenoh-pico/config.h @@ -271,7 +271,7 @@ * Default session lease expire factor. */ #ifndef Z_TRANSPORT_LEASE_EXPIRE_FACTOR -#define Z_TRANSPORT_LEASE_EXPIRE_FACTOR 3.5 +#define Z_TRANSPORT_LEASE_EXPIRE_FACTOR 3 #endif /** diff --git a/include/zenoh-pico/deprecated/platform.h b/include/zenoh-pico/deprecated/platform.h deleted file mode 100644 index 5e47d65c6..000000000 --- a/include/zenoh-pico/deprecated/platform.h +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (c) 2024 ZettaScale Technology -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License 2.0 which is available at -// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// -// Contributors: -// ZettaScale Zenoh Team, - -#ifndef ZENOH_PICO_DEPRECATED_PLATFORM_H -#define ZENOH_PICO_DEPRECATED_PLATFORM_H - -#include - -#include "zenoh-pico/config.h" -#include "zenoh-pico/system/platform-common.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/*------------------ Random ------------------*/ -uint8_t zp_random_u8(void); -uint16_t zp_random_u16(void); -uint32_t zp_random_u32(void); -uint64_t zp_random_u64(void); -void zp_random_fill(void *buf, size_t len); - -/*------------------ Memory ------------------*/ -void *zp_malloc(size_t size); -void *zp_realloc(void *ptr, size_t size); -void zp_free(void *ptr); - -#if Z_FEATURE_MULTI_THREAD == 1 -/*------------------ Thread ------------------*/ -typedef z_task_t zp_task_t; -typedef z_task_attr_t zp_task_attr_t; - -int8_t zp_task_init(zp_task_t *task, zp_task_attr_t *attr, void *(*fun)(void *), void *arg); -int8_t zp_task_join(zp_task_t *task); -void zp_task_free(zp_task_t **task); - -/*------------------ Mutex ------------------*/ -typedef z_mutex_t zp_mutex_t; -int8_t zp_mutex_init(zp_mutex_t *m); -int8_t zp_mutex_free(zp_mutex_t *m); - -int8_t zp_mutex_lock(zp_mutex_t *m); -int8_t zp_mutex_trylock(zp_mutex_t *m); -int8_t zp_mutex_unlock(zp_mutex_t *m); - -/*------------------ CondVar ------------------*/ -typedef z_condvar_t zp_condvar_t; -int8_t zp_condvar_init(zp_condvar_t *cv); -int8_t zp_condvar_free(zp_condvar_t *cv); - -int8_t zp_condvar_signal(zp_condvar_t *cv); -int8_t zp_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m); -#endif // Z_FEATURE_MULTI_THREAD == 1 - -/*------------------ Sleep ------------------*/ -int zp_sleep_us(size_t time); -int zp_sleep_ms(size_t time); -int zp_sleep_s(size_t time); - -/*------------------ Clock ------------------*/ -typedef z_clock_t zp_clock_t; -zp_clock_t zp_clock_now(void); -unsigned long zp_clock_elapsed_us(zp_clock_t *time); -unsigned long zp_clock_elapsed_ms(zp_clock_t *time); -unsigned long zp_clock_elapsed_s(zp_clock_t *time); - -/*------------------ Time ------------------*/ -typedef z_time_t zp_time_t; -zp_time_t zp_time_now(void); -const char *zp_time_now_as_str(char *const buf, unsigned long buflen); -unsigned long zp_time_elapsed_us(zp_time_t *time); -unsigned long zp_time_elapsed_ms(zp_time_t *time); -unsigned long zp_time_elapsed_s(zp_time_t *time); - -#ifdef __cplusplus -} -#endif - -#endif /* ZENOH_PICO_DEPRECATED_PLATFORM_H */ diff --git a/include/zenoh-pico/link/config/bt.h b/include/zenoh-pico/link/config/bt.h index 0a68898b0..9910e9886 100644 --- a/include/zenoh-pico/link/config/bt.h +++ b/include/zenoh-pico/link/config/bt.h @@ -50,4 +50,4 @@ int8_t _z_bt_config_from_str(_z_str_intmap_t *strint, const char *s); int8_t _z_bt_config_from_strn(_z_str_intmap_t *strint, const char *s, size_t n); #endif -#endif /* ZENOH_PICO_LINK_CONFIG_BT_H */ \ No newline at end of file +#endif /* ZENOH_PICO_LINK_CONFIG_BT_H */ diff --git a/include/zenoh-pico/link/config/serial.h b/include/zenoh-pico/link/config/serial.h index 7eb4408ba..6960d2ea6 100644 --- a/include/zenoh-pico/link/config/serial.h +++ b/include/zenoh-pico/link/config/serial.h @@ -66,4 +66,4 @@ int8_t _z_serial_config_from_str(_z_str_intmap_t *strint, const char *s); int8_t _z_serial_config_from_strn(_z_str_intmap_t *strint, const char *s, size_t n); #endif -#endif /* ZENOH_PICO_LINK_CONFIG_SERIAL_H */ \ No newline at end of file +#endif /* ZENOH_PICO_LINK_CONFIG_SERIAL_H */ diff --git a/include/zenoh-pico/protocol/definitions/core.h b/include/zenoh-pico/protocol/definitions/core.h index 3fd9110b1..5d98e4baf 100644 --- a/include/zenoh-pico/protocol/definitions/core.h +++ b/include/zenoh-pico/protocol/definitions/core.h @@ -44,6 +44,6 @@ #define _Z_FLAGS(h) (_Z_FLAGS_MASK & (h)) #define _Z_HAS_FLAG(h, f) (((h) & (f)) != 0) #define _Z_SET_FLAG(h, f) (h |= f) -#define _Z_CLEAR_FLAG(h, f) (h &= ~(f)) +#define _Z_CLEAR_FLAG(h, f) (h &= (uint8_t)(~(f))) #endif /* INCLUDE_ZENOH_PICO_PROTOCOL_DEFINITIONS_CORE_H */ diff --git a/include/zenoh-pico/session/push.h b/include/zenoh-pico/session/push.h index 583746c15..76c02b2f1 100644 --- a/include/zenoh-pico/session/push.h +++ b/include/zenoh-pico/session/push.h @@ -23,4 +23,4 @@ int8_t _z_trigger_push(_z_session_t *zn, _z_n_msg_push_t *push); -#endif /* ZENOH_PICO_SESSION_PUSH_H */ \ No newline at end of file +#endif /* ZENOH_PICO_SESSION_PUSH_H */ diff --git a/include/zenoh-pico/session/reply.h b/include/zenoh-pico/session/reply.h index e84fa5c7e..050f81ee5 100644 --- a/include/zenoh-pico/session/reply.h +++ b/include/zenoh-pico/session/reply.h @@ -26,4 +26,4 @@ int8_t _z_trigger_reply_partial(_z_session_t *zn, _z_zint_t id, _z_keyexpr_t key int8_t _z_trigger_reply_final(_z_session_t *zn, _z_n_msg_response_final_t *final); -#endif /* ZENOH_PICO_SESSION_REPLY_H */ \ No newline at end of file +#endif /* ZENOH_PICO_SESSION_REPLY_H */ diff --git a/include/zenoh-pico/session/resource.h b/include/zenoh-pico/session/resource.h index 7c6ef0cc1..3702a86cd 100644 --- a/include/zenoh-pico/session/resource.h +++ b/include/zenoh-pico/session/resource.h @@ -27,7 +27,7 @@ uint16_t _z_get_resource_id(_z_session_t *zn); _z_resource_t *_z_get_resource_by_id(_z_session_t *zn, uint16_t mapping, _z_zint_t rid); _z_resource_t *_z_get_resource_by_key(_z_session_t *zn, const _z_keyexpr_t *keyexpr); _z_keyexpr_t _z_get_expanded_key_from_key(_z_session_t *zn, const _z_keyexpr_t *keyexpr); -int16_t _z_register_resource(_z_session_t *zn, const _z_keyexpr_t key, uint16_t id, uint16_t register_to_mapping); +uint16_t _z_register_resource(_z_session_t *zn, const _z_keyexpr_t key, uint16_t id, uint16_t register_to_mapping); void _z_unregister_resource(_z_session_t *zn, uint16_t id, uint16_t mapping); void _z_unregister_resources_for_peer(_z_session_t *zn, uint16_t mapping); void _z_flush_resources(_z_session_t *zn); diff --git a/include/zenoh-pico/system/link/raweth.h b/include/zenoh-pico/system/link/raweth.h index 418107f23..c5be5be6a 100644 --- a/include/zenoh-pico/system/link/raweth.h +++ b/include/zenoh-pico/system/link/raweth.h @@ -87,8 +87,8 @@ size_t _z_send_raweth(const _z_sys_net_socket_t *sock, const void *buff, size_t size_t _z_receive_raweth(const _z_sys_net_socket_t *sock, void *buff, size_t buff_len, _z_slice_t *addr, const _zp_raweth_whitelist_array_t *whitelist); int8_t _z_close_raweth(_z_sys_net_socket_t *sock); -size_t _z_raweth_ntohs(size_t val); -size_t _z_raweth_htons(size_t val); +uint16_t _z_raweth_ntohs(uint16_t val); +uint16_t _z_raweth_htons(uint16_t val); #endif diff --git a/include/zenoh-pico/system/platform.h b/include/zenoh-pico/system/platform.h index 4fe70198d..a0bf54990 100644 --- a/include/zenoh-pico/system/platform.h +++ b/include/zenoh-pico/system/platform.h @@ -18,7 +18,6 @@ #include #include "zenoh-pico/config.h" -#include "zenoh-pico/deprecated/platform.h" #include "zenoh-pico/system/platform-common.h" #endif /* ZENOH_PICO_SYSTEM_PLATFORM_H */ diff --git a/src/api/api.c b/src/api/api.c index 07a781d0e..c1ad88e1d 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -258,17 +258,6 @@ const z_loaned_encoding_t *z_encoding_loan(const z_owned_encoding_t *encoding) { z_loaned_encoding_t *z_encoding_loan_mut(z_owned_encoding_t *encoding) { return encoding->_val; } -// Convert a user owned encoding to an internal encoding, return default encoding if value invalid -static _z_encoding_t _z_encoding_from_owned(const z_owned_encoding_t *encoding) { - if (encoding == NULL) { - return _z_encoding_null(); - } - if (encoding->_val == NULL) { - return _z_encoding_null(); - } - return *encoding->_val; -} - const uint8_t *z_slice_data(const z_loaned_slice_t *slice) { return slice->start; } size_t z_slice_len(const z_loaned_slice_t *slice) { return slice->len; } @@ -581,7 +570,6 @@ int8_t zp_bytes_serialize_from_pair(z_owned_bytes_t *bytes, z_owned_bytes_t *fir // Calculate pair size size_t first_len = z_slice_len(&first->_val->_slice); size_t second_len = z_slice_len(&second->_val->_slice); - size_t len = 2 * sizeof(uint32_t) + first_len + second_len; // Copy data // FIXME: size endianness, Issue #420 memcpy((uint8_t *)&bytes->_val->_slice.start[*curr_idx], &first_len, sizeof(uint32_t)); @@ -700,6 +688,8 @@ _Z_VIEW_FUNCTIONS_PTR_IMPL(_z_string_vec_t, string_array) _Z_OWNED_FUNCTIONS_PTR_IMPL(_z_slice_t, slice, _z_slice_copy, _z_slice_free) _Z_OWNED_FUNCTIONS_PTR_IMPL(_z_bytes_t, bytes, _z_bytes_copy, _z_bytes_free) +#if Z_FEATURE_PUBLICATION == 1 || Z_FEATURE_QUERYABLE == 1 || Z_FEATURE_QUERY == 1 +// Convert a user owned bytes payload to an internal bytes payload, returning an empty one if value invalid static _z_bytes_t _z_bytes_from_owned_bytes(z_owned_bytes_t *bytes) { _z_bytes_t b = _z_bytes_null(); if ((bytes != NULL) && (bytes->_val != NULL)) { @@ -708,6 +698,18 @@ static _z_bytes_t _z_bytes_from_owned_bytes(z_owned_bytes_t *bytes) { return b; } +// Convert a user owned encoding to an internal encoding, return default encoding if value invalid +static _z_encoding_t _z_encoding_from_owned(const z_owned_encoding_t *encoding) { + if (encoding == NULL) { + return _z_encoding_null(); + } + if (encoding->_val == NULL) { + return _z_encoding_null(); + } + return *encoding->_val; +} +#endif + _Z_OWNED_FUNCTIONS_RC_IMPL(sample) _Z_OWNED_FUNCTIONS_RC_IMPL(session) @@ -763,7 +765,7 @@ int8_t z_scout(z_owned_scouting_config_t *config, z_owned_closure_hello_t *callb if (opt_as_str == NULL) { opt_as_str = (char *)Z_CONFIG_SCOUTING_TIMEOUT_DEFAULT; } - uint32_t timeout = strtoul(opt_as_str, NULL, 10); + uint32_t timeout = (uint32_t)strtoul(opt_as_str, NULL, 10); _z_id_t zid = _z_id_empty(); char *zid_str = _z_config_get(config->_val, Z_CONFIG_SESSION_ZID_KEY); @@ -1243,7 +1245,7 @@ int8_t z_declare_subscriber(z_owned_subscriber_t *sub, const z_loaned_session_t _z_keyexpr_t resource_key = *keyexpr; if (wild != NULL && wild != resource_key._suffix) { wild -= 1; - size_t len = wild - resource_key._suffix; + size_t len = (size_t)(wild - resource_key._suffix); suffix = z_malloc(len + 1); if (suffix != NULL) { memcpy(suffix, resource_key._suffix, len); diff --git a/src/collections/fifo.c b/src/collections/fifo.c index 463c7f9db..914cf2752 100644 --- a/src/collections/fifo.c +++ b/src/collections/fifo.c @@ -47,7 +47,7 @@ void _z_fifo_free(_z_fifo_t **r, z_element_free_f free_f) { _z_fifo_t *ptr = (_z_fifo_t *)*r; if (ptr != NULL) { _z_fifo_clear(ptr, free_f); - zp_free(ptr); + z_free(ptr); *r = NULL; } } diff --git a/src/collections/fifo_mt.c b/src/collections/fifo_mt.c index d41a6675d..072fd6cc2 100644 --- a/src/collections/fifo_mt.c +++ b/src/collections/fifo_mt.c @@ -23,25 +23,25 @@ int8_t _z_fifo_mt_init(_z_fifo_mt_t *fifo, size_t capacity) { _Z_RETURN_IF_ERR(_z_fifo_init(&fifo->_fifo, capacity)) #if Z_FEATURE_MULTI_THREAD == 1 - _Z_RETURN_IF_ERR(zp_mutex_init(&fifo->_mutex)) - _Z_RETURN_IF_ERR(zp_condvar_init(&fifo->_cv_not_full)) - _Z_RETURN_IF_ERR(zp_condvar_init(&fifo->_cv_not_empty)) + _Z_RETURN_IF_ERR(z_mutex_init(&fifo->_mutex)) + _Z_RETURN_IF_ERR(z_condvar_init(&fifo->_cv_not_full)) + _Z_RETURN_IF_ERR(z_condvar_init(&fifo->_cv_not_empty)) #endif return _Z_RES_OK; } _z_fifo_mt_t *_z_fifo_mt_new(size_t capacity) { - _z_fifo_mt_t *fifo = (_z_fifo_mt_t *)zp_malloc(sizeof(_z_fifo_mt_t)); + _z_fifo_mt_t *fifo = (_z_fifo_mt_t *)z_malloc(sizeof(_z_fifo_mt_t)); if (fifo == NULL) { - _Z_ERROR("zp_malloc failed"); + _Z_ERROR("z_malloc failed"); return NULL; } int8_t ret = _z_fifo_mt_init(fifo, capacity); if (ret != _Z_RES_OK) { _Z_ERROR("_z_fifo_mt_init failed: %i", ret); - zp_free(fifo); + z_free(fifo); return NULL; } @@ -50,9 +50,9 @@ _z_fifo_mt_t *_z_fifo_mt_new(size_t capacity) { void _z_fifo_mt_clear(_z_fifo_mt_t *fifo, z_element_free_f free_f) { #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_free(&fifo->_mutex); - zp_condvar_free(&fifo->_cv_not_full); - zp_condvar_free(&fifo->_cv_not_empty); + z_mutex_free(&fifo->_mutex); + z_condvar_free(&fifo->_cv_not_full); + z_condvar_free(&fifo->_cv_not_empty); #endif _z_fifo_clear(&fifo->_fifo, free_f); @@ -60,10 +60,11 @@ void _z_fifo_mt_clear(_z_fifo_mt_t *fifo, z_element_free_f free_f) { void _z_fifo_mt_free(_z_fifo_mt_t *fifo, z_element_free_f free_f) { _z_fifo_mt_clear(fifo, free_f); - zp_free(fifo); + z_free(fifo); } int8_t _z_fifo_mt_push(const void *elem, void *context, z_element_free_f element_free) { + _ZP_UNUSED(element_free); if (elem == NULL || context == NULL) { return _Z_ERR_GENERIC; } @@ -71,16 +72,16 @@ int8_t _z_fifo_mt_push(const void *elem, void *context, z_element_free_f element _z_fifo_mt_t *f = (_z_fifo_mt_t *)context; #if Z_FEATURE_MULTI_THREAD == 1 - _Z_RETURN_IF_ERR(zp_mutex_lock(&f->_mutex)) + _Z_RETURN_IF_ERR(z_mutex_lock(&f->_mutex)) while (elem != NULL) { elem = _z_fifo_push(&f->_fifo, (void *)elem); if (elem != NULL) { - _Z_RETURN_IF_ERR(zp_condvar_wait(&f->_cv_not_full, &f->_mutex)) + _Z_RETURN_IF_ERR(z_condvar_wait(&f->_cv_not_full, &f->_mutex)) } else { - _Z_RETURN_IF_ERR(zp_condvar_signal(&f->_cv_not_empty)) + _Z_RETURN_IF_ERR(z_condvar_signal(&f->_cv_not_empty)) } } - _Z_RETURN_IF_ERR(zp_mutex_unlock(&f->_mutex)) + _Z_RETURN_IF_ERR(z_mutex_unlock(&f->_mutex)) #else // Z_FEATURE_MULTI_THREAD == 1 _z_fifo_push_drop(&f->_fifo, (void *)elem, element_free); #endif // Z_FEATURE_MULTI_THREAD == 1 @@ -93,16 +94,16 @@ int8_t _z_fifo_mt_pull(void *dst, void *context, z_element_move_f element_move) #if Z_FEATURE_MULTI_THREAD == 1 void *src = NULL; - _Z_RETURN_IF_ERR(zp_mutex_lock(&f->_mutex)) + _Z_RETURN_IF_ERR(z_mutex_lock(&f->_mutex)) while (src == NULL) { src = _z_fifo_pull(&f->_fifo); if (src == NULL) { - _Z_RETURN_IF_ERR(zp_condvar_wait(&f->_cv_not_empty, &f->_mutex)) + _Z_RETURN_IF_ERR(z_condvar_wait(&f->_cv_not_empty, &f->_mutex)) } else { - _Z_RETURN_IF_ERR(zp_condvar_signal(&f->_cv_not_full)) + _Z_RETURN_IF_ERR(z_condvar_signal(&f->_cv_not_full)) } } - _Z_RETURN_IF_ERR(zp_mutex_unlock(&f->_mutex)) + _Z_RETURN_IF_ERR(z_mutex_unlock(&f->_mutex)) element_move(dst, src); #else // Z_FEATURE_MULTI_THREAD == 1 void *src = _z_fifo_pull(&f->_fifo); @@ -119,12 +120,12 @@ int8_t _z_fifo_mt_try_pull(void *dst, void *context, z_element_move_f element_mo #if Z_FEATURE_MULTI_THREAD == 1 void *src = NULL; - _Z_RETURN_IF_ERR(zp_mutex_lock(&f->_mutex)) + _Z_RETURN_IF_ERR(z_mutex_lock(&f->_mutex)) src = _z_fifo_pull(&f->_fifo); if (src != NULL) { - _Z_RETURN_IF_ERR(zp_condvar_signal(&f->_cv_not_full)) + _Z_RETURN_IF_ERR(z_condvar_signal(&f->_cv_not_full)) } - _Z_RETURN_IF_ERR(zp_mutex_unlock(&f->_mutex)) + _Z_RETURN_IF_ERR(z_mutex_unlock(&f->_mutex)) #else // Z_FEATURE_MULTI_THREAD == 1 void *src = _z_fifo_pull(&f->_fifo); #endif // Z_FEATURE_MULTI_THREAD == 1 diff --git a/src/collections/lifo.c b/src/collections/lifo.c index 6cccca8fa..4f31a22cf 100644 --- a/src/collections/lifo.c +++ b/src/collections/lifo.c @@ -21,7 +21,7 @@ int8_t _z_lifo_init(_z_lifo_t *r, size_t capacity) { memset(r, 0, sizeof(_z_lifo_t)); if (capacity != (size_t)0) { - r->_val = (void **)zp_malloc(sizeof(void *) * capacity); + r->_val = (void **)z_malloc(sizeof(void *) * capacity); } if (r->_val != NULL) { memset(r->_val, 0, capacity); @@ -73,7 +73,7 @@ void _z_lifo_clear(_z_lifo_t *r, z_element_free_f free_f) { free_f(&e); e = _z_lifo_pull(r); } - zp_free(r->_val); + z_free(r->_val); r->_val = NULL; r->_capacity = (size_t)0; @@ -84,7 +84,7 @@ void _z_lifo_free(_z_lifo_t **r, z_element_free_f free_f) { _z_lifo_t *ptr = (_z_lifo_t *)*r; if (ptr != NULL) { _z_lifo_clear(ptr, free_f); - zp_free(ptr); + z_free(ptr); *r = NULL; } } diff --git a/src/collections/ring.c b/src/collections/ring.c index ce3e90894..66adb6c89 100644 --- a/src/collections/ring.c +++ b/src/collections/ring.c @@ -25,7 +25,7 @@ int8_t _z_ring_init(_z_ring_t *r, size_t capacity) { memset(r, 0, sizeof(_z_ring_t)); if (capacity != (size_t)0) { - r->_val = (void **)zp_malloc(sizeof(void *) * capacity); + r->_val = (void **)z_malloc(sizeof(void *) * capacity); } if (r->_val != NULL) { memset(r->_val, 0, capacity); @@ -96,7 +96,7 @@ void _z_ring_clear(_z_ring_t *r, z_element_free_f free_f) { free_f(&e); e = _z_ring_pull(r); } - zp_free(r->_val); + z_free(r->_val); r->_val = NULL; r->_capacity = (size_t)0; @@ -109,7 +109,7 @@ void _z_ring_free(_z_ring_t **r, z_element_free_f free_f) { _z_ring_t *ptr = (_z_ring_t *)*r; if (ptr != NULL) { _z_ring_clear(ptr, free_f); - zp_free(ptr); + z_free(ptr); *r = NULL; } } diff --git a/src/collections/ring_mt.c b/src/collections/ring_mt.c index f28c432c9..c3b68953f 100644 --- a/src/collections/ring_mt.c +++ b/src/collections/ring_mt.c @@ -23,16 +23,16 @@ int8_t _z_ring_mt_init(_z_ring_mt_t *ring, size_t capacity) { _Z_RETURN_IF_ERR(_z_ring_init(&ring->_ring, capacity)) #if Z_FEATURE_MULTI_THREAD == 1 - _Z_RETURN_IF_ERR(zp_mutex_init(&ring->_mutex)) - _Z_RETURN_IF_ERR(zp_condvar_init(&ring->_cv_not_empty)) + _Z_RETURN_IF_ERR(z_mutex_init(&ring->_mutex)) + _Z_RETURN_IF_ERR(z_condvar_init(&ring->_cv_not_empty)) #endif return _Z_RES_OK; } _z_ring_mt_t *_z_ring_mt_new(size_t capacity) { - _z_ring_mt_t *ring = (_z_ring_mt_t *)zp_malloc(sizeof(_z_ring_mt_t)); + _z_ring_mt_t *ring = (_z_ring_mt_t *)z_malloc(sizeof(_z_ring_mt_t)); if (ring == NULL) { - _Z_ERROR("zp_malloc failed"); + _Z_ERROR("z_malloc failed"); return NULL; } @@ -47,8 +47,8 @@ _z_ring_mt_t *_z_ring_mt_new(size_t capacity) { void _z_ring_mt_clear(_z_ring_mt_t *ring, z_element_free_f free_f) { #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_free(&ring->_mutex); - zp_condvar_free(&ring->_cv_not_empty); + z_mutex_free(&ring->_mutex); + z_condvar_free(&ring->_cv_not_empty); #endif _z_ring_clear(&ring->_ring, free_f); @@ -57,7 +57,7 @@ void _z_ring_mt_clear(_z_ring_mt_t *ring, z_element_free_f free_f) { void _z_ring_mt_free(_z_ring_mt_t *ring, z_element_free_f free_f) { _z_ring_mt_clear(ring, free_f); - zp_free(ring); + z_free(ring); } int8_t _z_ring_mt_push(const void *elem, void *context, z_element_free_f element_free) { @@ -68,14 +68,14 @@ int8_t _z_ring_mt_push(const void *elem, void *context, z_element_free_f element _z_ring_mt_t *r = (_z_ring_mt_t *)context; #if Z_FEATURE_MULTI_THREAD == 1 - _Z_RETURN_IF_ERR(zp_mutex_lock(&r->_mutex)) + _Z_RETURN_IF_ERR(z_mutex_lock(&r->_mutex)) #endif _z_ring_push_force_drop(&r->_ring, (void *)elem, element_free); #if Z_FEATURE_MULTI_THREAD == 1 - _Z_RETURN_IF_ERR(zp_condvar_signal(&r->_cv_not_empty)) - _Z_RETURN_IF_ERR(zp_mutex_unlock(&r->_mutex)) + _Z_RETURN_IF_ERR(z_condvar_signal(&r->_cv_not_empty)) + _Z_RETURN_IF_ERR(z_mutex_unlock(&r->_mutex)) #endif return _Z_RES_OK; } @@ -85,14 +85,14 @@ int8_t _z_ring_mt_pull(void *dst, void *context, z_element_move_f element_move) #if Z_FEATURE_MULTI_THREAD == 1 void *src = NULL; - _Z_RETURN_IF_ERR(zp_mutex_lock(&r->_mutex)) + _Z_RETURN_IF_ERR(z_mutex_lock(&r->_mutex)) while (src == NULL) { src = _z_ring_pull(&r->_ring); if (src == NULL) { - _Z_RETURN_IF_ERR(zp_condvar_wait(&r->_cv_not_empty, &r->_mutex)) + _Z_RETURN_IF_ERR(z_condvar_wait(&r->_cv_not_empty, &r->_mutex)) } } - _Z_RETURN_IF_ERR(zp_mutex_unlock(&r->_mutex)) + _Z_RETURN_IF_ERR(z_mutex_unlock(&r->_mutex)) element_move(dst, src); #else // Z_FEATURE_MULTI_THREAD == 1 void *src = _z_ring_pull(&r->_ring); @@ -108,13 +108,13 @@ int8_t _z_ring_mt_try_pull(void *dst, void *context, z_element_move_f element_mo _z_ring_mt_t *r = (_z_ring_mt_t *)context; #if Z_FEATURE_MULTI_THREAD == 1 - _Z_RETURN_IF_ERR(zp_mutex_lock(&r->_mutex)) + _Z_RETURN_IF_ERR(z_mutex_lock(&r->_mutex)) #endif void *src = _z_ring_pull(&r->_ring); #if Z_FEATURE_MULTI_THREAD == 1 - _Z_RETURN_IF_ERR(zp_mutex_unlock(&r->_mutex)) + _Z_RETURN_IF_ERR(z_mutex_unlock(&r->_mutex)) #endif if (src != NULL) { diff --git a/src/collections/slice.c b/src/collections/slice.c index 59668747e..879c139b4 100644 --- a/src/collections/slice.c +++ b/src/collections/slice.c @@ -268,4 +268,4 @@ _z_bytes_t _z_bytes_from_double(double val) { // Encode double memcpy((uint8_t *)ret._slice.start, &val, sizeof(val)); return ret; -} \ No newline at end of file +} diff --git a/src/deprecated/platform.c b/src/deprecated/platform.c deleted file mode 100644 index 4081d5b1e..000000000 --- a/src/deprecated/platform.c +++ /dev/null @@ -1,63 +0,0 @@ -// -// Copyright (c) 2024 ZettaScale Technology -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License 2.0 which is available at -// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// -// Contributors: -// ZettaScale Zenoh Team, -// - -#include "zenoh-pico/deprecated/platform.h" - -#include "zenoh-pico/system/platform-common.h" - -uint8_t zp_random_u8(void) { return z_random_u8(); }; -uint16_t zp_random_u16(void) { return z_random_u16(); }; -uint32_t zp_random_u32(void) { return z_random_u32(); }; -uint64_t zp_random_u64(void) { return z_random_u64(); }; -void zp_random_fill(void *buf, size_t len) { return z_random_fill(buf, len); }; - -void *zp_malloc(size_t size) { return z_malloc(size); }; -void *zp_realloc(void *ptr, size_t size) { return z_realloc(ptr, size); }; -void zp_free(void *ptr) { return z_free(ptr); }; - -#if Z_FEATURE_MULTI_THREAD == 1 - -int8_t zp_task_init(zp_task_t *task, zp_task_attr_t *attr, void *(*fun)(void *), void *arg) { - return z_task_init(task, attr, fun, arg); -}; -int8_t zp_task_join(zp_task_t *task) { return z_task_join(task); }; -void zp_task_free(zp_task_t **task) { return z_task_free(task); }; - -int8_t zp_mutex_init(zp_mutex_t *m) { return z_mutex_init(m); }; -int8_t zp_mutex_free(zp_mutex_t *m) { return z_mutex_free(m); }; -int8_t zp_mutex_lock(zp_mutex_t *m) { return z_mutex_lock(m); }; -int8_t zp_mutex_trylock(zp_mutex_t *m) { return z_mutex_trylock(m); }; -int8_t zp_mutex_unlock(zp_mutex_t *m) { return z_mutex_unlock(m); }; - -int8_t zp_condvar_init(zp_condvar_t *cv) { return z_condvar_init(cv); }; -int8_t zp_condvar_free(zp_condvar_t *cv) { return z_condvar_free(cv); }; - -int8_t zp_condvar_signal(zp_condvar_t *cv) { return z_condvar_signal(cv); }; -int8_t zp_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { return z_condvar_wait(cv, m); }; -#endif // Z_FEATURE_MULTI_THREAD == 1 - -int zp_sleep_us(size_t time) { return z_sleep_us(time); }; -int zp_sleep_ms(size_t time) { return z_sleep_ms(time); }; -int zp_sleep_s(size_t time) { return z_sleep_s(time); }; - -zp_clock_t zp_clock_now(void) { return z_clock_now(); }; -unsigned long zp_clock_elapsed_us(zp_clock_t *time) { return z_clock_elapsed_us(time); }; -unsigned long zp_clock_elapsed_ms(zp_clock_t *time) { return z_clock_elapsed_ms(time); }; -unsigned long zp_clock_elapsed_s(zp_clock_t *time) { return z_clock_elapsed_s(time); }; - -zp_time_t zp_time_now(void) { return z_time_now(); }; -const char *zp_time_now_as_str(char *const buf, unsigned long buflen) { return z_time_now_as_str(buf, buflen); }; -unsigned long zp_time_elapsed_us(zp_time_t *time) { return z_time_elapsed_us(time); }; -unsigned long zp_time_elapsed_ms(zp_time_t *time) { return z_time_elapsed_ms(time); }; -unsigned long zp_time_elapsed_s(zp_time_t *time) { return z_time_elapsed_s(time); }; diff --git a/src/link/config/ws.c b/src/link/config/ws.c index 14e4c113c..dd4378e6a 100644 --- a/src/link/config/ws.c +++ b/src/link/config/ws.c @@ -28,8 +28,7 @@ size_t _z_ws_config_strlen(const _z_str_intmap_t *s) { void _z_ws_config_onto_str(char *dst, size_t dst_len, const _z_str_intmap_t *s) { WS_CONFIG_MAPPING_BUILD - - return _z_str_intmap_onto_str(dst, dst_len, s, argc, args); + _z_str_intmap_onto_str(dst, dst_len, s, argc, args); } char *_z_ws_config_to_str(const _z_str_intmap_t *s) { diff --git a/src/link/multicast/udp.c b/src/link/multicast/udp.c index 0e08eff58..ef1aab5ca 100644 --- a/src/link/multicast/udp.c +++ b/src/link/multicast/udp.c @@ -93,7 +93,7 @@ int8_t _z_endpoint_udp_multicast_valid(_z_endpoint_t *endpoint) { if (s_port == NULL) { ret = _Z_ERR_CONFIG_LOCATOR_INVALID; } else { - uint32_t port = strtoul(s_port, NULL, 10); + uint32_t port = (uint32_t)strtoul(s_port, NULL, 10); if ((port < (uint32_t)1) || (port > (uint32_t)65355)) { // Port numbers should range from 1 to 65355 ret = _Z_ERR_CONFIG_LOCATOR_INVALID; } @@ -115,7 +115,7 @@ int8_t _z_f_link_open_udp_multicast(_z_link_t *self) { uint32_t tout = Z_CONFIG_SOCKET_TIMEOUT; char *tout_as_str = _z_str_intmap_get(&self->_endpoint._config, UDP_CONFIG_TOUT_KEY); if (tout_as_str != NULL) { - tout = strtoul(tout_as_str, NULL, 10); + tout = (uint32_t)strtoul(tout_as_str, NULL, 10); } const char *iface = _z_str_intmap_get(&self->_endpoint._config, UDP_CONFIG_IFACE_KEY); diff --git a/src/link/unicast/tcp.c b/src/link/unicast/tcp.c index fe006cdc8..c1b54becf 100644 --- a/src/link/unicast/tcp.c +++ b/src/link/unicast/tcp.c @@ -93,7 +93,7 @@ int8_t _z_endpoint_tcp_valid(_z_endpoint_t *endpoint) { if (s_port == NULL) { ret = _Z_ERR_CONFIG_LOCATOR_INVALID; } else { - uint32_t port = strtoul(s_port, NULL, 10); + uint32_t port = (uint32_t)strtoul(s_port, NULL, 10); if ((port < (uint32_t)1) || (port > (uint32_t)65355)) { // Port numbers should range from 1 to 65355 ret = _Z_ERR_CONFIG_LOCATOR_INVALID; } @@ -110,7 +110,7 @@ int8_t _z_f_link_open_tcp(_z_link_t *zl) { uint32_t tout = Z_CONFIG_SOCKET_TIMEOUT; char *tout_as_str = _z_str_intmap_get(&zl->_endpoint._config, TCP_CONFIG_TOUT_KEY); if (tout_as_str != NULL) { - tout = strtoul(tout_as_str, NULL, 10); + tout = (uint32_t)strtoul(tout_as_str, NULL, 10); } ret = _z_open_tcp(&zl->_socket._tcp._sock, zl->_socket._tcp._rep, tout); diff --git a/src/link/unicast/udp.c b/src/link/unicast/udp.c index b76b832e6..d30418727 100644 --- a/src/link/unicast/udp.c +++ b/src/link/unicast/udp.c @@ -93,7 +93,7 @@ int8_t _z_endpoint_udp_unicast_valid(_z_endpoint_t *endpoint) { if (s_port == NULL) { ret = _Z_ERR_CONFIG_LOCATOR_INVALID; } else { - uint32_t port = strtoul(s_port, NULL, 10); + uint32_t port = (uint32_t)strtoul(s_port, NULL, 10); if ((port < (uint32_t)1) || (port > (uint32_t)65355)) { // Port numbers should range from 1 to 65355 ret = _Z_ERR_CONFIG_LOCATOR_INVALID; } @@ -110,7 +110,7 @@ int8_t _z_f_link_open_udp_unicast(_z_link_t *self) { uint32_t tout = Z_CONFIG_SOCKET_TIMEOUT; char *tout_as_str = _z_str_intmap_get(&self->_endpoint._config, UDP_CONFIG_TOUT_KEY); if (tout_as_str != NULL) { - tout = strtoul(tout_as_str, NULL, 10); + tout = (uint32_t)strtoul(tout_as_str, NULL, 10); } ret = _z_open_udp_unicast(&self->_socket._udp._sock, self->_socket._udp._rep, tout); @@ -124,7 +124,7 @@ int8_t _z_f_link_listen_udp_unicast(_z_link_t *self) { uint32_t tout = Z_CONFIG_SOCKET_TIMEOUT; char *tout_as_str = _z_str_intmap_get(&self->_endpoint._config, UDP_CONFIG_TOUT_KEY); if (tout_as_str != NULL) { - tout = strtoul(tout_as_str, NULL, 10); + tout = (uint32_t)strtoul(tout_as_str, NULL, 10); } ret = _z_listen_udp_unicast(&self->_socket._udp._sock, self->_socket._udp._rep, tout); diff --git a/src/net/encoding.c b/src/net/encoding.c index 782d3dc3a..406d10437 100644 --- a/src/net/encoding.c +++ b/src/net/encoding.c @@ -41,7 +41,7 @@ _z_encoding_t _z_encoding_wrap(z_encoding_id_t id, const char *schema) { _z_encoding_t _z_encoding_null(void) { return _z_encoding_wrap(Z_ENCODING_ID_DEFAULT, NULL); } -void _z_encoding_clear(_z_encoding_t *encoding) { _z_slice_clear(&encoding->schema); }; +void _z_encoding_clear(_z_encoding_t *encoding) { _z_slice_clear(&encoding->schema); } _Bool _z_encoding_check(const _z_encoding_t *encoding) { return ((encoding->id != Z_ENCODING_ID_DEFAULT) || _z_slice_check(encoding->schema)); diff --git a/src/net/primitives.c b/src/net/primitives.c index 35476ccf0..f50cbd611 100644 --- a/src/net/primitives.c +++ b/src/net/primitives.c @@ -58,8 +58,8 @@ void _z_scout(const z_what_t what, const _z_id_t zid, const char *locator, const uint16_t _z_declare_resource(_z_session_t *zn, _z_keyexpr_t keyexpr) { uint16_t ret = Z_RESOURCE_ID_NONE; - if (zn->_tp._type == - _Z_TRANSPORT_UNICAST_TYPE) { // FIXME: remove when resource declaration is implemented for multicast transport + // FIXME: remove this check when resource declaration is implemented for multicast transport + if (zn->_tp._type == _Z_TRANSPORT_UNICAST_TYPE) { uint16_t id = _z_register_resource(zn, keyexpr, 0, _Z_KEYEXPR_MAPPING_LOCAL); if (id != 0) { // Build the declare message to send on the wire diff --git a/src/net/sample.c b/src/net/sample.c index 7ceca0f2f..9db7355e3 100644 --- a/src/net/sample.c +++ b/src/net/sample.c @@ -88,7 +88,7 @@ _z_sample_t _z_sample_create(const _z_keyexpr_t *key, const _z_slice_t *payload, s.kind = kind; s.timestamp = timestamp; s.qos = qos; - s.attachment = _z_bytes_duplicate(&att); + s.attachment._slice = _z_slice_steal((_z_slice_t *)&att._slice); return s; } #else diff --git a/src/net/session.c b/src/net/session.c index 0300584d2..373485da1 100644 --- a/src/net/session.c +++ b/src/net/session.c @@ -85,7 +85,7 @@ int8_t _z_open(_z_session_t *zn, _z_config_t *config) { if (opt_as_str == NULL) { opt_as_str = (char *)Z_CONFIG_SCOUTING_TIMEOUT_DEFAULT; } - uint32_t timeout = strtoul(opt_as_str, NULL, 10); + uint32_t timeout = (uint32_t)strtoul(opt_as_str, NULL, 10); // Scout and return upon the first result _z_hello_list_t *hellos = _z_scout_inner(what, zid, mcast_locator, timeout, true); @@ -95,7 +95,7 @@ int8_t _z_open(_z_session_t *zn, _z_config_t *config) { } _z_hello_list_free(&hellos); } else { - int key = Z_CONFIG_CONNECT_KEY; + uint_fast8_t key = Z_CONFIG_CONNECT_KEY; if (listen != NULL) { if (connect == NULL) { key = Z_CONFIG_LISTEN_KEY; diff --git a/src/protocol/codec.c b/src/protocol/codec.c index 9ad0b9f2c..36aff6bc9 100644 --- a/src/protocol/codec.c +++ b/src/protocol/codec.c @@ -76,8 +76,8 @@ int8_t _z_uint8_decode(uint8_t *u8, _z_zbuf_t *zbf) { int8_t _z_uint16_encode(_z_wbuf_t *wbf, uint16_t u16) { int8_t ret = _Z_RES_OK; - ret |= _z_wbuf_write(wbf, (u16 & 0xFF)); - ret |= _z_wbuf_write(wbf, ((u16 >> 8) & 0xFF)); + ret |= _z_wbuf_write(wbf, (u16 & 0xFFU)); + ret |= _z_wbuf_write(wbf, ((u16 >> 8) & 0xFFU)); return ret; } diff --git a/src/protocol/codec/declarations.c b/src/protocol/codec/declarations.c index aec401587..fb11ef461 100644 --- a/src/protocol/codec/declarations.c +++ b/src/protocol/codec/declarations.c @@ -323,6 +323,8 @@ int8_t _z_undecl_token_decode(_z_undecl_token_t *decl, _z_zbuf_t *zbf, uint8_t h } int8_t _z_decl_final_decode(_z_decl_final_t *decl, _z_zbuf_t *zbf, uint8_t header) { + // Nothing to do + _ZP_UNUSED(decl); if (_Z_HAS_FLAG(header, _Z_FLAG_Z_Z)) { _Z_RETURN_IF_ERR(_z_msg_ext_skip_non_mandatories(zbf, 0x13)); } diff --git a/src/protocol/codec/message.c b/src/protocol/codec/message.c index 592323756..139395e2a 100644 --- a/src/protocol/codec/message.c +++ b/src/protocol/codec/message.c @@ -93,7 +93,9 @@ int8_t _z_timestamp_encode(_z_wbuf_t *wbf, const _z_timestamp_t *ts) { return ret; } int8_t _z_timestamp_encode_ext(_z_wbuf_t *wbf, const _z_timestamp_t *ts) { - _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, _z_zint_len(ts->time) + (uint8_t)1 + _z_id_len(ts->id))); + // Encode extension size then timestamp + size_t ext_size = (size_t)(_z_zint_len(ts->time) + 1 + _z_id_len(ts->id)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, ext_size)); return _z_timestamp_encode(wbf, ts); } @@ -233,8 +235,8 @@ int8_t _z_source_info_encode(_z_wbuf_t *wbf, const _z_source_info_t *info) { int8_t _z_source_info_encode_ext(_z_wbuf_t *wbf, const _z_source_info_t *info) { int8_t ret = 0; uint8_t zidlen = _z_id_len(info->_id); - uint16_t len = 1 + zidlen + _z_zint_len(info->_entity_id) + _z_zint_len(info->_source_sn); - _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, len)); + size_t ext_size = 1u + zidlen + _z_zint_len(info->_entity_id) + _z_zint_len(info->_source_sn); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, ext_size)); _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, zidlen << 4)); _z_slice_t zid = _z_slice_wrap(info->_id.id, zidlen); _Z_RETURN_IF_ERR(_z_slice_val_encode(wbf, &zid)); @@ -497,6 +499,7 @@ int8_t _z_reply_encode(_z_wbuf_t *wbf, const _z_msg_reply_t *reply) { return _Z_RES_OK; } int8_t _z_reply_decode_extension(_z_msg_ext_t *extension, void *ctx) { + _ZP_UNUSED(ctx); int8_t ret = _Z_RES_OK; switch (_Z_EXT_FULL_ID(extension->_header)) { default: @@ -595,7 +598,7 @@ int8_t _z_scout_encode(_z_wbuf_t *wbf, uint8_t header, const _z_s_msg_scout_t *m uint8_t zid_len = _z_id_len(msg->_zid); if (zid_len > 0) { _Z_SET_FLAG(cbyte, _Z_FLAG_T_SCOUT_I); - cbyte |= ((zid_len - 1) & 0x0F) << 4; + cbyte |= (uint8_t)(((zid_len - 1) & 0x0F) << 4); } _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, cbyte)) @@ -633,7 +636,7 @@ int8_t _z_hello_encode(_z_wbuf_t *wbf, uint8_t header, const _z_s_msg_hello_t *m uint8_t zidlen = _z_id_len(msg->_zid); uint8_t cbyte = 0; cbyte |= (msg->_whatami & 0x03); - cbyte |= ((zidlen - 1) & 0x0F) << 4; + cbyte |= (uint8_t)(((zidlen - 1) & 0x0F) << 4); _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, cbyte)) _Z_RETURN_IF_ERR(_z_slice_val_encode(wbf, &(_z_slice_t){.start = msg->_zid.id, .len = zidlen, ._is_alloc = false})); diff --git a/src/protocol/codec/network.c b/src/protocol/codec/network.c index a676cb595..efee7bcfc 100644 --- a/src/protocol/codec/network.c +++ b/src/protocol/codec/network.c @@ -75,7 +75,7 @@ int8_t _z_push_decode_ext_cb(_z_msg_ext_t *extension, void *ctx) { if (extension->_body._zint._val > UINT32_MAX) { return _Z_ERR_MESSAGE_DESERIALIZATION_FAILED; } - msg->_qos = (_z_n_qos_t){._val = (uint32_t)extension->_body._zint._val}; + msg->_qos = (_z_n_qos_t){._val = (uint8_t)extension->_body._zint._val}; break; } case _Z_MSG_EXT_ENC_ZBUF | 0x02: { // Timestamp ext @@ -246,7 +246,7 @@ int8_t _z_response_encode(_z_wbuf_t *wbf, const _z_n_msg_response_t *msg) { _Bool has_qos_ext = msg->_ext_qos._val != _Z_N_QOS_DEFAULT._val; _Bool has_ts_ext = _z_timestamp_check(&msg->_ext_timestamp); _Bool has_responder_ext = _z_id_check(msg->_ext_responder._zid) || msg->_ext_responder._eid != 0; - uint8_t n_ext = (has_qos_ext ? 1 : 0) + (has_ts_ext ? 1 : 0) + (has_responder_ext ? 1 : 0); + int n_ext = (has_qos_ext ? 1 : 0) + (has_ts_ext ? 1 : 0) + (has_responder_ext ? 1 : 0); _Bool has_suffix = _z_keyexpr_has_suffix(msg->_key); if (_z_keyexpr_is_local(&msg->_key)) { _Z_SET_FLAG(header, _Z_FLAG_N_RESPONSE_M); @@ -284,8 +284,9 @@ int8_t _z_response_encode(_z_wbuf_t *wbf, const _z_n_msg_response_t *msg) { uint8_t extheader = _Z_MSG_EXT_ENC_ZBUF | 0x03 | (n_ext != 0 ? _Z_FLAG_Z_Z : 0); _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, extheader)); uint8_t zidlen = _z_id_len(msg->_ext_responder._zid); - extheader = (zidlen - 1) << 4; - _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, zidlen + (uint8_t)1 + _z_zint_len(msg->_ext_responder._eid))); + extheader = (uint8_t)((zidlen - 1) << 4); + size_t ext_size = (size_t)(zidlen + 1 + _z_zint_len(msg->_ext_responder._eid)); + _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, ext_size)); _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, extheader)); _Z_RETURN_IF_ERR(_z_wbuf_write_bytes(wbf, msg->_ext_responder._zid.id, 0, zidlen)); _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, msg->_ext_responder._eid)); @@ -397,8 +398,8 @@ int8_t _z_declare_encode(_z_wbuf_t *wbf, const _z_n_msg_declare_t *decl) { uint8_t header = _Z_MID_N_DECLARE; _Bool has_qos_ext = decl->_ext_qos._val != _Z_N_QOS_DEFAULT._val; _Bool has_timestamp_ext = _z_timestamp_check(&decl->_ext_timestamp); - uint8_t n = (has_qos_ext ? 1 : 0) + (has_timestamp_ext ? 1 : 0); - if (n != 0) { + int n_ext = (has_qos_ext ? 1 : 0) + (has_timestamp_ext ? 1 : 0); + if (n_ext != 0) { header |= _Z_FLAG_N_Z; } if (decl->has_interest_id) { @@ -412,13 +413,13 @@ int8_t _z_declare_encode(_z_wbuf_t *wbf, const _z_n_msg_declare_t *decl) { } // Encode extensions if (has_qos_ext) { - n -= 1; - _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, 0x01 | _Z_MSG_EXT_ENC_ZINT | (n != 0 ? _Z_FLAG_Z_Z : 0))); + n_ext -= 1; + _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, 0x01 | _Z_MSG_EXT_ENC_ZINT | (n_ext != 0 ? _Z_FLAG_Z_Z : 0))); _Z_RETURN_IF_ERR(_z_zsize_encode(wbf, decl->_ext_qos._val)); } if (has_timestamp_ext) { - n -= 1; - _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, 0x02 | _Z_MSG_EXT_ENC_ZBUF | (n != 0 ? _Z_FLAG_Z_Z : 0))); + n_ext -= 1; + _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, 0x02 | _Z_MSG_EXT_ENC_ZBUF | (n_ext != 0 ? _Z_FLAG_Z_Z : 0))); _Z_RETURN_IF_ERR(_z_timestamp_encode_ext(wbf, &decl->_ext_timestamp)); } // Encode declaration diff --git a/src/protocol/codec/transport.c b/src/protocol/codec/transport.c index 00cacad9c..5e3b455ce 100644 --- a/src/protocol/codec/transport.c +++ b/src/protocol/codec/transport.c @@ -37,12 +37,12 @@ int8_t _z_join_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_join_t *msg uint8_t cbyte = 0; cbyte |= (msg->_whatami & 0x03); uint8_t zidlen = _z_id_len(msg->_zid); - cbyte |= ((zidlen - 1) & 0x0F) << 4; + cbyte |= (uint8_t)(((zidlen - 1) & 0x0F) << 4); _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, cbyte)); _Z_RETURN_IF_ERR(_z_wbuf_write_bytes(wbf, msg->_zid.id, 0, zidlen)); if (_Z_HAS_FLAG(header, _Z_FLAG_T_JOIN_S)) { - uint8_t cbyte = 0; + cbyte = 0; cbyte |= (msg->_seq_num_res & 0x03); cbyte |= ((msg->_req_id_res & 0x03) << 2); _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, cbyte)); @@ -155,7 +155,7 @@ int8_t _z_init_encode(_z_wbuf_t *wbf, uint8_t header, const _z_t_msg_init_t *msg uint8_t cbyte = 0; cbyte |= (msg->_whatami & 0x03); uint8_t zidlen = _z_id_len(msg->_zid); - cbyte |= ((zidlen - 1) & 0x0F) << 4; // TODO[protocol]: check if ZID > 0 && <= 16 + cbyte |= (uint8_t)(((zidlen - 1) & 0x0F) << 4); // TODO[protocol]: check if ZID > 0 && <= 16 _Z_RETURN_IF_ERR(_z_uint8_encode(wbf, cbyte)) _Z_RETURN_IF_ERR(_z_wbuf_write_bytes(wbf, msg->_zid.id, 0, zidlen)) diff --git a/src/protocol/core.c b/src/protocol/core.c index 81e27b5a4..08cc542c4 100644 --- a/src/protocol/core.c +++ b/src/protocol/core.c @@ -42,7 +42,7 @@ _Bool _z_id_check(_z_id_t id) { } return ret; } -_z_id_t _z_id_empty() { +_z_id_t _z_id_empty(void) { return (_z_id_t){.id = { 0, 0, @@ -62,10 +62,10 @@ _z_id_t _z_id_empty() { 0, }}; } -_z_source_info_t _z_source_info_null() { +_z_source_info_t _z_source_info_null(void) { return (_z_source_info_t){._source_sn = 0, ._entity_id = 0, ._id = _z_id_empty()}; } -_z_timestamp_t _z_timestamp_null() { return (_z_timestamp_t){.id = _z_id_empty(), .time = 0}; } +_z_timestamp_t _z_timestamp_null(void) { return (_z_timestamp_t){.id = _z_id_empty(), .time = 0}; } _z_value_t _z_value_null(void) { return (_z_value_t){.payload = _z_bytes_null(), .encoding = _z_encoding_null()}; } _z_value_t _z_value_steal(_z_value_t *value) { _z_value_t ret = *value; diff --git a/src/protocol/definitions/network.c b/src/protocol/definitions/network.c index 63341b68e..f7c08f34f 100644 --- a/src/protocol/definitions/network.c +++ b/src/protocol/definitions/network.c @@ -72,7 +72,7 @@ _z_push_body_t _z_push_body_steal(_z_push_body_t *msg) { *msg = _z_push_body_null(); return ret; } -_z_push_body_t _z_push_body_null() { +_z_push_body_t _z_push_body_null(void) { return (_z_push_body_t){ ._is_put = false, ._body._del._commons = {._timestamp = _z_timestamp_null(), ._source_info = _z_source_info_null()}}; diff --git a/src/protocol/definitions/transport.c b/src/protocol/definitions/transport.c index 2a774f758..39bbee9d1 100644 --- a/src/protocol/definitions/transport.c +++ b/src/protocol/definitions/transport.c @@ -17,14 +17,20 @@ #include "zenoh-pico/collections/slice.h" #include "zenoh-pico/utils/logging.h" -void _z_s_msg_scout_clear(_z_s_msg_scout_t *msg) {} +void _z_s_msg_scout_clear(_z_s_msg_scout_t *msg) { + // Nothing to do + _ZP_UNUSED(msg); +} /*------------------ Locators Field ------------------*/ void _z_locators_clear(_z_locator_array_t *ls) { _z_locator_array_clear(ls); } void _z_s_msg_hello_clear(_z_s_msg_hello_t *msg) { _z_locators_clear(&msg->_locators); } -void _z_t_msg_join_clear(_z_t_msg_join_t *msg) {} +void _z_t_msg_join_clear(_z_t_msg_join_t *msg) { + // Nothing to do + _ZP_UNUSED(msg); +} void _z_t_msg_init_clear(_z_t_msg_init_t *msg) { _z_slice_clear(&msg->_cookie); } @@ -414,4 +420,4 @@ void _z_s_msg_copy(_z_scouting_message_t *clone, _z_scouting_message_t *msg) { _Z_DEBUG("WARNING: Trying to copy session message with unknown ID(%d)", mid); } break; } -} \ No newline at end of file +} diff --git a/src/protocol/iobuf.c b/src/protocol/iobuf.c index f31511c4c..aa1f0346f 100644 --- a/src/protocol/iobuf.c +++ b/src/protocol/iobuf.c @@ -70,7 +70,7 @@ uint8_t _z_iosli_read(_z_iosli_t *ios) { void _z_iosli_read_bytes(_z_iosli_t *ios, uint8_t *dst, size_t offset, size_t length) { assert(_z_iosli_readable(ios) >= length); - uint8_t *w_pos = _z_ptr_u8_offset(dst, offset); + uint8_t *w_pos = _z_ptr_u8_offset(dst, (ptrdiff_t)offset); (void)memcpy(w_pos, ios->_buf + ios->_r_pos, length); ios->_r_pos = ios->_r_pos + length; } @@ -90,8 +90,8 @@ void _z_iosli_write(_z_iosli_t *ios, uint8_t b) { void _z_iosli_write_bytes(_z_iosli_t *ios, const uint8_t *bs, size_t offset, size_t length) { assert(_z_iosli_writable(ios) >= length); - uint8_t *w_pos = _z_ptr_u8_offset(ios->_buf, ios->_w_pos); - (void)memcpy(w_pos, _z_cptr_u8_offset(bs, offset), length); + uint8_t *w_pos = _z_ptr_u8_offset(ios->_buf, (ptrdiff_t)ios->_w_pos); + (void)memcpy(w_pos, _z_cptr_u8_offset(bs, (ptrdiff_t)offset), length); ios->_w_pos += length; } @@ -103,7 +103,7 @@ void _z_iosli_put(_z_iosli_t *ios, uint8_t b, size_t pos) { _z_slice_t _z_iosli_to_bytes(const _z_iosli_t *ios) { _z_slice_t a; a.len = _z_iosli_readable(ios); - a.start = _z_cptr_u8_offset(ios->_buf, ios->_r_pos); + a.start = _z_cptr_u8_offset(ios->_buf, (ptrdiff_t)ios->_r_pos); return a; } @@ -183,7 +183,9 @@ size_t _z_zbuf_capacity(const _z_zbuf_t *zbf) { return zbf->_ios._capacity; } size_t _z_zbuf_space_left(const _z_zbuf_t *zbf) { return _z_iosli_writable(&zbf->_ios); } -uint8_t const *_z_zbuf_start(const _z_zbuf_t *zbf) { return _z_ptr_u8_offset(zbf->_ios._buf, zbf->_ios._r_pos); } +uint8_t const *_z_zbuf_start(const _z_zbuf_t *zbf) { + return _z_ptr_u8_offset(zbf->_ios._buf, (ptrdiff_t)zbf->_ios._r_pos); +} size_t _z_zbuf_len(const _z_zbuf_t *zbf) { return _z_iosli_readable(&zbf->_ios); } _Bool _z_zbuf_can_read(const _z_zbuf_t *zbf) { return _z_zbuf_len(zbf) > (size_t)0; } diff --git a/src/protocol/keyexpr.c b/src/protocol/keyexpr.c index 49fefcbf7..09f128747 100644 --- a/src/protocol/keyexpr.c +++ b/src/protocol/keyexpr.c @@ -89,7 +89,7 @@ zp_keyexpr_canon_status_t __zp_canon_prefix(const char *start, size_t *len) { _Bool in_big_wild = false; char const *chunk_start = start; - const char *end = _z_cptr_char_offset(start, *len); + const char *end = _z_cptr_char_offset(start, (ptrdiff_t)(*len)); char const *next_slash; do { @@ -192,7 +192,7 @@ zp_keyexpr_canon_status_t __zp_canon_prefix(const char *start, size_t *len) { } void __zp_singleify(char *start, size_t *len, const char *needle) { - const char *end = _z_cptr_char_offset(start, *len); + const char *end = _z_cptr_char_offset(start, (ptrdiff_t)(*len)); _Bool right_after_needle = false; char *reader = start; @@ -203,7 +203,7 @@ void __zp_singleify(char *start, size_t *len, const char *needle) { break; } right_after_needle = true; - reader = _z_ptr_char_offset(reader, pos); + reader = _z_ptr_char_offset(reader, (ptrdiff_t)pos); } else { right_after_needle = false; reader = _z_ptr_char_offset(reader, 1); @@ -218,10 +218,10 @@ void __zp_singleify(char *start, size_t *len, const char *needle) { for (size_t i = 0; i < pos; i++) { writer[i] = reader[i]; } - writer = _z_ptr_char_offset(writer, pos); + writer = _z_ptr_char_offset(writer, (ptrdiff_t)pos); } right_after_needle = true; - reader = _z_ptr_char_offset(reader, pos); + reader = _z_ptr_char_offset(reader, (ptrdiff_t)pos); } else { right_after_needle = false; *writer = *reader; @@ -239,7 +239,7 @@ void __zp_ke_write_chunk(char **writer, const char *chunk, size_t len, const cha } (void)memcpy(writer[0], chunk, len); - writer[0] = _z_ptr_char_offset(writer[0], len); + writer[0] = _z_ptr_char_offset(writer[0], (ptrdiff_t)len); } /*------------------ Common helpers ------------------*/ @@ -291,7 +291,7 @@ _Bool _z_ke_isdoublestar(_z_str_se_t s) { /*------------------ Inclusion helpers ------------------*/ _Bool _z_ke_chunk_includes_nodsl(_z_str_se_t l, _z_str_se_t r) { - size_t llen = l.end - l.start; + size_t llen = (size_t)(l.end - l.start); _Bool result = !(r.start[0] == _Z_VERBATIM) && ((llen == (size_t)1) && (l.start[0] == '*') && (((_z_ptr_char_diff(r.end, r.start) == 2) && (r.start[0] == '*')) == false)); @@ -396,8 +396,8 @@ _Bool _z_keyexpr_includes_superwild(_z_str_se_t left, _z_str_se_t right, _z_ke_c _Bool _z_keyexpr_includes(const char *lstart, const size_t llen, const char *rstart, const size_t rlen) { _Bool result = ((llen == rlen) && (strncmp(lstart, rstart, llen) == 0)); if (result == false) { - _z_str_se_t l = {.start = lstart, .end = _z_cptr_char_offset(lstart, llen)}; - _z_str_se_t r = {.start = rstart, .end = _z_cptr_char_offset(rstart, rlen)}; + _z_str_se_t l = {.start = lstart, .end = _z_cptr_char_offset(lstart, (ptrdiff_t)llen)}; + _z_str_se_t r = {.start = rstart, .end = _z_cptr_char_offset(rstart, (ptrdiff_t)rlen)}; size_t ln_chunks = 0, ln_verbatim = 0; size_t rn_chunks = 0, rn_verbatim = 0; int8_t lwildness = _zp_ke_wildness(l, &ln_chunks, &ln_verbatim); @@ -630,8 +630,8 @@ _Bool _z_keyexpr_intersect_bothsuper(_z_str_se_t l, _z_str_se_t r, _z_ke_chunk_m _Bool _z_keyexpr_intersects(const char *lstart, const size_t llen, const char *rstart, const size_t rlen) { _Bool result = ((llen == rlen) && (strncmp(lstart, rstart, llen) == 0)); if (result == false) { - _z_str_se_t l = {.start = lstart, .end = _z_cptr_char_offset(lstart, llen)}; - _z_str_se_t r = {.start = rstart, .end = _z_cptr_char_offset(rstart, rlen)}; + _z_str_se_t l = {.start = lstart, .end = _z_cptr_char_offset(lstart, (ptrdiff_t)llen)}; + _z_str_se_t r = {.start = rstart, .end = _z_cptr_char_offset(rstart, (ptrdiff_t)rlen)}; size_t ln_chunks = 0, ln_verbatim = 0; size_t rn_chunks = 0, rn_verbatim = 0; int8_t lwildness = _zp_ke_wildness(l, &ln_chunks, &ln_verbatim); @@ -685,8 +685,8 @@ zp_keyexpr_canon_status_t _z_keyexpr_canonize(char *start, size_t *len) { (ret == Z_KEYEXPR_CANON_DOUBLE_STAR_AFTER_DOUBLE_STAR)) { ret = Z_KEYEXPR_CANON_SUCCESS; - const char *end = _z_cptr_char_offset(start, *len); - char *reader = _z_ptr_char_offset(start, canon_len); + const char *end = _z_cptr_char_offset(start, (ptrdiff_t)(*len)); + char *reader = _z_ptr_char_offset(start, (ptrdiff_t)canon_len); const char *write_start = reader; char *writer = reader; char *next_slash = strchr(reader, '/'); @@ -799,4 +799,4 @@ zp_keyexpr_canon_status_t _z_keyexpr_canonize(char *start, size_t *len) { return ret; } -zp_keyexpr_canon_status_t _z_keyexpr_is_canon(const char *start, size_t len) { return __zp_canon_prefix(start, &len); } \ No newline at end of file +zp_keyexpr_canon_status_t _z_keyexpr_is_canon(const char *start, size_t len) { return __zp_canon_prefix(start, &len); } diff --git a/src/session/push.c b/src/session/push.c index 0763d0bd4..4c2645f41 100644 --- a/src/session/push.c +++ b/src/session/push.c @@ -25,12 +25,15 @@ int8_t _z_trigger_push(_z_session_t *zn, _z_n_msg_push_t *push) { int8_t ret = _Z_RES_OK; // TODO check body to know where to dispatch +#if Z_FEATURE_SUBSCRIPTION == 1 _z_slice_t payload = push->_body._is_put ? push->_body._body._put._payload : _z_slice_empty(); _z_encoding_t encoding = push->_body._is_put ? push->_body._body._put._encoding : _z_encoding_null(); - int kind = push->_body._is_put ? Z_SAMPLE_KIND_PUT : Z_SAMPLE_KIND_DELETE; -#if Z_FEATURE_SUBSCRIPTION == 1 + size_t kind = push->_body._is_put ? Z_SAMPLE_KIND_PUT : Z_SAMPLE_KIND_DELETE; ret = _z_trigger_subscriptions(zn, push->_key, payload, encoding, kind, push->_timestamp, push->_qos, push->_body._body._put._attachment); +#else + _ZP_UNUSED(zn); + _ZP_UNUSED(push); #endif return ret; } diff --git a/src/session/reply.c b/src/session/reply.c index dc57530e3..5b756d8f5 100644 --- a/src/session/reply.c +++ b/src/session/reply.c @@ -30,6 +30,11 @@ int8_t _z_trigger_reply_partial(_z_session_t *zn, _z_zint_t id, _z_keyexpr_t key } else { ret = _Z_ERR_GENERIC; } +#else + _ZP_UNUSED(zn); + _ZP_UNUSED(id); + _ZP_UNUSED(key); + _ZP_UNUSED(reply); #endif return ret; } @@ -42,6 +47,7 @@ int8_t _z_trigger_reply_final(_z_session_t *zn, _z_n_msg_response_final_t *final _z_zint_t id = final->_request_id; _z_trigger_query_reply_final(zn, id); #else + _ZP_UNUSED(zn); _ZP_UNUSED(final); #endif return ret; diff --git a/src/session/resource.c b/src/session/resource.c index 0c2dc44ce..ca1305d41 100644 --- a/src/session/resource.c +++ b/src/session/resource.c @@ -213,8 +213,8 @@ _z_keyexpr_t _z_get_expanded_key_from_key(_z_session_t *zn, const _z_keyexpr_t * } /// Returns the ID of the registered keyexpr. Returns 0 if registration failed. -int16_t _z_register_resource(_z_session_t *zn, _z_keyexpr_t key, uint16_t id, uint16_t register_to_mapping) { - int16_t ret = Z_RESOURCE_ID_NONE; +uint16_t _z_register_resource(_z_session_t *zn, _z_keyexpr_t key, uint16_t id, uint16_t register_to_mapping) { + uint16_t ret = Z_RESOURCE_ID_NONE; key = _z_keyexpr_alias(key); uint16_t mapping = register_to_mapping; uint16_t parent_mapping = _z_keyexpr_mapping_id(&key); diff --git a/src/session/rx.c b/src/session/rx.c index c1a53ce1c..2f040a4fa 100644 --- a/src/session/rx.c +++ b/src/session/rx.c @@ -98,8 +98,8 @@ int8_t _z_handle_network_message(_z_session_t *zn, _z_zenoh_message_t *msg, uint #endif } break; case _Z_REQUEST_PUT: { - _z_msg_put_t put = req._body._put; #if Z_FEATURE_SUBSCRIPTION == 1 + _z_msg_put_t put = req._body._put; ret = _z_trigger_subscriptions(zn, req._key, put._payload, put._encoding, Z_SAMPLE_KIND_PUT, put._commons._timestamp, req._ext_qos, put._attachment); #endif @@ -109,8 +109,8 @@ int8_t _z_handle_network_message(_z_session_t *zn, _z_zenoh_message_t *msg, uint } } break; case _Z_REQUEST_DEL: { - _z_msg_del_t del = req._body._del; #if Z_FEATURE_SUBSCRIPTION == 1 + _z_msg_del_t del = req._body._del; ret = _z_trigger_subscriptions(zn, req._key, _z_slice_empty(), _z_encoding_null(), Z_SAMPLE_KIND_DELETE, del._commons._timestamp, req._ext_qos, _z_bytes_null()); diff --git a/src/session/subscription.c b/src/session/subscription.c index 66c8510a8..ec0980feb 100644 --- a/src/session/subscription.c +++ b/src/session/subscription.c @@ -215,6 +215,7 @@ void _z_trigger_local_subscriptions(_z_session_t *zn, const _z_keyexpr_t keyexpr _ZP_UNUSED(payload); _ZP_UNUSED(payload_len); _ZP_UNUSED(qos); + _ZP_UNUSED(att); } #endif // Z_FEATURE_SUBSCRIPTION == 1 diff --git a/src/session/utils.c b/src/session/utils.c index 8600b5211..556694bb8 100644 --- a/src/session/utils.c +++ b/src/session/utils.c @@ -139,4 +139,4 @@ void _zp_session_unlock_mutex(_z_session_t *zn) { (void)z_mutex_unlock(&zn->_mut #else void _zp_session_lock_mutex(_z_session_t *zn) { _ZP_UNUSED(zn); } void _zp_session_unlock_mutex(_z_session_t *zn) { _ZP_UNUSED(zn); } -#endif \ No newline at end of file +#endif diff --git a/src/system/unix/link/raweth.c b/src/system/unix/link/raweth.c index 0b3131e35..9a97546f2 100644 --- a/src/system/unix/link/raweth.c +++ b/src/system/unix/link/raweth.c @@ -96,7 +96,7 @@ size_t _z_receive_raweth(const _z_sys_net_socket_t *sock, void *buff, size_t buf const _zp_raweth_whitelist_array_t *whitelist) { // Read from socket ssize_t bytesRead = recvfrom(sock->_fd, buff, buff_len, 0, NULL, NULL); - if ((bytesRead < 0) || (bytesRead < sizeof(_zp_eth_header_t))) { + if ((bytesRead < 0) || (bytesRead < (ssize_t)sizeof(_zp_eth_header_t))) { return SIZE_MAX; } _Bool is_valid = true; @@ -118,15 +118,16 @@ size_t _z_receive_raweth(const _z_sys_net_socket_t *sock, void *buff, size_t buf } // Copy sender mac if needed if (addr != NULL) { + uint8_t *header_addr = (uint8_t *)buff; *addr = _z_slice_make(sizeof(ETH_ALEN)); - (void)memcpy((uint8_t *)addr->start, (buff + ETH_ALEN), sizeof(ETH_ALEN)); + (void)memcpy((uint8_t *)addr->start, (header_addr + ETH_ALEN), sizeof(ETH_ALEN)); } - return bytesRead; + return (size_t)bytesRead; } -size_t _z_raweth_ntohs(size_t val) { return ntohs(val); } +uint16_t _z_raweth_ntohs(uint16_t val) { return ntohs(val); } -size_t _z_raweth_htons(size_t val) { return htons(val); } +uint16_t _z_raweth_htons(uint16_t val) { return htons(val); } #endif // defined(__linux) #endif // Z_FEATURE_RAWETH_TRANSPORT == 1 diff --git a/src/system/unix/network.c b/src/system/unix/network.c index e4a7a2af9..ca40c15a5 100644 --- a/src/system/unix/network.c +++ b/src/system/unix/network.c @@ -125,10 +125,10 @@ void _z_close_tcp(_z_sys_net_socket_t *sock) { size_t _z_read_tcp(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len) { ssize_t rb = recv(sock._fd, ptr, len, 0); if (rb < (ssize_t)0) { - rb = SIZE_MAX; + return SIZE_MAX; } - return rb; + return (size_t)rb; } size_t _z_read_exact_tcp(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len) { @@ -143,7 +143,7 @@ size_t _z_read_exact_tcp(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t le } n = n + rb; - pos = _z_ptr_u8_offset(pos, n); + pos = _z_ptr_u8_offset(pos, (ptrdiff_t)n); } while (n != len); return n; @@ -151,7 +151,7 @@ size_t _z_read_exact_tcp(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t le size_t _z_send_tcp(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t len) { #if defined(ZENOH_LINUX) - return send(sock._fd, ptr, len, MSG_NOSIGNAL); + return (size_t)send(sock._fd, ptr, len, MSG_NOSIGNAL); #else return send(sock._fd, ptr, len, 0); #endif @@ -223,10 +223,9 @@ size_t _z_read_udp_unicast(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t ssize_t rb = recvfrom(sock._fd, ptr, len, 0, (struct sockaddr *)&raddr, &addrlen); if (rb < (ssize_t)0) { - rb = SIZE_MAX; + return SIZE_MAX; } - - return rb; + return (size_t)rb; } size_t _z_read_exact_udp_unicast(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len) { @@ -241,7 +240,7 @@ size_t _z_read_exact_udp_unicast(const _z_sys_net_socket_t sock, uint8_t *ptr, s } n = n + rb; - pos = _z_ptr_u8_offset(pos, n); + pos = _z_ptr_u8_offset(pos, (ptrdiff_t)n); } while (n != len); return n; @@ -249,7 +248,7 @@ size_t _z_read_exact_udp_unicast(const _z_sys_net_socket_t sock, uint8_t *ptr, s size_t _z_send_udp_unicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t len, const _z_sys_net_endpoint_t rep) { - return sendto(sock._fd, ptr, len, 0, rep._iptcp->ai_addr, rep._iptcp->ai_addrlen); + return (size_t)sendto(sock._fd, ptr, len, 0, rep._iptcp->ai_addr, rep._iptcp->ai_addrlen); } #endif @@ -324,7 +323,7 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin ret = _Z_ERR_GENERIC; } } else if (lsockaddr->sa_family == AF_INET6) { - int ifindex = if_nametoindex(iface); + int ifindex = (int)if_nametoindex(iface); if ((ret == _Z_RES_OK) && (setsockopt(sock->_fd, IPPROTO_IPV6, IPV6_MULTICAST_IF, &ifindex, sizeof(ifindex)) < 0)) { ret = _Z_ERR_GENERIC; @@ -396,7 +395,7 @@ int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpo if (rep._iptcp->ai_family == AF_INET) { struct sockaddr_in address; (void)memset(&address, 0, sizeof(address)); - address.sin_family = rep._iptcp->ai_family; + address.sin_family = (sa_family_t)rep._iptcp->ai_family; address.sin_port = ((struct sockaddr_in *)rep._iptcp->ai_addr)->sin_port; inet_pton(address.sin_family, "0.0.0.0", &address.sin_addr); if ((ret == _Z_RES_OK) && (bind(sock->_fd, (struct sockaddr *)&address, sizeof(address)) < 0)) { @@ -405,7 +404,7 @@ int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpo } else if (rep._iptcp->ai_family == AF_INET6) { struct sockaddr_in6 address; (void)memset(&address, 0, sizeof(address)); - address.sin6_family = rep._iptcp->ai_family; + address.sin6_family = (sa_family_t)rep._iptcp->ai_family; address.sin6_port = ((struct sockaddr_in6 *)rep._iptcp->ai_addr)->sin6_port; inet_pton(address.sin6_family, "::", &address.sin6_addr); if ((ret == _Z_RES_OK) && (bind(sock->_fd, (struct sockaddr *)&address, sizeof(address)) < 0)) { @@ -517,8 +516,7 @@ size_t _z_read_udp_multicast(const _z_sys_net_socket_t sock, uint8_t *ptr, size_ do { rb = recvfrom(sock._fd, ptr, len, 0, (struct sockaddr *)&raddr, &replen); if (rb < (ssize_t)0) { - rb = SIZE_MAX; - break; + return SIZE_MAX; } if (lep._iptcp->ai_family == AF_INET) { @@ -551,7 +549,7 @@ size_t _z_read_udp_multicast(const _z_sys_net_socket_t sock, uint8_t *ptr, size_ } } while (1); - return rb; + return (size_t)rb; } size_t _z_read_exact_udp_multicast(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len, @@ -567,7 +565,7 @@ size_t _z_read_exact_udp_multicast(const _z_sys_net_socket_t sock, uint8_t *ptr, } n = n + rb; - pos = _z_ptr_u8_offset(pos, n); + pos = _z_ptr_u8_offset(pos, (ptrdiff_t)n); } while (n != len); return n; @@ -575,7 +573,7 @@ size_t _z_read_exact_udp_multicast(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t _z_send_udp_multicast(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t len, const _z_sys_net_endpoint_t rep) { - return sendto(sock._fd, ptr, len, 0, rep._iptcp->ai_addr, rep._iptcp->ai_addrlen); + return (size_t)sendto(sock._fd, ptr, len, 0, rep._iptcp->ai_addr, rep._iptcp->ai_addrlen); } #endif diff --git a/src/system/unix/system.c b/src/system/unix/system.c index 799b60519..49857ac7e 100644 --- a/src/system/unix/system.c +++ b/src/system/unix/system.c @@ -102,12 +102,12 @@ void z_free(void *ptr) { free(ptr); } #if Z_FEATURE_MULTI_THREAD == 1 /*------------------ Task ------------------*/ int8_t z_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) { - return pthread_create(task, attr, fun, arg); + return (int8_t)pthread_create(task, attr, fun, arg); } -int8_t z_task_join(z_task_t *task) { return pthread_join(*task, NULL); } +int8_t z_task_join(z_task_t *task) { return (int8_t)pthread_join(*task, NULL); } -int8_t zp_task_cancel(z_task_t *task) { return pthread_cancel(*task); } +int8_t zp_task_cancel(z_task_t *task) { return (int8_t)pthread_cancel(*task); } void z_task_free(z_task_t **task) { z_task_t *ptr = *task; @@ -116,28 +116,28 @@ void z_task_free(z_task_t **task) { } /*------------------ Mutex ------------------*/ -int8_t z_mutex_init(z_mutex_t *m) { return pthread_mutex_init(m, 0); } +int8_t z_mutex_init(z_mutex_t *m) { return (int8_t)pthread_mutex_init(m, 0); } -int8_t z_mutex_free(z_mutex_t *m) { return pthread_mutex_destroy(m); } +int8_t z_mutex_free(z_mutex_t *m) { return (int8_t)pthread_mutex_destroy(m); } -int8_t z_mutex_lock(z_mutex_t *m) { return pthread_mutex_lock(m); } +int8_t z_mutex_lock(z_mutex_t *m) { return (int8_t)pthread_mutex_lock(m); } -int8_t z_mutex_trylock(z_mutex_t *m) { return pthread_mutex_trylock(m); } +int8_t z_mutex_trylock(z_mutex_t *m) { return (int8_t)pthread_mutex_trylock(m); } -int8_t z_mutex_unlock(z_mutex_t *m) { return pthread_mutex_unlock(m); } +int8_t z_mutex_unlock(z_mutex_t *m) { return (int8_t)pthread_mutex_unlock(m); } /*------------------ Condvar ------------------*/ -int8_t z_condvar_init(z_condvar_t *cv) { return pthread_cond_init(cv, 0); } +int8_t z_condvar_init(z_condvar_t *cv) { return (int8_t)pthread_cond_init(cv, 0); } -int8_t z_condvar_free(z_condvar_t *cv) { return pthread_cond_destroy(cv); } +int8_t z_condvar_free(z_condvar_t *cv) { return (int8_t)pthread_cond_destroy(cv); } -int8_t z_condvar_signal(z_condvar_t *cv) { return pthread_cond_signal(cv); } +int8_t z_condvar_signal(z_condvar_t *cv) { return (int8_t)pthread_cond_signal(cv); } -int8_t z_condvar_wait(z_condvar_t *cv, z_mutex_t *m) { return pthread_cond_wait(cv, m); } +int8_t z_condvar_wait(z_condvar_t *cv, z_mutex_t *m) { return (int8_t)pthread_cond_wait(cv, m); } #endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ -int z_sleep_us(size_t time) { return usleep(time); } +int z_sleep_us(size_t time) { return usleep((unsigned int)time); } int z_sleep_ms(size_t time) { z_time_t start = z_time_now(); @@ -152,7 +152,7 @@ int z_sleep_ms(size_t time) { return 0; } -int z_sleep_s(size_t time) { return sleep(time); } +int z_sleep_s(size_t time) { return (int)sleep((unsigned int)time); } /*------------------ Instant ------------------*/ z_clock_t z_clock_now(void) { @@ -165,7 +165,8 @@ unsigned long z_clock_elapsed_us(z_clock_t *instant) { z_clock_t now; clock_gettime(CLOCK_MONOTONIC, &now); - unsigned long elapsed = (1000000 * (now.tv_sec - instant->tv_sec) + (now.tv_nsec - instant->tv_nsec) / 1000); + unsigned long elapsed = + (unsigned long)(1000000 * (now.tv_sec - instant->tv_sec) + (now.tv_nsec - instant->tv_nsec) / 1000); return elapsed; } @@ -173,7 +174,8 @@ unsigned long z_clock_elapsed_ms(z_clock_t *instant) { z_clock_t now; clock_gettime(CLOCK_MONOTONIC, &now); - unsigned long elapsed = (1000 * (now.tv_sec - instant->tv_sec) + (now.tv_nsec - instant->tv_nsec) / 1000000); + unsigned long elapsed = + (unsigned long)(1000 * (now.tv_sec - instant->tv_sec) + (now.tv_nsec - instant->tv_nsec) / 1000000); return elapsed; } @@ -181,7 +183,7 @@ unsigned long z_clock_elapsed_s(z_clock_t *instant) { z_clock_t now; clock_gettime(CLOCK_MONOTONIC, &now); - unsigned long elapsed = now.tv_sec - instant->tv_sec; + unsigned long elapsed = (unsigned long)(now.tv_sec - instant->tv_sec); return elapsed; } @@ -204,7 +206,7 @@ unsigned long z_time_elapsed_us(z_time_t *time) { z_time_t now; gettimeofday(&now, NULL); - unsigned long elapsed = (1000000 * (now.tv_sec - time->tv_sec) + (now.tv_usec - time->tv_usec)); + unsigned long elapsed = (unsigned long)(1000000 * (now.tv_sec - time->tv_sec) + (now.tv_usec - time->tv_usec)); return elapsed; } @@ -212,7 +214,7 @@ unsigned long z_time_elapsed_ms(z_time_t *time) { z_time_t now; gettimeofday(&now, NULL); - unsigned long elapsed = (1000 * (now.tv_sec - time->tv_sec) + (now.tv_usec - time->tv_usec) / 1000); + unsigned long elapsed = (unsigned long)(1000 * (now.tv_sec - time->tv_sec) + (now.tv_usec - time->tv_usec) / 1000); return elapsed; } @@ -220,6 +222,6 @@ unsigned long z_time_elapsed_s(z_time_t *time) { z_time_t now; gettimeofday(&now, NULL); - unsigned long elapsed = now.tv_sec - time->tv_sec; + unsigned long elapsed = (unsigned long)(now.tv_sec - time->tv_sec); return elapsed; } diff --git a/src/transport/multicast/lease.c b/src/transport/multicast/lease.c index f728535f6..5c313a8af 100644 --- a/src/transport/multicast/lease.c +++ b/src/transport/multicast/lease.c @@ -23,6 +23,37 @@ #if Z_FEATURE_MULTICAST_TRANSPORT == 1 || Z_FEATURE_RAWETH_TRANSPORT == 1 +int8_t _zp_multicast_send_join(_z_transport_multicast_t *ztm) { + _z_conduit_sn_list_t next_sn; + next_sn._is_qos = false; + next_sn._val._plain._best_effort = ztm->_sn_tx_best_effort; + next_sn._val._plain._reliable = ztm->_sn_tx_reliable; + + _z_id_t zid = ((_z_session_t *)ztm->_session)->_local_zid; + _z_transport_message_t jsm = _z_t_msg_make_join(Z_WHATAMI_PEER, Z_TRANSPORT_LEASE, zid, next_sn); + + return ztm->_send_f(ztm, &jsm); +} + +int8_t _zp_multicast_send_keep_alive(_z_transport_multicast_t *ztm) { + _z_transport_message_t t_msg = _z_t_msg_make_keep_alive(); + return ztm->_send_f(ztm, &t_msg); +} + +#else +int8_t _zp_multicast_send_join(_z_transport_multicast_t *ztm) { + _ZP_UNUSED(ztm); + return _Z_ERR_TRANSPORT_NOT_AVAILABLE; +} + +int8_t _zp_multicast_send_keep_alive(_z_transport_multicast_t *ztm) { + _ZP_UNUSED(ztm); + return _Z_ERR_TRANSPORT_NOT_AVAILABLE; +} +#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 || Z_FEATURE_RAWETH_TRANSPORT == 1 + +#if Z_FEATURE_MULTI_THREAD == 1 && (Z_FEATURE_MULTICAST_TRANSPORT == 1 || Z_FEATURE_RAWETH_TRANSPORT == 1) + static _z_zint_t _z_get_minimum_lease(_z_transport_peer_entry_list_t *peers, _z_zint_t local_lease) { _z_zint_t ret = local_lease; @@ -57,45 +88,14 @@ static _z_zint_t _z_get_next_lease(_z_transport_peer_entry_list_t *peers) { return ret; } -int8_t _zp_multicast_send_join(_z_transport_multicast_t *ztm) { - _z_conduit_sn_list_t next_sn; - next_sn._is_qos = false; - next_sn._val._plain._best_effort = ztm->_sn_tx_best_effort; - next_sn._val._plain._reliable = ztm->_sn_tx_reliable; - - _z_id_t zid = ((_z_session_t *)ztm->_session)->_local_zid; - _z_transport_message_t jsm = _z_t_msg_make_join(Z_WHATAMI_PEER, Z_TRANSPORT_LEASE, zid, next_sn); - - return ztm->_send_f(ztm, &jsm); -} - -int8_t _zp_multicast_send_keep_alive(_z_transport_multicast_t *ztm) { - _z_transport_message_t t_msg = _z_t_msg_make_keep_alive(); - return ztm->_send_f(ztm, &t_msg); -} - -#else -int8_t _zp_multicast_send_join(_z_transport_multicast_t *ztm) { - _ZP_UNUSED(ztm); - return _Z_ERR_TRANSPORT_NOT_AVAILABLE; -} - -int8_t _zp_multicast_send_keep_alive(_z_transport_multicast_t *ztm) { - _ZP_UNUSED(ztm); - return _Z_ERR_TRANSPORT_NOT_AVAILABLE; -} -#endif // Z_FEATURE_MULTICAST_TRANSPORT == 1 || Z_FEATURE_RAWETH_TRANSPORT == 1 - -#if Z_FEATURE_MULTI_THREAD == 1 && (Z_FEATURE_MULTICAST_TRANSPORT == 1 || Z_FEATURE_RAWETH_TRANSPORT == 1) - void *_zp_multicast_lease_task(void *ztm_arg) { _z_transport_multicast_t *ztm = (_z_transport_multicast_t *)ztm_arg; ztm->_transmitted = false; // From all peers, get the next lease time (minimum) - _z_zint_t next_lease = _z_get_minimum_lease(ztm->_peers, ztm->_lease); - _z_zint_t next_keep_alive = (_z_zint_t)(next_lease / Z_TRANSPORT_LEASE_EXPIRE_FACTOR); - _z_zint_t next_join = Z_JOIN_INTERVAL; + int next_lease = (int)_z_get_minimum_lease(ztm->_peers, ztm->_lease); + int next_keep_alive = (int)(next_lease / Z_TRANSPORT_LEASE_EXPIRE_FACTOR); + int next_join = Z_JOIN_INTERVAL; _z_transport_peer_entry_list_t *it = NULL; while (ztm->_lease_task_running == true) { @@ -137,12 +137,11 @@ void *_zp_multicast_lease_task(void *ztm_arg) { // Reset the keep alive parameters ztm->_transmitted = false; - next_keep_alive = - (_z_zint_t)(_z_get_minimum_lease(ztm->_peers, ztm->_lease) / Z_TRANSPORT_LEASE_EXPIRE_FACTOR); + next_keep_alive = (int)(_z_get_minimum_lease(ztm->_peers, ztm->_lease) / Z_TRANSPORT_LEASE_EXPIRE_FACTOR); } // Compute the target interval to sleep - _z_zint_t interval; + int interval; if (next_lease > 0) { interval = next_lease; if (next_keep_alive < interval) { @@ -161,7 +160,7 @@ void *_zp_multicast_lease_task(void *ztm_arg) { z_mutex_unlock(&ztm->_mutex_peer); // The keep alive and lease intervals are expressed in milliseconds - z_sleep_ms(interval); + z_sleep_ms((size_t)interval); // Decrement all intervals z_mutex_lock(&ztm->_mutex_peer); @@ -169,10 +168,16 @@ void *_zp_multicast_lease_task(void *ztm_arg) { it = ztm->_peers; while (it != NULL) { _z_transport_peer_entry_t *entry = _z_transport_peer_entry_list_head(it); - entry->_next_lease = entry->_next_lease - interval; + int entry_next_lease = (int)entry->_next_lease - interval; + if (entry_next_lease >= 0) { + entry->_next_lease = (size_t)entry_next_lease; + } else { + _Z_ERROR("Negative next lease value"); + entry->_next_lease = 0; + } it = _z_transport_peer_entry_list_tail(it); } - next_lease = _z_get_next_lease(ztm->_peers); + next_lease = (int)_z_get_next_lease(ztm->_peers); next_keep_alive = next_keep_alive - interval; next_join = next_join - interval; diff --git a/src/transport/raweth/link.c b/src/transport/raweth/link.c index 1970a3d34..a8c45492a 100644 --- a/src/transport/raweth/link.c +++ b/src/transport/raweth/link.c @@ -45,6 +45,9 @@ #define RAWETH_CONFIG_WHITELIST_KEY 0x04 #define RAWETH_CONFIG_WHITELIST_STR "whitelist" +// Ethtype must be at least 0x600 in network order +#define RAWETH_ETHTYPE_MIN_VALUE 0x600U + #define RAWETH_CONFIG_MAPPING_BUILD \ _z_str_intmapping_t args[RAWETH_CONFIG_ARGC]; \ args[0]._key = RAWETH_CONFIG_IFACE_KEY; \ @@ -99,7 +102,7 @@ static _Bool _z_valid_ethtype_raweth(_z_str_intmap_t *config) { return false; } long ethtype = strtol(s_ethtype, NULL, 16); - return (_z_raweth_htons(ethtype) > 0x600); // Ethtype must be at least 0x600 in network order + return (_z_raweth_htons((uint16_t)ethtype) > RAWETH_ETHTYPE_MIN_VALUE); } static long _z_get_ethtype_raweth(_z_str_intmap_t *config) { @@ -170,7 +173,7 @@ static int8_t _z_get_mapping_raweth(_z_str_intmap_t *config, _zp_raweth_mapping_ return _Z_RES_OK; } -static const size_t _z_valid_whitelist_raweth(_z_str_intmap_t *config) { +static size_t _z_valid_whitelist_raweth(_z_str_intmap_t *config) { // Retrieve data const char *cfg_str = _z_str_intmap_get(config, RAWETH_CONFIG_WHITELIST_KEY); if (cfg_str == NULL) { @@ -314,13 +317,13 @@ static _Bool _z_valid_address_raweth(const char *address) { return false; } // Check if the colons are at the correct positions - for (int i = 2; i < len; i += 3) { + for (size_t i = 2; i < len; i += 3) { if (address[i] != ':') { return false; } } // Check if each character is a valid hexadecimal digit - for (int i = 0; i < len; ++i) { + for (size_t i = 0; i < len; ++i) { if (i % 3 != 2) { char c = address[i]; if (!((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'))) { @@ -332,7 +335,6 @@ static _Bool _z_valid_address_raweth(const char *address) { } static uint8_t *_z_parse_address_raweth(const char *address) { - size_t len = strlen(address); // Allocate data uint8_t *ret = (uint8_t *)z_malloc(_ZP_MAC_ADDR_LENGTH); if (ret == NULL) { diff --git a/src/transport/raweth/rx.c b/src/transport/raweth/rx.c index db135c9cb..dfba004a6 100644 --- a/src/transport/raweth/rx.c +++ b/src/transport/raweth/rx.c @@ -47,9 +47,9 @@ static size_t _z_raweth_link_recv_zbuf(const _z_link_t *link, _z_zbuf_t *zbf, _z } size_t data_length = 0; if (has_vlan) { - _zp_eth_vlan_header_t *header = (_zp_eth_vlan_header_t *)buff; + _zp_eth_vlan_header_t *vlan_header = (_zp_eth_vlan_header_t *)buff; // Retrieve data length - data_length = _z_raweth_ntohs(header->data_length); + data_length = _z_raweth_ntohs(vlan_header->data_length); if (rb < (data_length + sizeof(_zp_eth_vlan_header_t))) { // Invalid data_length return SIZE_MAX; @@ -58,7 +58,7 @@ static size_t _z_raweth_link_recv_zbuf(const _z_link_t *link, _z_zbuf_t *zbf, _z _z_zbuf_set_wpos(zbf, _z_zbuf_get_wpos(zbf) + sizeof(_zp_eth_vlan_header_t) + data_length); _z_zbuf_set_rpos(zbf, _z_zbuf_get_rpos(zbf) + sizeof(_zp_eth_vlan_header_t)); } else { - _zp_eth_header_t *header = (_zp_eth_header_t *)buff; + header = (_zp_eth_header_t *)buff; // Retrieve data length data_length = _z_raweth_ntohs(header->data_length); if (rb < (data_length + sizeof(_zp_eth_header_t))) { diff --git a/src/transport/raweth/tx.c b/src/transport/raweth/tx.c index 9e75d3163..72784f6b6 100644 --- a/src/transport/raweth/tx.c +++ b/src/transport/raweth/tx.c @@ -37,13 +37,13 @@ static void _zp_raweth_unlock_tx_mutex(_z_transport_multicast_t *ztm) { _ZP_UNUS #endif static int _zp_raweth_find_map_entry(const _z_keyexpr_t *keyexpr, _z_raweth_socket_t *sock) { - for (int i = 0; i < _zp_raweth_mapping_array_len(&sock->_mapping); i++) { + for (size_t i = 0; i < _zp_raweth_mapping_array_len(&sock->_mapping); i++) { // Find matching keyexpr const _zp_raweth_mapping_entry_t *entry = _zp_raweth_mapping_array_get(&sock->_mapping, i); if (zp_keyexpr_intersect_null_terminated(keyexpr->_suffix, entry->_keyexpr._suffix) != _Z_RES_OK) { continue; } - return i; + return (int)i; } return -1; } @@ -72,7 +72,7 @@ static int8_t _zp_raweth_set_socket(const _z_keyexpr_t *keyexpr, _z_raweth_socke _Z_DEBUG("Key '%s' wasn't found in config mapping, sending to default address", keyexpr->_suffix); } // Store data into socket - const _zp_raweth_mapping_entry_t *entry = _zp_raweth_mapping_array_get(&sock->_mapping, idx); + const _zp_raweth_mapping_entry_t *entry = _zp_raweth_mapping_array_get(&sock->_mapping, (size_t)idx); memcpy(&sock->_dmac, &entry->_dmac, _ZP_MAC_ADDR_LENGTH); uint16_t vlan = entry->_vlan; sock->_has_vlan = entry->_has_vlan; @@ -130,7 +130,7 @@ static int8_t __unsafe_z_raweth_write_header(_z_link_t *zl, _z_wbuf_t *wbf) { header.vlan_type = _ZP_ETH_TYPE_VLAN; header.tag = resocket->_vlan; header.ethtype = resocket->_ethtype; - header.data_length = _z_raweth_htons(wpos - sizeof(header)); + header.data_length = _z_raweth_htons((uint16_t)(wpos - sizeof(header))); // Write header _Z_RETURN_IF_ERR(_z_wbuf_write_bytes(wbf, (uint8_t *)&header, 0, sizeof(header))); } else { @@ -139,7 +139,7 @@ static int8_t __unsafe_z_raweth_write_header(_z_link_t *zl, _z_wbuf_t *wbf) { memcpy(&header.dmac, &resocket->_dmac, _ZP_MAC_ADDR_LENGTH); memcpy(&header.smac, &resocket->_smac, _ZP_MAC_ADDR_LENGTH); header.ethtype = resocket->_ethtype; - header.data_length = _z_raweth_htons(wpos - sizeof(header)); + header.data_length = _z_raweth_htons((uint16_t)(wpos - sizeof(header))); // Write header _Z_RETURN_IF_ERR(_z_wbuf_write_bytes(wbf, (uint8_t *)&header, 0, sizeof(header))); } diff --git a/src/transport/unicast/lease.c b/src/transport/unicast/lease.c index 03d0ffd1b..9dfad2244 100644 --- a/src/transport/unicast/lease.c +++ b/src/transport/unicast/lease.c @@ -44,10 +44,11 @@ void *_zp_unicast_lease_task(void *ztu_arg) { ztu->_received = false; ztu->_transmitted = false; - _z_zint_t next_lease = ztu->_lease; - _z_zint_t next_keep_alive = (_z_zint_t)(ztu->_lease / Z_TRANSPORT_LEASE_EXPIRE_FACTOR); + int next_lease = (int)ztu->_lease; + int next_keep_alive = (int)(ztu->_lease / Z_TRANSPORT_LEASE_EXPIRE_FACTOR); while (ztu->_lease_task_running == true) { - if (next_lease == 0) { + // Next lease process + if (next_lease <= 0) { // Check if received data if (ztu->_received == true) { // Reset the lease parameters @@ -58,10 +59,9 @@ void *_zp_unicast_lease_task(void *ztu_arg) { _z_unicast_transport_close(ztu, _Z_CLOSE_EXPIRED); break; } - - next_lease = ztu->_lease; + next_lease = (int)ztu->_lease; } - + // Next keep alive process if (next_keep_alive <= 0) { // Check if need to send a keep alive if (ztu->_transmitted == false) { @@ -72,11 +72,11 @@ void *_zp_unicast_lease_task(void *ztu_arg) { // Reset the keep alive parameters ztu->_transmitted = false; - next_keep_alive = (_z_zint_t)(ztu->_lease / Z_TRANSPORT_LEASE_EXPIRE_FACTOR); + next_keep_alive = (int)(ztu->_lease / Z_TRANSPORT_LEASE_EXPIRE_FACTOR); } // Compute the target interval - _z_zint_t interval; + int interval; if (next_lease == 0) { interval = next_keep_alive; } else { @@ -87,7 +87,7 @@ void *_zp_unicast_lease_task(void *ztu_arg) { } // The keep alive and lease intervals are expressed in milliseconds - z_sleep_ms(interval); + z_sleep_ms((size_t)interval); next_lease = next_lease - interval; next_keep_alive = next_keep_alive - interval; diff --git a/src/transport/unicast/rx.c b/src/transport/unicast/rx.c index 6278ca735..33132b3ca 100644 --- a/src/transport/unicast/rx.c +++ b/src/transport/unicast/rx.c @@ -164,7 +164,7 @@ int8_t _z_unicast_handle_transport_message(_z_transport_unicast_t *ztu, _z_trans _z_zbuf_t zbf = _z_wbuf_to_zbuf(dbuf); // Convert the defragmentation buffer into a decoding buffer _z_zenoh_message_t zm; - int8_t ret = _z_network_message_decode(&zm, &zbf); + ret = _z_network_message_decode(&zm, &zbf); if (ret == _Z_RES_OK) { _z_handle_network_message(ztu->_session, &zm, _Z_KEYEXPR_MAPPING_UNKNOWN_REMOTE); _z_msg_clear(&zm); // Clear must be explicitly called for fragmented zenoh messages. Non-fragmented diff --git a/src/utils/encoding.c b/src/utils/encoding.c index 085511bdf..0fb93f978 100644 --- a/src/utils/encoding.c +++ b/src/utils/encoding.c @@ -51,7 +51,7 @@ size_t _z_cobs_decode(const uint8_t *input, size_t input_len, uint8_t *output) { uint8_t *pos = output; uint8_t code = (uint8_t)0xFF; - const uint8_t *input_end_ptr = _z_cptr_u8_offset(input, input_len); + const uint8_t *input_end_ptr = _z_cptr_u8_offset(input, (ptrdiff_t)input_len); for (uint8_t block = (uint8_t)0x00; byte < input_end_ptr; block--) { if (block != (uint8_t)0x00) { *pos = *byte; diff --git a/src/utils/pointers.c b/src/utils/pointers.c index 2e1bd4b08..77c05628f 100644 --- a/src/utils/pointers.c +++ b/src/utils/pointers.c @@ -14,13 +14,13 @@ #include "zenoh-pico/utils/pointers.h" -size_t _z_ptr_u8_diff(const uint8_t *l_ptr, const uint8_t *r_ptr) { return l_ptr - r_ptr; } +size_t _z_ptr_u8_diff(const uint8_t *l_ptr, const uint8_t *r_ptr) { return (size_t)(l_ptr - r_ptr); } const uint8_t *_z_cptr_u8_offset(const uint8_t *ptr, const ptrdiff_t off) { return ptr + off; } uint8_t *_z_ptr_u8_offset(uint8_t *ptr, const ptrdiff_t off) { return ptr + off; } -size_t _z_ptr_char_diff(const char *l_ptr, const char *r_ptr) { return l_ptr - r_ptr; } +size_t _z_ptr_char_diff(const char *l_ptr, const char *r_ptr) { return (size_t)(l_ptr - r_ptr); } const char *_z_cptr_char_offset(const char *ptr, const ptrdiff_t off) { return ptr + off; } diff --git a/src/utils/string.c b/src/utils/string.c index e95e3ab07..512ae2310 100644 --- a/src/utils/string.c +++ b/src/utils/string.c @@ -26,7 +26,7 @@ char const *_z_rstrstr(char const *haystack_start, char const *haystack_end, con char const *he = haystack_end; const char *needle_end = strchr(needle_start, 0); - hs = _z_cptr_char_offset(hs, _z_ptr_char_diff(needle_end, needle_start)); + hs = _z_cptr_char_offset(hs, (ptrdiff_t)_z_ptr_char_diff(needle_end, needle_start)); char const *result = NULL; while ((result == false) && (he >= hs)) { char found = 1; @@ -50,7 +50,7 @@ char const *_z_rstrstr(char const *haystack_start, char const *haystack_end, con } char const *_z_bstrstr(_z_str_se_t haystack, _z_str_se_t needle) { - haystack.end = _z_cptr_char_offset(haystack.end, -1 * _z_ptr_char_diff(needle.end, needle.start)); + haystack.end = _z_cptr_char_offset(haystack.end, -1 * (ptrdiff_t)_z_ptr_char_diff(needle.end, needle.start)); char const *result = NULL; for (; (result == false) && (haystack.start <= haystack.end); haystack.start = _z_cptr_char_offset(haystack.start, 1)) { @@ -86,7 +86,7 @@ char const *_z_strstr_skipneedle(char const *haystack_start, char const *haystac char const *_z_bstrstr_skipneedle(_z_str_se_t haystack, _z_str_se_t needle) { char const *result = _z_bstrstr(haystack, needle); if (result != NULL) { - result = _z_cptr_char_offset(result, _z_ptr_char_diff(needle.end, needle.start)); + result = _z_cptr_char_offset(result, (ptrdiff_t)_z_ptr_char_diff(needle.end, needle.start)); } return result; } @@ -102,7 +102,7 @@ _z_str_se_t _z_splitstr_next(_z_splitstr_t *str) { if (result.end == str->s.end) { str->s = (_z_str_se_t){.start = NULL, .end = NULL}; } else { - str->s.start = _z_cptr_char_offset(result.end, strlen(str->delimiter)); + str->s.start = _z_cptr_char_offset(result.end, (ptrdiff_t)strlen(str->delimiter)); } } return result; @@ -122,7 +122,7 @@ _z_str_se_t _z_splitstr_nextback(_z_splitstr_t *str) { if (result.start == str->s.start) { str->s = (_z_str_se_t){.start = NULL, .end = NULL}; } else { - str->s.end = _z_cptr_char_offset(result.start, -1 * strlen(str->delimiter)); + str->s.end = _z_cptr_char_offset(result.start, -1 * (ptrdiff_t)strlen(str->delimiter)); } } return result; diff --git a/tests/z_api_alignment_test.c b/tests/z_api_alignment_test.c index aa5f634ae..7a1d233f2 100644 --- a/tests/z_api_alignment_test.c +++ b/tests/z_api_alignment_test.c @@ -226,7 +226,7 @@ int main(int argc, char **argv) { assert_eq(_ret_int8, 0); assert(hellos >= 1); - uint32_t _scouting_timeout = strtoul(SCOUTING_TIMEOUT, NULL, 10); + uint32_t _scouting_timeout = (uint32_t)strtoul(SCOUTING_TIMEOUT, NULL, 10); z_sleep_ms(_scouting_timeout); printf("Ok\n"); z_sleep_s(SLEEP);