diff --git a/examples/arduino/z_get.ino b/examples/arduino/z_get.ino index bd9ab841f..9df8af2f8 100644 --- a/examples/arduino/z_get.ino +++ b/examples/arduino/z_get.ino @@ -111,7 +111,8 @@ void loop() { Serial.print("Sending Query "); Serial.print(KEYEXPR); Serial.println(" ..."); - z_get_options_t opts = z_get_options_default(); + z_get_options_t opts; + z_get_options_default(&opts); if (strcmp(VALUE, "") != 0) { opts.value.payload = _z_bytes_wrap((const uint8_t *)VALUE, strlen(VALUE)); } diff --git a/examples/espidf/z_get.c b/examples/espidf/z_get.c index cd69bc600..180de1d61 100644 --- a/examples/espidf/z_get.c +++ b/examples/espidf/z_get.c @@ -156,7 +156,8 @@ void app_main() { while (1) { sleep(5); printf("Sending Query '%s'...\n", KEYEXPR); - z_get_options_t opts = z_get_options_default(); + z_get_options_t opts; + z_get_options_default(&opts); if (strcmp(VALUE, "") != 0) { opts.value.payload = _z_bytes_wrap((const uint8_t *)VALUE, strlen(VALUE)); } diff --git a/examples/freertos_plus_tcp/z_get.c b/examples/freertos_plus_tcp/z_get.c index 97c49dd79..c3473901e 100644 --- a/examples/freertos_plus_tcp/z_get.c +++ b/examples/freertos_plus_tcp/z_get.c @@ -80,7 +80,8 @@ void app_main(void) { while (1) { z_sleep_s(5); printf("Sending Query '%s'...\n", KEYEXPR); - z_get_options_t opts = z_get_options_default(); + z_get_options_t opts; + z_get_options_default(&opts); if (strcmp(VALUE, "") != 0) { opts.value.payload = _z_bytes_wrap((const uint8_t *)VALUE, strlen(VALUE)); } diff --git a/examples/freertos_plus_tcp/z_queryable.c b/examples/freertos_plus_tcp/z_queryable.c index c962f5107..edf173db2 100644 --- a/examples/freertos_plus_tcp/z_queryable.c +++ b/examples/freertos_plus_tcp/z_queryable.c @@ -39,7 +39,8 @@ void query_handler(const z_query_t *query, void *ctx) { if (payload_value.payload.len > 0) { printf(" with value '%.*s'\n", (int)payload_value.payload.len, payload_value.payload.start); } - z_query_reply_options_t options = z_query_reply_options_default(); + z_query_reply_options_t options; + z_query_reply_options_default(&options); options.encoding = z_encoding(Z_ENCODING_PREFIX_TEXT_PLAIN, NULL); z_query_reply(query, z_keyexpr(KEYEXPR), (const unsigned char *)VALUE, strlen(VALUE), &options); z_drop(z_move(keystr)); diff --git a/examples/mbed/z_get.cpp b/examples/mbed/z_get.cpp index f88d4224b..9bf56cdcd 100644 --- a/examples/mbed/z_get.cpp +++ b/examples/mbed/z_get.cpp @@ -76,7 +76,8 @@ int main(int argc, char **argv) { while (1) { z_sleep_s(5); printf("Sending Query '%s'...\n", KEYEXPR); - z_get_options_t opts = z_get_options_default(); + z_get_options_t opts; + z_get_options_default(&opts); if (strcmp(VALUE, "") != 0) { opts.value.payload = _z_bytes_wrap((const uint8_t *)VALUE, strlen(VALUE)); } diff --git a/examples/unix/c11/z_get.c b/examples/unix/c11/z_get.c index 27bc5631b..42fbb1a92 100644 --- a/examples/unix/c11/z_get.c +++ b/examples/unix/c11/z_get.c @@ -128,7 +128,8 @@ int main(int argc, char **argv) { z_mutex_lock(&mutex); printf("Sending Query '%s'...\n", keyexpr); - z_get_options_t opts = z_get_options_default(); + z_get_options_t opts; + z_get_options_default(&opts); if (value != NULL) { opts.value.payload = _z_bytes_wrap((const uint8_t *)value, strlen(value)); } diff --git a/examples/unix/c11/z_get_channel.c b/examples/unix/c11/z_get_channel.c index e1de0b0da..2ad10ba85 100644 --- a/examples/unix/c11/z_get_channel.c +++ b/examples/unix/c11/z_get_channel.c @@ -88,7 +88,8 @@ int main(int argc, char **argv) { } printf("Sending Query '%s'...\n", keyexpr); - z_get_options_t opts = z_get_options_default(); + z_get_options_t opts; + z_get_options_default(&opts); if (value != NULL) { opts.value.payload = _z_bytes_wrap((const uint8_t *)value, strlen(value)); } diff --git a/examples/unix/c11/z_queryable.c b/examples/unix/c11/z_queryable.c index 8bfe513ef..8876ddffd 100644 --- a/examples/unix/c11/z_queryable.c +++ b/examples/unix/c11/z_queryable.c @@ -49,7 +49,8 @@ void query_handler(const z_query_t *query, void *ctx) { } #endif - z_query_reply_options_t options = z_query_reply_options_default(); + z_query_reply_options_t options; + z_query_reply_options_default(&options); options.encoding = z_encoding(Z_ENCODING_PREFIX_TEXT_PLAIN, NULL); #if Z_FEATURE_ATTACHMENT == 1 diff --git a/examples/unix/c11/z_queryable_channel.c b/examples/unix/c11/z_queryable_channel.c index aff9a9d4c..e568a2b17 100644 --- a/examples/unix/c11/z_queryable_channel.c +++ b/examples/unix/c11/z_queryable_channel.c @@ -107,7 +107,8 @@ int main(int argc, char **argv) { if (payload_value.payload.len > 0) { printf(" with value '%.*s'\n", (int)payload_value.payload.len, payload_value.payload.start); } - z_query_reply_options_t options = z_query_reply_options_default(); + z_query_reply_options_t options; + z_query_reply_options_default(&options); options.encoding = z_encoding(Z_ENCODING_PREFIX_TEXT_PLAIN, NULL); z_query_reply(&q, z_keyexpr(keyexpr), (const unsigned char *)value, strlen(value), &options); z_drop(z_move(keystr)); diff --git a/examples/unix/c99/z_get.c b/examples/unix/c99/z_get.c index 8d58fef63..dbfbca469 100644 --- a/examples/unix/c99/z_get.c +++ b/examples/unix/c99/z_get.c @@ -114,7 +114,8 @@ int main(int argc, char **argv) { z_mutex_lock(&mutex); printf("Sending Query '%s'...\n", keyexpr); - z_get_options_t opts = z_get_options_default(); + z_get_options_t opts; + z_get_options_default(&opts); if (value != NULL) { opts.value.payload = _z_bytes_wrap((const uint8_t *)value, strlen(value)); } diff --git a/examples/unix/c99/z_queryable.c b/examples/unix/c99/z_queryable.c index 1d28562fc..404a16add 100644 --- a/examples/unix/c99/z_queryable.c +++ b/examples/unix/c99/z_queryable.c @@ -28,7 +28,8 @@ void query_handler(const z_query_t *query, void *ctx) { z_keyexpr_to_string(z_query_keyexpr(query), &keystr); z_bytes_t pred = z_query_parameters(query); printf(" >> [Queryable handler] Received Query '%s%.*s'\n", z_str_loan(&keystr), (int)pred.len, pred.start); - z_query_reply_options_t options = z_query_reply_options_default(); + z_query_reply_options_t options; + z_query_reply_options_default(&options); options.encoding = z_encoding(Z_ENCODING_PREFIX_TEXT_PLAIN, NULL); z_query_reply(query, z_keyexpr(keyexpr), (const unsigned char *)value, strlen(value), &options); z_str_drop(z_str_move(&keystr)); diff --git a/examples/windows/z_get.c b/examples/windows/z_get.c index a633fd07b..c7461f60f 100644 --- a/examples/windows/z_get.c +++ b/examples/windows/z_get.c @@ -79,7 +79,8 @@ int main(int argc, char **argv) { z_mutex_lock(&mutex); printf("Sending Query '%s'...\n", keyexpr); - z_get_options_t opts = z_get_options_default(); + z_get_options_t opts; + z_get_options_default(&opts); if (value != NULL) { opts.value.payload = _z_bytes_wrap((const uint8_t *)value, strlen(value)); } diff --git a/examples/windows/z_queryable.c b/examples/windows/z_queryable.c index a42bd26cd..f7065ca71 100644 --- a/examples/windows/z_queryable.c +++ b/examples/windows/z_queryable.c @@ -31,7 +31,8 @@ void query_handler(const z_query_t *query, void *ctx) { if (payload_value.payload.len > 0) { printf(" with value '%.*s'\n", (int)payload_value.payload.len, payload_value.payload.start); } - z_query_reply_options_t options = z_query_reply_options_default(); + z_query_reply_options_t options; + z_query_reply_options_default(&options); options.encoding = z_encoding(Z_ENCODING_PREFIX_TEXT_PLAIN, NULL); z_query_reply(query, z_keyexpr(keyexpr), (const unsigned char *)value, strlen(value), &options); z_drop(z_move(keystr)); diff --git a/examples/zephyr/z_get.c b/examples/zephyr/z_get.c index 8c0ef5340..cb243a675 100644 --- a/examples/zephyr/z_get.c +++ b/examples/zephyr/z_get.c @@ -72,7 +72,8 @@ int main(int argc, char **argv) { while (1) { sleep(5); printf("Sending Query '%s'...\n", KEYEXPR); - z_get_options_t opts = z_get_options_default(); + z_get_options_t opts; + z_get_options_default(&opts); opts.target = Z_QUERY_TARGET_ALL; z_owned_closure_reply_t callback; z_closure(&callback, reply_handler, reply_dropper); diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index 456e70160..a47bb6f1a 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -1026,7 +1026,7 @@ int8_t z_publisher_delete(const z_publisher_t pub, const z_publisher_delete_opti * Returns: * Returns the constructed :c:type:`z_get_options_t`. */ -z_get_options_t z_get_options_default(void); +void z_get_options_default(z_get_options_t *options); /** * Issues a distributed query for a given keyexpr. @@ -1092,7 +1092,7 @@ z_value_t z_reply_err(const z_owned_reply_t *reply); * Returns: * Returns the constructed :c:type:`z_queryable_options_t`. */ -z_queryable_options_t z_queryable_options_default(void); +void z_queryable_options_default(z_queryable_options_t *options); /** * Declares a queryable for the given keyexpr. @@ -1143,7 +1143,7 @@ int8_t z_undeclare_queryable(z_owned_queryable_t *queryable); * Returns: * Returns the constructed :c:type:`z_query_reply_options_t`. */ -z_query_reply_options_t z_query_reply_options_default(void); +void z_query_reply_options_default(z_query_reply_options_t *options); /** * Sends a reply to a query. @@ -1221,7 +1221,7 @@ int8_t z_undeclare_keyexpr(z_session_t zs, z_owned_keyexpr_t *keyexpr); * Returns: * Returns the constructed :c:type:`z_subscriber_options_t`. */ -z_subscriber_options_t z_subscriber_options_default(void); +void z_subscriber_options_default(z_subscriber_options_t *options); /** * Declares a (push) subscriber for the given keyexpr. diff --git a/src/api/api.c b/src/api/api.c index eccfe37b2..7410bc563 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -805,15 +805,15 @@ z_owned_keyexpr_t z_publisher_keyexpr(z_publisher_t publisher) { #if Z_FEATURE_QUERY == 1 OWNED_FUNCTIONS_PTR_INTERNAL(z_reply_t, z_owned_reply_t, reply, _z_reply_free, _z_owner_noop_copy) -z_get_options_t z_get_options_default(void) { - return (z_get_options_t) { - .target = z_query_target_default(), .consolidation = z_query_consolidation_default(), - .value = {.encoding = z_encoding_default(), .payload = _z_bytes_empty()}, +void z_get_options_default(z_get_options_t *options) { + options->target = z_query_target_default(); + options->consolidation = z_query_consolidation_default(); + options->value.encoding = z_encoding_default(); + options->value.payload = _z_bytes_empty(); #if Z_FEATURE_ATTACHMENT == 1 - .attachment = z_attachment_null(), + options->attachment = z_attachment_null(); #endif - .timeout_ms = Z_GET_TIMEOUT_DEFAULT - }; + options->timeout_ms = Z_GET_TIMEOUT_DEFAULT; } typedef struct __z_reply_handler_wrapper_t { @@ -835,7 +835,8 @@ int8_t z_get(z_session_t zs, z_keyexpr_t keyexpr, const char *parameters, z_owne void *ctx = callback->context; callback->context = NULL; - z_get_options_t opt = z_get_options_default(); + z_get_options_t opt; + z_get_options_default(&opt); if (options != NULL) { opt.consolidation = options->consolidation; opt.target = options->target; @@ -894,9 +895,7 @@ OWNED_FUNCTIONS_PTR_COMMON(z_queryable_t, z_owned_queryable_t, queryable) OWNED_FUNCTIONS_PTR_CLONE(z_queryable_t, z_owned_queryable_t, queryable, _z_owner_noop_copy) void z_queryable_drop(z_owned_queryable_t *val) { z_undeclare_queryable(val); } -z_queryable_options_t z_queryable_options_default(void) { - return (z_queryable_options_t){.complete = _Z_QUERYABLE_COMPLETE_DEFAULT}; -} +void z_queryable_options_default(z_queryable_options_t *options) { options->complete = _Z_QUERYABLE_COMPLETE_DEFAULT; } z_owned_queryable_t z_declare_queryable(z_session_t zs, z_keyexpr_t keyexpr, z_owned_closure_query_t *callback, const z_queryable_options_t *options) { @@ -916,7 +915,8 @@ z_owned_queryable_t z_declare_queryable(z_session_t zs, z_keyexpr_t keyexpr, z_o } } - z_queryable_options_t opt = z_queryable_options_default(); + z_queryable_options_t opt; + z_queryable_options_default(&opt); if (options != NULL) { opt.complete = options->complete; } @@ -933,13 +933,16 @@ int8_t z_undeclare_queryable(z_owned_queryable_t *queryable) { return ret; } -z_query_reply_options_t z_query_reply_options_default(void) { - return (z_query_reply_options_t){.encoding = z_encoding_default()}; -} +void z_query_reply_options_default(z_query_reply_options_t *options) { options->encoding = z_encoding_default(); } int8_t z_query_reply(const z_query_t *query, const z_keyexpr_t keyexpr, const uint8_t *payload, size_t payload_len, const z_query_reply_options_t *options) { - z_query_reply_options_t opts = options == NULL ? z_query_reply_options_default() : *options; + z_query_reply_options_t opts; + if (options == NULL) { + z_query_reply_options_default(&opts); + } else { + opts = *options; + } _z_value_t value = {.payload = { .start = payload, @@ -989,9 +992,7 @@ OWNED_FUNCTIONS_PTR_COMMON(z_subscriber_t, z_owned_subscriber_t, subscriber) OWNED_FUNCTIONS_PTR_CLONE(z_subscriber_t, z_owned_subscriber_t, subscriber, _z_owner_noop_copy) void z_subscriber_drop(z_owned_subscriber_t *val) { z_undeclare_subscriber(val); } -z_subscriber_options_t z_subscriber_options_default(void) { - return (z_subscriber_options_t){.reliability = Z_RELIABILITY_DEFAULT}; -} +void z_subscriber_options_default(z_subscriber_options_t *options) { options->reliability = Z_RELIABILITY_DEFAULT; } int8_t z_declare_subscriber(z_owned_subscriber_t *sub, z_session_t zs, z_keyexpr_t keyexpr, z_owned_closure_sample_t *callback, const z_subscriber_options_t *options) { diff --git a/tests/z_api_alignment_test.c b/tests/z_api_alignment_test.c index 0e490ba62..6ff3bd7c1 100644 --- a/tests/z_api_alignment_test.c +++ b/tests/z_api_alignment_test.c @@ -77,7 +77,8 @@ void query_handler(const z_query_t *query, void *arg) { (void)(pred); z_value_t payload_value = z_query_value(query); (void)(payload_value); - z_query_reply_options_t _ret_qreply_opt = z_query_reply_options_default(); + z_query_reply_options_t _ret_qreply_opt; + z_query_reply_options_default(&_ret_qreply_opt); z_query_reply(query, z_keyexpr(z_loan(k_str)), (const uint8_t *)value, strlen(value), &_ret_qreply_opt); z_drop(z_move(k_str)); @@ -287,7 +288,8 @@ int main(int argc, char **argv) { printf("Declaring Subscriber..."); z_owned_closure_sample_t _ret_closure_sample; z_closure(&_ret_closure_sample, data_handler, NULL, &ls1); - z_subscriber_options_t _ret_sub_opt = z_subscriber_options_default(); + z_subscriber_options_t _ret_sub_opt; + z_subscriber_options_default(&_ret_sub_opt); z_owned_subscriber_t _ret_sub; _ret_int8 = z_declare_subscriber(&_ret_sub, z_loan(s2), z_keyexpr(keyexpr_str), z_move(_ret_closure_sample), &_ret_sub_opt); @@ -304,7 +306,8 @@ int main(int argc, char **argv) { printf("Ok\n"); printf("Session Put..."); - z_put_options_t _ret_put_opt = z_put_options_default(); + z_put_options_t _ret_put_opt; + z_put_options_default(&_ret_put_opt); _ret_put_opt.congestion_control = Z_CONGESTION_CONTROL_BLOCK; z_encoding_t _ret_encoding = z_encoding_default(); (void)(_ret_encoding); @@ -385,7 +388,8 @@ int main(int argc, char **argv) { printf("Declaring Queryable..."); z_owned_closure_query_t _ret_closure_query; z_closure(&_ret_closure_query, query_handler, NULL, &ls1); - z_queryable_options_t _ret_qle_opt = z_queryable_options_default(); + z_queryable_options_t _ret_qle_opt; + z_queryable_options_default(&_ret_qle_opt); z_owned_queryable_t qle = z_declare_queryable(z_loan(s1), z_keyexpr(s1_res), z_move(_ret_closure_query), &_ret_qle_opt); assert(z_check(qle)); @@ -397,7 +401,8 @@ int main(int argc, char **argv) { z_session_t ls2 = z_loan(s2); z_owned_closure_reply_t _ret_closure_reply; z_closure(&_ret_closure_reply, reply_handler, NULL, &ls2); - z_get_options_t _ret_get_opt = z_get_options_default(); + z_get_options_t _ret_get_opt; + z_get_options_default(&_ret_get_opt); _ret_get_opt.target = z_query_target_default(); _ret_get_opt.consolidation = z_query_consolidation_auto(); (void)(_ret_get_opt.consolidation);