Skip to content

Commit

Permalink
feat: remove obsolete functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Aug 22, 2024
1 parent f35e4f1 commit c1b0c33
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 62 deletions.
2 changes: 0 additions & 2 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 0 additions & 27 deletions include/zenoh-pico/api/primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand All @@ -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.
*
Expand Down
25 changes: 6 additions & 19 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,20 @@ 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);
return _Z_RES_OK;
}

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;
}

Expand Down Expand Up @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions src/session/resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions tests/z_api_alignment_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/z_keyexpr_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion tools/z_keyexpr_canonizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit c1b0c33

Please sign in to comment.