Skip to content

Commit

Permalink
Fix compilation issues (#431)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jean-roland authored Jun 20, 2024
1 parent 079228f commit 60ff708
Show file tree
Hide file tree
Showing 63 changed files with 346 additions and 457 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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$
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/multicast.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
73 changes: 39 additions & 34 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion examples/unix/c11/z_pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
28 changes: 15 additions & 13 deletions include/zenoh-pico/api/handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions include/zenoh-pico/collections/fifo_mt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions include/zenoh-pico/collections/ring_mt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion include/zenoh-pico/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
88 changes: 0 additions & 88 deletions include/zenoh-pico/deprecated/platform.h

This file was deleted.

2 changes: 1 addition & 1 deletion include/zenoh-pico/link/config/bt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
#endif /* ZENOH_PICO_LINK_CONFIG_BT_H */
2 changes: 1 addition & 1 deletion include/zenoh-pico/link/config/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
#endif /* ZENOH_PICO_LINK_CONFIG_SERIAL_H */
2 changes: 1 addition & 1 deletion include/zenoh-pico/protocol/definitions/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
2 changes: 1 addition & 1 deletion include/zenoh-pico/session/push.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
#endif /* ZENOH_PICO_SESSION_PUSH_H */
2 changes: 1 addition & 1 deletion include/zenoh-pico/session/reply.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
#endif /* ZENOH_PICO_SESSION_REPLY_H */
2 changes: 1 addition & 1 deletion include/zenoh-pico/session/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions include/zenoh-pico/system/link/raweth.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion include/zenoh-pico/system/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <stdint.h>

#include "zenoh-pico/config.h"
#include "zenoh-pico/deprecated/platform.h"
#include "zenoh-pico/system/platform-common.h"

#endif /* ZENOH_PICO_SYSTEM_PLATFORM_H */
Loading

0 comments on commit 60ff708

Please sign in to comment.