From b619064e2bf899ca3c7704d4139784af3ce117cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Plewa?= Date: Thu, 25 Aug 2022 16:31:08 +0200 Subject: [PATCH] Squashed 'src/deps/miniasync/' changes from f3b809217..a8d51f0a4 a8d51f0a4 Merge pull request #111 from kswiecicki/kw-issues b1efa1c99 Merge pull request #109 from KFilipek/add-casting dc88b63a0 masync: fix hashmap memory allocation 97055b841 masync: assert hashmap example copied value 701844c99 masync: fix hashmap example allocation checking 93b1698ff masync: fix hashmap example cleanup 7fa75e02f masync: avoid casting error on C++ compilation git-subtree-dir: src/deps/miniasync git-subtree-split: a8d51f0a46d8143cbbc5ac8ca272ad3ba19fed6e --- examples/hashmap/hashmap.c | 16 +++++++++++++++- src/include/libminiasync/future.h | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/examples/hashmap/hashmap.c b/examples/hashmap/hashmap.c index c8599e92601..b923203f45f 100644 --- a/examples/hashmap/hashmap.c +++ b/examples/hashmap/hashmap.c @@ -119,7 +119,7 @@ hashmap_new(size_t capacity) return NULL; } - struct hashmap *hm = malloc(sizeof(struct hashmap) * capacity); + struct hashmap *hm = malloc(sizeof(struct hashmap)); if (hm == NULL) { return NULL; } @@ -1149,13 +1149,26 @@ main(void) char other_val[] = "Coffee"; struct hashmap *hm = hashmap_new(4); + if (hm == NULL) { + printf("failed to allocate a new hashmap.\n"); + return 1; + } /* Create a runtime instance for efficient future polling */ struct runtime *r = runtime_new(); + if (r == NULL) { + hashmap_delete(hm); + + printf("failed to allocate a new runtime.\n"); + return 1; + } /* Create a thread mover to be used for data move operations */ struct data_mover_threads *dmt = data_mover_threads_default(); if (dmt == NULL) { + runtime_delete(r); + hashmap_delete(hm); + printf("failed to allocate data mover.\n"); return 1; } @@ -1249,6 +1262,7 @@ main(void) /* Entry with '4' key should store value 'Buzz' */ struct hashmap_get_copy_output *get_copy_output = FUTURE_OUTPUT(&get_futs[0]); + assert(strcmp(buf, val_4) == 0); assert(get_copy_output->value == buf); assert(get_copy_output->size == strlen(val_4) + 1); /* 'hashmap_get_copy_fut' will not copy more data than buffer can fit */ diff --git a/src/include/libminiasync/future.h b/src/include/libminiasync/future.h index de396adeb9d..72be055a7a0 100644 --- a/src/include/libminiasync/future.h +++ b/src/include/libminiasync/future.h @@ -388,7 +388,7 @@ future_has_property_default(void *future, enum future_property property) static inline int future_chain_has_property(void *future, enum future_property property) { - struct future *fut = future; + struct future *fut = (struct future *)future; struct future_context *ctx = &fut->context; uint8_t *data = (uint8_t *)future_context_get_data(ctx); struct future_chain_entry *entry = (struct future_chain_entry *)(data);