diff options
author | Mitya Selivanov <0x7fffff@guattari.ru> | 2022-08-15 07:08:35 +0400 |
---|---|---|
committer | Mitya Selivanov <0x7fffff@guattari.ru> | 2022-08-15 07:08:35 +0400 |
commit | cfbefecf8f033c838aa7f325b400b2b949f81838 (patch) | |
tree | 9235ebf1f6b97ba51f9f257a5bc249390139c4fd /source | |
parent | 90259625e45c3e4cb26af3c30fffdb182d08dba1 (diff) | |
download | kit-cfbefecf8f033c838aa7f325b400b2b949f81838.zip |
explicit coroutine init with size
Diffstat (limited to 'source')
-rw-r--r-- | source/kit/async_function.h | 12 | ||||
-rw-r--r-- | source/test/unittests/async_function.test.c | 2 |
2 files changed, 7 insertions, 7 deletions
diff --git a/source/kit/async_function.h b/source/kit/async_function.h index 0fa565a..5ae9ade 100644 --- a/source/kit/async_function.h +++ b/source/kit/async_function.h @@ -1,6 +1,8 @@ #ifndef KIT_ASYNC_FUNCTION_H #define KIT_ASYNC_FUNCTION_H +#include <string.h> + #ifdef __cplusplus extern "C" { #endif @@ -156,12 +158,10 @@ typedef struct { (promise_) = kit_af_temp_; \ } while (0) -#define KIT_AF_INIT_EXPLICIT(promise_, coro_func_) \ - do { \ - (promise_)._index = 0; \ - (promise_)._state_machine = (coro_func_); \ - (promise_)._context.state = NULL; \ - (promise_)._context.execute = NULL; \ +#define KIT_AF_INIT_EXPLICIT(promise_, size_, coro_func_) \ + do { \ + memset(&(promise_), 0, size_); \ + (promise_)._state_machine = (coro_func_); \ } while (0) #define KIT_AF_EXECUTION_CONTEXT(promise_, ...) \ diff --git a/source/test/unittests/async_function.test.c b/source/test/unittests/async_function.test.c index f4571a0..1ff3031 100644 --- a/source/test/unittests/async_function.test.c +++ b/source/test/unittests/async_function.test.c @@ -86,7 +86,7 @@ TEST("coroutine init") { TEST("coroutine init explicit") { AF_TYPE(test_foo) promise; - AF_INIT_EXPLICIT(promise, AF_NAME(test_foo)); + AF_INIT_EXPLICIT(promise, sizeof promise, AF_NAME(test_foo)); REQUIRE(!AF_FINISHED(promise)); } |