Skip to content

Commit

Permalink
_z_check/null renamed to z_internal (#599)
Browse files Browse the repository at this point in the history
* _z_check/null renamed to z_internal

* macro fix

* test fix

* macros corrected

* test fix

* tests fix

* clang format
  • Loading branch information
milyin authored Aug 20, 2024
1 parent 51c0491 commit cf62926
Show file tree
Hide file tree
Showing 12 changed files with 214 additions and 213 deletions.
2 changes: 1 addition & 1 deletion include/zenoh-pico/api/handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ extern "C" {
/* elem_clone_f */ z_##item_name##_clone, \
/* elem_move_f */ z_##item_name##_move, \
/* elem_drop_f */ z_##item_name##_drop, \
/* elem_null */ _z_owned_##item_name##_null)
/* elem_null */ z_internal_##item_name##_null)

#define _Z_CHANNEL_DEFINE_DUMMY(item_name, kind_name) \
typedef struct { \
Expand Down
184 changes: 92 additions & 92 deletions include/zenoh-pico/api/macros.h

Large diffs are not rendered by default.

114 changes: 57 additions & 57 deletions include/zenoh-pico/api/olv_macros.h

Large diffs are not rendered by default.

35 changes: 18 additions & 17 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ int8_t z_keyexpr_as_view_string(const z_loaned_keyexpr_t *keyexpr, z_view_string
}

int8_t z_keyexpr_concat(z_owned_keyexpr_t *key, const z_loaned_keyexpr_t *left, const char *right, size_t len) {
_z_owned_keyexpr_null(key);
z_internal_keyexpr_null(key);
if (len == 0) {
return z_keyexpr_clone(key, left);
} else if (right == NULL) {
Expand Down Expand Up @@ -124,7 +124,7 @@ int8_t z_keyexpr_concat(z_owned_keyexpr_t *key, const z_loaned_keyexpr_t *left,
}

int8_t z_keyexpr_join(z_owned_keyexpr_t *key, const z_loaned_keyexpr_t *left, const z_loaned_keyexpr_t *right) {
_z_owned_keyexpr_null(key);
z_internal_keyexpr_null(key);

size_t left_len = strlen(left->_suffix);
size_t right_len = strlen(right->_suffix);
Expand Down Expand Up @@ -376,7 +376,7 @@ _Z_OWNED_FUNCTIONS_VALUE_IMPL(_z_encoding_t, encoding, _z_encoding_check, _z_enc

int8_t z_encoding_from_str(z_owned_encoding_t *encoding, const char *s) {
// Init owned encoding
_z_owned_encoding_null(encoding);
z_internal_encoding_null(encoding);
// Convert string to encoding
if (s != NULL) {
return _z_encoding_convert_from_substr(encoding, s, strlen(s));
Expand All @@ -386,7 +386,7 @@ int8_t z_encoding_from_str(z_owned_encoding_t *encoding, const char *s) {

int8_t z_encoding_from_substr(z_owned_encoding_t *encoding, const char *s, size_t len) {
// Init owned encoding
_z_owned_encoding_null(encoding);
z_internal_encoding_null(encoding);
// Convert string to encoding
if (s != NULL) {
return _z_encoding_convert_from_substr(encoding, s, len);
Expand All @@ -411,7 +411,7 @@ int8_t z_encoding_set_schema_from_substr(z_loaned_encoding_t *encoding, const ch

int8_t z_encoding_to_string(const z_loaned_encoding_t *encoding, z_owned_string_t *s) {
// Init owned string
_z_owned_string_null(s);
z_internal_string_null(s);
// Convert encoding to string
_z_encoding_convert_into_string(encoding, s);
return _Z_RES_OK;
Expand Down Expand Up @@ -487,7 +487,7 @@ int8_t z_bytes_deserialize_into_slice(const z_loaned_bytes_t *bytes, z_owned_sli

int8_t z_bytes_deserialize_into_string(const z_loaned_bytes_t *bytes, z_owned_string_t *s) {
// Init owned string
_z_owned_string_null(s);
z_internal_string_null(s);
// Convert bytes to string
size_t len = _z_bytes_len(bytes);
s->_val = _z_string_preallocate(len);
Expand Down Expand Up @@ -912,13 +912,13 @@ int8_t z_scout(z_moved_config_t *config, z_moved_closure_hello_t *callback, cons
} else {
ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY;
}
_z_owned_closure_hello_null(&callback->_this);
z_internal_closure_hello_null(&callback->_this);

return ret;
}

int8_t z_open(z_owned_session_t *zs, z_moved_config_t *config) {
_z_owned_session_null(zs);
z_internal_session_null(zs);
_z_session_t *s = z_malloc(sizeof(_z_session_t));
if (s == NULL) {
z_config_drop(config);
Expand All @@ -937,7 +937,7 @@ int8_t z_open(z_owned_session_t *zs, z_moved_config_t *config) {
int8_t ret = _z_open(&zs->_rc, &config->_this._val);
if (ret != _Z_RES_OK) {
_z_session_rc_decr(&zs->_rc);
_z_owned_session_null(zs);
z_internal_session_null(zs);
z_config_drop(config);
return ret;
}
Expand All @@ -947,7 +947,7 @@ int8_t z_open(z_owned_session_t *zs, z_moved_config_t *config) {
}

int8_t z_close(z_moved_session_t *zs) {
if (zs == NULL || !_z_owned_session_check(&zs->_this)) {
if (zs == NULL || !z_internal_session_check(&zs->_this)) {
return _Z_RES_OK;
}
z_session_drop(zs);
Expand All @@ -971,7 +971,7 @@ int8_t z_info_peers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_t *cal
if (callback->_this._val.drop != NULL) {
callback->_this._val.drop(ctx);
}
_z_owned_closure_zid_null(&callback->_this);
z_internal_closure_zid_null(&callback->_this);
return 0;
}

Expand All @@ -991,7 +991,7 @@ int8_t z_info_routers_zid(const z_loaned_session_t *zs, z_moved_closure_zid_t *c
if (callback->_this._val.drop != NULL) {
callback->_this._val.drop(ctx);
}
_z_owned_closure_zid_null(&callback->_this);
z_internal_closure_zid_null(&callback->_this);
return 0;
}

Expand Down Expand Up @@ -1306,7 +1306,8 @@ int8_t z_get(const z_loaned_session_t *zs, const z_loaned_keyexpr_t *keyexpr, co
z_bytes_drop(opt.payload);
z_encoding_drop(opt.encoding);
z_bytes_drop(opt.attachment);
_z_owned_closure_reply_null(&callback->_this); // call and drop passed to _z_query, so we nullify the closure here
z_internal_closure_reply_null(
&callback->_this); // call and drop passed to _z_query, so we nullify the closure here
return ret;
}

Expand Down Expand Up @@ -1372,7 +1373,7 @@ int8_t z_declare_queryable(z_owned_queryable_t *queryable, const z_loaned_sessio
queryable->_val =
_z_declare_queryable(zs, key, opt.complete, callback->_this._val.call, callback->_this._val.drop, ctx);

_z_owned_closure_query_null(&callback->_this);
z_internal_closure_query_null(&callback->_this);
return _Z_RES_OK;
}

Expand Down Expand Up @@ -1486,7 +1487,7 @@ int8_t z_keyexpr_from_str_autocanonize(z_owned_keyexpr_t *key, const char *name)
}

int8_t z_keyexpr_from_substr_autocanonize(z_owned_keyexpr_t *key, const char *name, size_t *len) {
_z_owned_keyexpr_null(key);
z_internal_keyexpr_null(key);
char *name_copy = _z_str_n_clone(name, *len);
if (name_copy == NULL) {
return _Z_ERR_SYSTEM_OUT_OF_MEMORY;
Expand All @@ -1504,7 +1505,7 @@ int8_t z_keyexpr_from_str(z_owned_keyexpr_t *key, const char *name) {
}

int8_t z_keyexpr_from_substr(z_owned_keyexpr_t *key, const char *name, size_t len) {
_z_owned_keyexpr_null(key);
z_internal_keyexpr_null(key);
char *name_copy = _z_str_n_clone(name, len);
if (name_copy == NULL) {
return _Z_ERR_SYSTEM_OUT_OF_MEMORY;
Expand Down Expand Up @@ -1605,7 +1606,7 @@ int8_t z_declare_subscriber(z_owned_subscriber_t *sub, const z_loaned_session_t
if (suffix != NULL) {
z_free(suffix);
}
_z_owned_closure_sample_null(&callback->_this);
z_internal_closure_sample_null(&callback->_this);
sub->_val = int_sub;

if (!_z_subscriber_check(&sub->_val)) {
Expand Down
22 changes: 11 additions & 11 deletions tests/z_api_alignment_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ int main(int argc, char **argv) {
printf("Testing Configs...");
z_owned_config_t _ret_config;
z_config_new(&_ret_config);
assert(!_z_check(_ret_config)); // null config corresponds to empty one
assert(!z_internal_check(_ret_config)); // null config corresponds to empty one
z_drop(z_move(_ret_config));
z_config_default(&_ret_config);
assert(_z_check(_ret_config));
assert(z_internal_check(_ret_config));
#ifdef ZENOH_PICO
_ret_int8 = zp_config_insert(z_loan_mut(_ret_config), Z_CONFIG_CONNECT_KEY, argv[1]);
assert_eq(_ret_int8, 0);
Expand All @@ -200,7 +200,7 @@ int main(int argc, char **argv) {

z_owned_config_t _ret_sconfig;
z_config_default(&_ret_sconfig);
assert(_z_check(_ret_sconfig));
assert(z_internal_check(_ret_sconfig));

printf("Ok\n");
z_sleep_s(SLEEP);
Expand All @@ -219,7 +219,7 @@ int main(int argc, char **argv) {

z_owned_session_t s1;
z_open(&s1, z_move(_ret_config));
assert(_z_check(s1));
assert(z_internal_check(s1));
z_id_t _ret_zid = z_info_zid(z_loan(s1));
printf("Session 1 with PID: 0x");
for (unsigned long i = 0; i < sizeof(_ret_zid); i++) {
Expand Down Expand Up @@ -263,7 +263,7 @@ int main(int argc, char **argv) {

z_owned_session_t s2;
z_open(&s2, z_move(_ret_config));
assert(_z_check(s2));
assert(z_internal_check(s2));
_ret_zid = z_info_zid(z_loan(s2));
printf("Session 2 with PID: 0x");
for (unsigned long i = 0; i < sizeof(_ret_zid); i++) {
Expand Down Expand Up @@ -300,7 +300,7 @@ int main(int argc, char **argv) {
z_view_keyexpr_from_str(&s1_key, s1_res);
z_owned_keyexpr_t _ret_expr;
z_declare_keyexpr(&_ret_expr, z_loan(s1), z_loan(s1_key));
assert(_z_check(_ret_expr));
assert(z_internal_check(_ret_expr));
printf("Ok\n");

printf("Session Put...");
Expand All @@ -317,7 +317,7 @@ int main(int argc, char **argv) {

_ret_int8 = z_put(z_loan(s1), z_loan(_ret_expr), z_move(payload), &_ret_put_opt);
assert_eq(_ret_int8, 0);
assert(!_z_check(encoding));
assert(!z_internal_check(encoding));
printf("Ok\n");

z_sleep_s(SLEEP);
Expand All @@ -338,7 +338,7 @@ int main(int argc, char **argv) {
_ret_int8 = z_undeclare_keyexpr(z_move(_ret_expr), z_loan(s1));
printf(" %02x\n", _ret_int8);
assert_eq(_ret_int8, 0);
assert(!_z_check(_ret_expr));
assert(!z_internal_check(_ret_expr));
printf("Ok\n");

printf("Declaring Publisher...");
Expand All @@ -350,7 +350,7 @@ int main(int argc, char **argv) {
z_owned_publisher_t _ret_pub;
_ret_int8 = z_declare_publisher(&_ret_pub, z_loan(s1), z_loan(s1_key), &_ret_pub_opt);
assert(_ret_int8 == _Z_RES_OK);
assert(!_z_check(encoding));
assert(!z_internal_check(encoding));
printf("Ok\n");

z_sleep_s(SLEEP);
Expand Down Expand Up @@ -381,15 +381,15 @@ int main(int argc, char **argv) {
printf("Undeclaring Publisher...");
_ret_int8 = z_undeclare_publisher(z_move(_ret_pub));
assert_eq(_ret_int8, 0);
assert(!_z_check(_ret_pub));
assert(!z_internal_check(_ret_pub));
printf("Ok\n");

z_sleep_s(SLEEP);

printf("Undeclaring Subscriber...");
_ret_int8 = z_undeclare_subscriber(z_move(_ret_sub));
assert_eq(_ret_int8, 0);
assert(!_z_check(_ret_sub));
assert(!z_internal_check(_ret_sub));
printf("Ok\n");

z_sleep_s(SLEEP);
Expand Down
4 changes: 2 additions & 2 deletions tests/z_api_bytes_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,14 @@ void test_slice(void) {
z_owned_slice_t s;
z_slice_copy_from_buf(&s, data, 10);
z_bytes_serialize_from_slice(&payload2, z_slice_loan(&s));
assert(_z_owned_slice_check(&s));
assert(z_internal_slice_check(&s));
z_slice_drop(z_slice_move(&s));
assert(z_check_and_drop_payload(&payload2, data, 10));

z_owned_bytes_t payload3;
z_slice_copy_from_buf(&s, data, 10);
z_bytes_from_slice(&payload3, z_slice_move(&s));
assert(!_z_owned_slice_check(&s));
assert(!z_internal_slice_check(&s));
assert(z_check_and_drop_payload(&payload3, data, 10));

z_owned_bytes_t payload4;
Expand Down
6 changes: 3 additions & 3 deletions tests/z_api_config_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void config_client(void) {
const char *locator = "tcp/127.0.0.1";
z_owned_config_t config;
assert(0 == z_config_client(&config, locator));
assert(_z_owned_config_check(&config));
assert(z_internal_config_check(&config));
assert(strcmp(zp_config_get(z_config_loan(&config), Z_CONFIG_MODE_KEY), Z_CONFIG_MODE_CLIENT) == 0);
assert(strcmp(zp_config_get(z_config_loan(&config), Z_CONFIG_CONNECT_KEY), locator) == 0);
z_config_drop(z_config_move(&config));
Expand All @@ -35,12 +35,12 @@ void config_peer(void) {
const char *locator = "udp/228.0.0.4:7447#iface=en0";
z_owned_config_t config;
assert(0 == z_config_peer(&config, locator));
assert(_z_owned_config_check(&config));
assert(z_internal_config_check(&config));
assert(strcmp(zp_config_get(z_config_loan(&config), Z_CONFIG_MODE_KEY), Z_CONFIG_MODE_PEER) == 0);
assert(strcmp(zp_config_get(z_config_loan(&config), Z_CONFIG_CONNECT_KEY), locator) == 0);
z_config_drop(z_config_move(&config));
assert(0 != z_config_peer(&config, NULL));
assert(!_z_owned_config_check(&config));
assert(!z_internal_config_check(&config));
}

int main(void) {
Expand Down
12 changes: 6 additions & 6 deletions tests/z_api_double_drop_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@
void test_keyexpr(void) {
z_owned_keyexpr_t keyexpr;
z_keyexpr_from_str(&keyexpr, URL);
assert(_z_check(keyexpr));
assert(z_internal_check(keyexpr));
z_drop(z_move(keyexpr));
assert(!_z_check(keyexpr));
assert(!z_internal_check(keyexpr));
z_drop(z_move(keyexpr));
assert(!_z_check(keyexpr));
assert(!z_internal_check(keyexpr));
}

void test_config(void) {
z_owned_config_t config;
z_config_default(&config);
assert(_z_check(config));
assert(z_internal_check(config));
z_drop(z_move(config));
assert(!_z_check(config));
assert(!z_internal_check(config));
z_drop(z_move(config));
assert(!_z_check(config));
assert(!z_internal_check(config));
}

int main(void) {
Expand Down
18 changes: 9 additions & 9 deletions tests/z_api_encoding_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

void test_null_encoding(void) {
z_owned_encoding_t e;
_z_owned_encoding_null(&e);
assert(!_z_owned_encoding_check(&e));
z_internal_encoding_null(&e);
assert(!z_internal_encoding_check(&e));
z_encoding_drop(z_encoding_move(&e));
}

void test_encoding_without_id(void) {
z_owned_encoding_t e1;
z_encoding_from_str(&e1, "my_encoding");
assert(_z_owned_encoding_check(&e1));
assert(z_internal_encoding_check(&e1));
z_owned_string_t s;
z_encoding_to_string(z_encoding_loan(&e1), &s);
assert(strncmp("zenoh/bytes;my_encoding", z_string_data(z_string_loan(&s)), z_string_len(z_string_loan(&s))) == 0);
Expand All @@ -27,7 +27,7 @@ void test_encoding_without_id(void) {

z_owned_encoding_t e2;
z_encoding_from_substr(&e2, "my_encoding", 4);
assert(_z_owned_encoding_check(&e2));
assert(z_internal_encoding_check(&e2));

z_encoding_to_string(z_encoding_loan(&e2), &s);
assert(strncmp("zenoh/bytes;my_e", z_string_data(z_string_loan(&s)), z_string_len(z_string_loan(&s))) == 0);
Expand All @@ -38,7 +38,7 @@ void test_encoding_without_id(void) {
void test_encoding_with_id(void) {
z_owned_encoding_t e1;
z_encoding_from_str(&e1, "zenoh/string;utf8");
assert(_z_owned_encoding_check(&e1));
assert(z_internal_encoding_check(&e1));
z_owned_string_t s;
z_encoding_to_string(z_encoding_loan(&e1), &s);
assert(strncmp("zenoh/string;utf8", z_string_data(z_string_loan(&s)), z_string_len(z_string_loan(&s))) == 0);
Expand All @@ -47,7 +47,7 @@ void test_encoding_with_id(void) {

z_owned_encoding_t e2;
z_encoding_from_substr(&e2, "zenoh/string;utf8", 15);
assert(_z_owned_encoding_check(&e2));
assert(z_internal_encoding_check(&e2));

z_encoding_to_string(z_encoding_loan(&e2), &s);
assert(strncmp("zenoh/string;utf8", z_string_data(z_string_loan(&s)), z_string_len(z_string_loan(&s))) == 0);
Expand All @@ -56,7 +56,7 @@ void test_encoding_with_id(void) {

z_owned_encoding_t e3;
z_encoding_from_str(&e3, "custom_id;custom_schema");
assert(_z_owned_encoding_check(&e3));
assert(z_internal_encoding_check(&e3));

z_encoding_to_string(z_encoding_loan(&e3), &s);
assert(strncmp("zenoh/bytes;custom_id;custom_schema", z_string_data(z_string_loan(&s)),
Expand All @@ -66,7 +66,7 @@ void test_encoding_with_id(void) {

z_owned_encoding_t e4;
z_encoding_from_substr(&e4, "custom_id;custom_schema", 16);
assert(_z_owned_encoding_check(&e2));
assert(z_internal_encoding_check(&e2));

z_encoding_to_string(z_encoding_loan(&e4), &s);
assert(strncmp("zenoh/bytes;custom_id;custom", z_string_data(z_string_loan(&s)), z_string_len(z_string_loan(&s))) ==
Expand All @@ -77,7 +77,7 @@ void test_encoding_with_id(void) {

void test_with_schema(void) {
z_owned_encoding_t e;
_z_owned_encoding_null(&e);
z_internal_encoding_null(&e);
z_encoding_set_schema_from_str(z_encoding_loan_mut(&e), "my_schema");

z_owned_string_t s;
Expand Down
Loading

0 comments on commit cf62926

Please sign in to comment.