Skip to content

Commit

Permalink
Merge branch 'main' into feature/platform-primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisBiryukov91 authored Feb 28, 2024
2 parents 33d7448 + 1e36616 commit b75fed0
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 43 deletions.
59 changes: 32 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ Subscribe
#include "zenoh.h"
void data_handler(const z_sample_t *sample, const void *arg) {
char *keystr = z_keyexpr_to_string(sample->keyexpr);
z_owned_str_t keystr = z_keyexpr_to_string(sample->keyexpr);
printf(">> Received (%s, %.*s)\n",
keystr, (int)sample->payload.len, sample->payload.start);
free(keystr);
z_drop(z_move(keystr));
}
int main(int argc, char **argv) {
Expand Down Expand Up @@ -87,9 +87,9 @@ Query
if (z_reply_is_ok(&reply))
{
z_sample_t sample = z_reply_ok(&reply);
char *keystr = z_keyexpr_to_string(sample.keyexpr);
z_owned_str_t keystr = z_keyexpr_to_string(sample.keyexpr);
printf(">> Received ('%s': '%.*s')\n", keystr, (int)sample.payload.len, sample.payload.start);
free(keystr);
z_drop(z_move(keystr));
}
}
Expand Down
8 changes: 4 additions & 4 deletions examples/z_ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int main(int argc, char** argv) {
z_owned_publisher_t pub = z_declare_publisher(z_loan(session), ping, NULL);
z_owned_closure_sample_t respond = z_closure(callback, drop, (void*)(&pub));
z_owned_subscriber_t sub = z_declare_subscriber(z_loan(session), pong, z_move(respond), NULL);
uint8_t* data = malloc(args.size);
uint8_t* data = z_malloc(args.size);
for (int i = 0; i < args.size; i++) {
data[i] = i % 10;
}
Expand All @@ -75,7 +75,7 @@ int main(int argc, char** argv) {
}
}
struct timespec t_start, t_stop, t_timeout;
unsigned long* results = malloc(sizeof(unsigned long) * args.number_of_pings);
unsigned long* results = z_malloc(sizeof(unsigned long) * args.number_of_pings);
for (int i = 0; i < args.number_of_pings; i++) {
clock_gettime(CLOCK_REALTIME, &t_timeout);
t_timeout.tv_sec += PING_TIMEOUT_SEC;
Expand All @@ -92,8 +92,8 @@ int main(int argc, char** argv) {
printf("%d bytes: seq=%d rtt=%luµs, lat=%luµs\n", args.size, i, results[i], results[i] / 2);
}
z_mutex_unlock(&mutex);
free(results);
free(data);
z_free(results);
z_free(data);
z_drop(z_move(sub));
z_drop(z_move(pub));
z_close(z_move(session));
Expand Down
2 changes: 1 addition & 1 deletion examples/z_pub_thr.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int main(int argc, char **argv) {

char *keyexpr = "test/thr";
size_t len = atoi(argv[1]);
uint8_t *value = (uint8_t *)malloc(len);
uint8_t *value = (uint8_t *)z_malloc(len);
memset(value, 1, len);

z_owned_config_t config = z_config_default();
Expand Down
4 changes: 2 additions & 2 deletions examples/z_scout.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ void callback(z_owned_hello_t *hello, void *context) {
void drop(void *context) {
printf("Dropping scout\n");
int count = *(int *)context;
free(context);
z_free(context);
if (!count) {
printf("Did not find any zenoh process.\n");
}
}

int main(int argc, char **argv) {
int *context = malloc(sizeof(int));
int *context = z_malloc(sizeof(int));
*context = 0;
z_owned_scouting_config_t config = z_scouting_config_default();
z_owned_closure_hello_t closure = z_closure(callback, drop, context);
Expand Down
4 changes: 2 additions & 2 deletions examples/z_sub_thr.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ typedef struct {
} z_stats_t;

z_stats_t *z_stats_make() {
z_stats_t *stats = malloc(sizeof(z_stats_t));
z_stats_t *stats = z_malloc(sizeof(z_stats_t));
stats->count = 0;
stats->finished_rounds = 0;
stats->first_start.tv_nsec = 0;
Expand Down Expand Up @@ -63,7 +63,7 @@ void drop_stats(void *context) {
double elapsed_s = get_elapsed_s(&stats->first_start, &end);
printf("Stats being dropped after unsubscribing: sent %ld messages over %f seconds (%f msg/s)\n", sent_messages,
elapsed_s, (double)sent_messages / elapsed_s);
free(context);
z_free(context);
}

int main(int argc, char **argv) {
Expand Down
1 change: 1 addition & 0 deletions include/zenoh.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ extern "C" {
}
#endif
#include "zenoh_macros.h"
#include "zenoh_memory.h"
#endif
Loading

0 comments on commit b75fed0

Please sign in to comment.