Skip to content

Commit

Permalink
Cleaning up code (#323)
Browse files Browse the repository at this point in the history
* fix: missing newline on task start fail log

* feat: uniformize c99 pub example with c11 one

* fix: free session is task start fail

* fix: unitiialized data issue

* fix: clean up if declare keyexpr fail in z_put

* fix: run Wconversion on c11 examples

* fix: run Wconversion on tests

* fix: run Wconversion on c99 examples

* build: add commented debug options
  • Loading branch information
jean-roland authored Jan 19, 2024
1 parent b48d2c1 commit f0ba603
Show file tree
Hide file tree
Showing 44 changed files with 139 additions and 89 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ endif()
if(CMAKE_BUILD_TYPE MATCHES "DEBUG")
if(UNIX)
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")
Expand Down
1 change: 1 addition & 0 deletions examples/freertos_plus_tcp/z_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void app_main(void) {
// Start read and lease tasks for zenoh-pico
if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) {
printf("Unable to start read and lease tasks\n");
z_close(z_session_move(&s));
return;
}

Expand Down
1 change: 1 addition & 0 deletions examples/freertos_plus_tcp/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ void app_main(void) {
// Start read and lease tasks for zenoh-pico
if (zp_start_read_task(z_loan(s), &read_task_opt) < 0 || zp_start_lease_task(z_loan(s), &lease_task_opt) < 0) {
printf("Unable to start read and lease tasks\n");
z_close(z_session_move(&s));
return;
}

Expand Down
1 change: 1 addition & 0 deletions examples/freertos_plus_tcp/z_pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void app_main(void) {
// Start read and lease tasks for zenoh-pico
if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) {
printf("Unable to start read and lease tasks\n");
z_close(z_session_move(&s));
return;
}

Expand Down
8 changes: 5 additions & 3 deletions examples/freertos_plus_tcp/z_put.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@ void app_main(void) {
// Start read and lease tasks for zenoh-pico
if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) {
printf("Unable to start read and lease tasks\n");
z_close(z_session_move(&s));
return;
}

printf("Declaring key expression '%s'...\n", KEYEXPR);
z_owned_keyexpr_t ke = z_declare_keyexpr(z_loan(s), z_keyexpr(KEYEXPR));
if (!z_check(ke)) {
printf("Unable to declare key expression!\n");
zp_stop_read_task(z_loan(s));
zp_stop_lease_task(z_loan(s));
z_close(z_move(s));
return;
}

Expand All @@ -67,12 +71,10 @@ void app_main(void) {
zp_sleep_s(1);
}

// Clean up
z_undeclare_keyexpr(z_loan(s), z_move(ke));

// Stop read and lease tasks for zenoh-pico
zp_stop_read_task(z_loan(s));
zp_stop_lease_task(z_loan(s));

z_close(z_move(s));
}
#else
Expand Down
1 change: 1 addition & 0 deletions examples/freertos_plus_tcp/z_queryable.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ void app_main(void) {
// Start read and lease tasks for zenoh-pico
if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) {
printf("Unable to start read and lease tasks\n");
z_close(z_session_move(&s));
return;
}

Expand Down
1 change: 1 addition & 0 deletions examples/freertos_plus_tcp/z_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void app_main(void) {
// Start read and lease tasks for zenoh-pico
if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) {
printf("Unable to start read and lease tasks\n");
z_close(z_session_move(&s));
return;
}

Expand Down
3 changes: 2 additions & 1 deletion examples/unix/c11/z_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ int main(int argc, char **argv) {

// Start read and lease tasks for zenoh-pico
if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) {
printf("Unable to start read and lease tasks");
printf("Unable to start read and lease tasks\n");
z_close(z_session_move(&s));
return -1;
}

Expand Down
3 changes: 2 additions & 1 deletion examples/unix/c11/z_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ int main(int argc, char **argv) {

// Start read and lease tasks for zenoh-pico
if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) {
printf("Unable to start read and lease tasks");
printf("Unable to start read and lease tasks\n");
z_close(z_session_move(&s));
return -1;
}

Expand Down
11 changes: 6 additions & 5 deletions examples/unix/c11/z_ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ int main(int argc, char** argv) {
}

if (zp_start_read_task(z_loan(session), NULL) < 0 || zp_start_lease_task(z_loan(session), NULL) < 0) {
printf("Unable to start read and lease tasks");
printf("Unable to start read and lease tasks\n");
z_close(z_session_move(&session));
return -1;
}

Expand All @@ -93,7 +94,7 @@ int main(int argc, char** argv) {

uint8_t* data = zp_malloc(args.size);
for (unsigned int i = 0; i < args.size; i++) {
data[i] = i % 10;
data[i] = (uint8_t)(i % 10);
}
zp_mutex_lock(&mutex);
if (args.warmup_ms) {
Expand Down Expand Up @@ -151,17 +152,17 @@ struct args_t parse_args(int argc, char** argv) {
char* arg = getopt(argc, argv, 's');
unsigned int size = DEFAULT_PKT_SIZE;
if (arg) {
size = atoi(arg);
size = (unsigned int)atoi(arg);
}
arg = getopt(argc, argv, 'n');
unsigned int number_of_pings = DEFAULT_PING_NB;
if (arg) {
number_of_pings = atoi(arg);
number_of_pings = (unsigned int)atoi(arg);
}
arg = getopt(argc, argv, 'w');
unsigned int warmup_ms = DEFAULT_WARMUP_MS;
if (arg) {
warmup_ms = atoi(arg);
warmup_ms = (unsigned int)atoi(arg);
}
return (struct args_t){
.help_requested = 0,
Expand Down
3 changes: 2 additions & 1 deletion examples/unix/c11/z_pong.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ int main(int argc, char** argv) {
}

if (zp_start_read_task(z_loan(session), NULL) < 0 || zp_start_lease_task(z_loan(session), NULL) < 0) {
printf("Unable to start read and lease tasks");
printf("Unable to start read and lease tasks\n");
z_close(z_session_move(&session));
return -1;
}

Expand Down
3 changes: 2 additions & 1 deletion examples/unix/c11/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ int main(int argc, char **argv) {

// Start read and lease tasks for zenoh-pico
if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) {
printf("Unable to start read and lease tasks");
printf("Unable to start read and lease tasks\n");
z_close(z_session_move(&s));
return -1;
}

Expand Down
5 changes: 3 additions & 2 deletions examples/unix/c11/z_pub_thr.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int main(int argc, char **argv) {
exit(-1);
}
char *keyexpr = "test/thr";
size_t len = atoi(argv[1]);
size_t len = (size_t)atoi(argv[1]);
uint8_t *value = (uint8_t *)malloc(len);
memset(value, 1, len);

Expand All @@ -45,7 +45,8 @@ int main(int argc, char **argv) {
}
// Start read and lease tasks for zenoh-pico
if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) {
printf("Unable to start read and lease tasks");
printf("Unable to start read and lease tasks\n");
z_close(z_session_move(&s));
exit(-1);
}
// Declare publisher
Expand Down
3 changes: 2 additions & 1 deletion examples/unix/c11/z_pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ int main(int argc, char **argv) {

// Start read and lease tasks for zenoh-pico
if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) {
printf("Unable to start read and lease tasks");
printf("Unable to start read and lease tasks\n");
z_close(z_session_move(&s));
return -1;
}

Expand Down
20 changes: 12 additions & 8 deletions examples/unix/c11/z_put.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,20 @@ int main(int argc, char **argv) {

// Start read and lease tasks for zenoh-pico
if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) {
printf("Unable to start read and lease tasks");
printf("Unable to start read and lease tasks\n");
z_close(z_session_move(&s));
return -1;
}

printf("Declaring key expression '%s'...\n", keyexpr);
// z_owned_keyexpr_t ke = z_declare_keyexpr(z_loan(s), z_keyexpr(keyexpr));
// if (!z_check(ke)) {
// printf("Unable to declare key expression!\n");
// return -1;
// }
z_owned_keyexpr_t ke = z_declare_keyexpr(z_loan(s), z_keyexpr(keyexpr));
if (!z_check(ke)) {
printf("Unable to declare key expression!\n");
zp_stop_read_task(z_loan(s));
zp_stop_lease_task(z_loan(s));
z_close(z_move(s));
return -1;
}

printf("Putting Data ('%s': '%s')...\n", keyexpr, value);
z_put_options_t options = z_put_options_default();
Expand All @@ -105,9 +109,9 @@ int main(int argc, char **argv) {
#if Z_FEATURE_ATTACHMENT == 1
z_bytes_map_drop(&map);
#endif
// z_undeclare_keyexpr(z_loan(s), z_move(ke));

// Stop read and lease tasks for zenoh-pico
// Clean up
z_undeclare_keyexpr(z_loan(s), z_move(ke));
zp_stop_read_task(z_loan(s));
zp_stop_lease_task(z_loan(s));
z_close(z_move(s));
Expand Down
3 changes: 2 additions & 1 deletion examples/unix/c11/z_queryable.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ int main(int argc, char **argv) {

// Start read and lease tasks for zenoh-pico
if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) {
printf("Unable to start read and lease tasks");
printf("Unable to start read and lease tasks\n");
z_close(z_session_move(&s));
return -1;
}

Expand Down
3 changes: 2 additions & 1 deletion examples/unix/c11/z_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ int main(int argc, char **argv) {

// Start read and lease tasks for zenoh-pico
if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) {
printf("Unable to start read and lease tasks");
printf("Unable to start read and lease tasks\n");
z_close(z_session_move(&s));
return -1;
}

Expand Down
5 changes: 3 additions & 2 deletions examples/unix/c11/z_sub_thr.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ int main(int argc, char **argv) {
}
// Start read and lease tasks for zenoh-pico
if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) {
printf("Unable to start read and lease tasks");
printf("Unable to start read and lease tasks\n");
z_close(z_session_move(&s));
exit(-1);
}
// Declare Subscriber/resource
Expand All @@ -101,7 +102,7 @@ int main(int argc, char **argv) {
printf("Start listening.\n");
char c = 0;
while (c != 'q') {
c = fgetc(stdin);
c = (char)fgetc(stdin);
}
// Wait for everything to settle
printf("End of test\n");
Expand Down
3 changes: 2 additions & 1 deletion examples/unix/c99/z_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ int main(int argc, char **argv) {

// Start read and lease tasks for zenoh-pico
if (zp_start_read_task(z_session_loan(&s), NULL) < 0 || zp_start_lease_task(z_session_loan(&s), NULL) < 0) {
printf("Unable to start read and lease tasks");
printf("Unable to start read and lease tasks\n");
z_close(z_session_move(&s));
return -1;
}

Expand Down
3 changes: 2 additions & 1 deletion examples/unix/c99/z_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ int main(int argc, char **argv) {

// Start read and lease tasks for zenoh-pico
if (zp_start_read_task(z_session_loan(&s), NULL) < 0 || zp_start_lease_task(z_session_loan(&s), NULL) < 0) {
printf("Unable to start read and lease tasks");
printf("Unable to start read and lease tasks\n");
z_close(z_session_move(&s));
return -1;
}

Expand Down
11 changes: 6 additions & 5 deletions examples/unix/c99/z_ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ int main(int argc, char** argv) {

if (zp_start_read_task(z_session_loan(&session), NULL) < 0 ||
zp_start_lease_task(z_session_loan(&session), NULL) < 0) {
printf("Unable to start read and lease tasks");
printf("Unable to start read and lease tasks\n");
z_close(z_session_move(&session));
return -1;
}

Expand All @@ -95,7 +96,7 @@ int main(int argc, char** argv) {

uint8_t* data = zp_malloc(args.size);
for (unsigned int i = 0; i < args.size; i++) {
data[i] = i % 10;
data[i] = (uint8_t)(i % 10);
}
zp_mutex_lock(&mutex);
if (args.warmup_ms) {
Expand Down Expand Up @@ -153,17 +154,17 @@ struct args_t parse_args(int argc, char** argv) {
char* arg = getopt(argc, argv, 's');
unsigned int size = DEFAULT_PKT_SIZE;
if (arg) {
size = atoi(arg);
size = (unsigned int)atoi(arg);
}
arg = getopt(argc, argv, 'n');
unsigned int number_of_pings = DEFAULT_PING_NB;
if (arg) {
number_of_pings = atoi(arg);
number_of_pings = (unsigned int)atoi(arg);
}
arg = getopt(argc, argv, 'w');
unsigned int warmup_ms = DEFAULT_WARMUP_MS;
if (arg) {
warmup_ms = atoi(arg);
warmup_ms = (unsigned int)atoi(arg);
}
return (struct args_t){
.help_requested = 0,
Expand Down
3 changes: 2 additions & 1 deletion examples/unix/c99/z_pong.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ int main(int argc, char** argv) {

if (zp_start_read_task(z_session_loan(&session), NULL) < 0 ||
zp_start_lease_task(z_session_loan(&session), NULL) < 0) {
printf("Unable to start read and lease tasks");
printf("Unable to start read and lease tasks\n");
z_close(z_session_move(&session));
return -1;
}

Expand Down
Loading

0 comments on commit f0ba603

Please sign in to comment.