From c1b0c3344057e96e1499116e5403d03b5911360d Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Thu, 22 Aug 2024 16:41:55 +0200 Subject: [PATCH] feat: remove obsolete functions --- docs/api.rst | 2 -- include/zenoh-pico/api/primitives.h | 27 --------------------------- src/api/api.c | 25 ++++++------------------- src/session/resource.c | 3 +-- tests/z_api_alignment_test.c | 9 --------- tests/z_keyexpr_test.c | 4 ++-- tools/z_keyexpr_canonizer.c | 2 +- 7 files changed, 10 insertions(+), 62 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index 092fc719a..1fea537d1 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -288,9 +288,7 @@ Primitives .. autocfunction:: primitives.h::z_view_keyexpr_from_str_autocanonize .. autocfunction:: primitives.h::z_keyexpr_as_view_string .. autocfunction:: primitives.h::z_keyexpr_is_canon -.. autocfunction:: primitives.h::zp_keyexpr_is_canon_null_terminated .. autocfunction:: primitives.h::z_keyexpr_canonize -.. autocfunction:: primitives.h::zp_keyexpr_canonize_null_terminated .. autocfunction:: primitives.h::z_keyexpr_includes .. autocfunction:: primitives.h::z_keyexpr_intersects .. autocfunction:: primitives.h::z_keyexpr_equals diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index 43a58414f..93dfa50ec 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -160,19 +160,6 @@ z_keyexpr_intersection_level_t z_keyexpr_relation_to(const z_loaned_keyexpr_t *l */ int8_t z_keyexpr_is_canon(const char *start, size_t len); -/** - * Checks if a given keyexpr is valid and in canonical form. - * - * Parameters: - * start: Pointer to the keyexpr in its string representation as a null terminated string. - * len: Number of characters in ``start``. - * - * Return: - * ``0`` if passed string is a valid (and canon) key expression, or a ``negative value`` otherwise. - * Error codes are defined in :c:enum:`zp_keyexpr_canon_status_t`. - */ -int8_t zp_keyexpr_is_canon_null_terminated(const char *start); - /** * Canonizes of a given keyexpr in string representation. * The canonization is performed over the passed string, possibly shortening it by modifying ``len``. @@ -187,20 +174,6 @@ int8_t zp_keyexpr_is_canon_null_terminated(const char *start); */ int8_t z_keyexpr_canonize(char *start, size_t *len); -/** - * Canonizes a given keyexpr in string representation. - * The canonization is performed over the passed string, possibly shortening it by modifying ``len``. - * - * Parameters: - * start: Pointer to the keyexpr in its string representation as a null terminated string. - * len: Number of characters in ``start``. - * - * Return: - * ``0`` if canonization successful, or a ``negative value`` otherwise. - * Error codes are defined in :c:enum:`zp_keyexpr_canon_status_t`. - */ -int8_t zp_keyexpr_canonize_null_terminated(char *start); - /** * Checks if a given keyexpr contains another keyexpr in its set. * diff --git a/src/api/api.c b/src/api/api.c index e6d0c8d85..f6f2d3080 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -61,18 +61,9 @@ size_t z_string_array_len(const z_loaned_string_array_t *a) { return _z_string_s _Bool z_string_array_is_empty(const z_loaned_string_array_t *a) { return _z_string_svec_is_empty(a); } -int8_t zp_keyexpr_canonize_null_terminated(char *start) { - zp_keyexpr_canon_status_t ret = Z_KEYEXPR_CANON_SUCCESS; - - size_t len = strlen(start); - size_t newlen = len; - ret = _z_keyexpr_canonize(start, &newlen); - if (newlen < len) { - start[newlen] = '\0'; - } +int8_t z_keyexpr_is_canon(const char *start, size_t len) { return _z_keyexpr_is_canon(start, len); } - return ret; -} +int8_t z_keyexpr_canonize(char *start, size_t *len) { return _z_keyexpr_canonize(start, len); } int8_t z_view_keyexpr_from_str(z_view_keyexpr_t *keyexpr, const char *name) { keyexpr->_val = _z_rname(name); @@ -80,8 +71,10 @@ int8_t z_view_keyexpr_from_str(z_view_keyexpr_t *keyexpr, const char *name) { } int8_t z_view_keyexpr_from_str_autocanonize(z_view_keyexpr_t *keyexpr, char *name) { - _Z_RETURN_IF_ERR(zp_keyexpr_canonize_null_terminated(name)); - keyexpr->_val = _z_rname(name); + size_t name_len = strlen(name); + _Z_RETURN_IF_ERR(z_keyexpr_canonize(name, &name_len)); + keyexpr->_val = _z_rname(NULL); + keyexpr->_val._suffix = _z_string_from_substr(name, name_len); return _Z_RES_OK; } @@ -154,12 +147,6 @@ z_keyexpr_intersection_level_t z_keyexpr_relation_to(const z_loaned_keyexpr_t *l return Z_KEYEXPR_INTERSECTION_LEVEL_DISJOINT; } -int8_t z_keyexpr_is_canon(const char *start, size_t len) { return _z_keyexpr_is_canon(start, len); } - -int8_t zp_keyexpr_is_canon_null_terminated(const char *start) { return _z_keyexpr_is_canon(start, strlen(start)); } - -int8_t z_keyexpr_canonize(char *start, size_t *len) { return _z_keyexpr_canonize(start, len); } - _Bool z_keyexpr_includes(const z_loaned_keyexpr_t *l, const z_loaned_keyexpr_t *r) { return _z_keyexpr_suffix_includes(l, r); } diff --git a/src/session/resource.c b/src/session/resource.c index 4f2d8f62d..3c165266e 100644 --- a/src/session/resource.c +++ b/src/session/resource.c @@ -88,8 +88,7 @@ _z_resource_t *__z_get_resource_by_key(_z_resource_list_t *rl, const _z_keyexpr_ } _z_keyexpr_t __z_get_expanded_key_from_key(_z_resource_list_t *xs, const _z_keyexpr_t *keyexpr) { - _z_keyexpr_t ret = { - ._id = Z_RESOURCE_ID_NONE, ._suffix = _z_string_null(), ._mapping = _z_keyexpr_mapping(0)}; + _z_keyexpr_t ret = {._id = Z_RESOURCE_ID_NONE, ._suffix = _z_string_null(), ._mapping = _z_keyexpr_mapping(0)}; // Need to build the complete resource name, by recursively look at RIDs // Resource names are looked up from right to left diff --git a/tests/z_api_alignment_test.c b/tests/z_api_alignment_test.c index 783963bed..c90a27238 100644 --- a/tests/z_api_alignment_test.c +++ b/tests/z_api_alignment_test.c @@ -154,18 +154,9 @@ int main(int argc, char **argv) { int8_t _ret_int8 = z_keyexpr_is_canon(keyexpr_str, keyexpr_len); assert(_ret_int8 < 0); -#ifdef ZENOH_PICO - _ret_int8 = zp_keyexpr_is_canon_null_terminated(keyexpr_str); - assert(_ret_int8 < 0); -#endif _ret_int8 = z_keyexpr_canonize(keyexpr_str, &keyexpr_len); assert_eq(_ret_int8, 0); assert_eq(strlen(URI), keyexpr_len); -#ifdef ZENOH_PICO - _ret_int8 = zp_keyexpr_canonize_null_terminated(keyexpr_str); - assert_eq(_ret_int8, 0); - assert_eq(strlen(URI), keyexpr_len); -#endif printf("Ok\n"); z_sleep_s(SLEEP); diff --git a/tests/z_keyexpr_test.c b/tests/z_keyexpr_test.c index 10377b56e..764f69941 100644 --- a/tests/z_keyexpr_test.c +++ b/tests/z_keyexpr_test.c @@ -322,13 +322,13 @@ void test_canonize(void) { memset(canon, 0, 128); strncpy(canon, ke, 128); size_t canon_len = strlen(canon); - zp_keyexpr_canon_status_t status = zp_keyexpr_canonize_null_terminated(canon); + zp_keyexpr_canon_status_t status = z_keyexpr_canonize(canon, &canon_len); printf("%s ", ke); printf(" Status: %d : %d", status, expected[i]); assert(status == expected[i]); if (status == Z_KEYEXPR_CANON_SUCCESS) { printf(" Match: %.*s : %s", (int)canon_len, canon, canonized[i]); - assert(strcmp(canonized[i], canon) == 0); + assert(strncmp(canonized[i], canon, canon_len) == 0); } printf("\n"); } diff --git a/tools/z_keyexpr_canonizer.c b/tools/z_keyexpr_canonizer.c index 239152648..c03c4f63a 100644 --- a/tools/z_keyexpr_canonizer.c +++ b/tools/z_keyexpr_canonizer.c @@ -33,7 +33,7 @@ int main(int argc, char **argv) { buffer = realloc(buffer, len + 1); strncpy(buffer, argv[i], len); buffer[len] = '\0'; - zp_keyexpr_canon_status_t status = zp_keyexpr_canonize_null_terminated(buffer); + zp_keyexpr_canon_status_t status = z_keyexpr_canonized(buffer, len)); switch (status) { case Z_KEYEXPR_CANON_SUCCESS: