diff --git a/includes/ziti/model_support.h b/includes/ziti/model_support.h index 11c207f3..79b7aa4f 100644 --- a/includes/ziti/model_support.h +++ b/includes/ziti/model_support.h @@ -117,7 +117,7 @@ return rc;\ int parse_##type##_array(array(type) *a, const char *json, size_t len) { return model_parse_array((void***)a, json, len, &type##_META); }\ ptr(type) alloc_##type() { return (ptr(type))calloc(1, sizeof(type)); } \ int cmp_##type(const type *lh, const type *rh) { return model_cmp(lh, rh, &type##_META); }\ -void free_##type(type *v) { model_free(v, &type##_META); } \ +void free_##type(ptr(type) v) { model_free(v, &type##_META); } \ void free_##type##_array(array(type) *ap) { model_free_array((void***)ap, &type##_META); } \ MODEL_API ssize_t type##_to_json_r(const ptr(type) v, int flags, char *outbuf, size_t max) { \ return model_to_json_r(v, &type##_META, flags, outbuf, max); } \ @@ -202,19 +202,19 @@ typedef struct model_map { struct model_impl_s *impl; } model_map; -ZITI_FUNC size_t model_map_size(model_map *map); +ZITI_FUNC size_t model_map_size(const model_map *map); ZITI_FUNC void *model_map_set(model_map *map, const char *key, void *val); -ZITI_FUNC void *model_map_get(model_map *map, const char *key); +ZITI_FUNC void *model_map_get(const model_map *map, const char *key); ZITI_FUNC void *model_map_remove(model_map *map, const char *key); ZITI_FUNC void model_map_clear(model_map *map, _free_f val_free_func); -ZITI_FUNC model_map_iter model_map_iterator(model_map *map); +ZITI_FUNC model_map_iter model_map_iterator(const model_map *map); -ZITI_FUNC const char *model_map_it_key(model_map_iter *it); +ZITI_FUNC const char *model_map_it_key(const model_map_iter *it); ZITI_FUNC void *model_map_it_value(model_map_iter it); diff --git a/library/model_support.c b/library/model_support.c index f67aa34e..e4d26d5c 100644 --- a/library/model_support.c +++ b/library/model_support.c @@ -50,7 +50,7 @@ limitations under the License. static int parse_obj(void *obj, const char *json, jsmntok_t *tok, type_meta *meta); -static int model_map_compare(model_map *lh, model_map *rh, type_meta *m); +static int model_map_compare(const model_map *lh, const model_map *rh, type_meta *m); jsmntok_t* parse_tokens(jsmn_parser *parser, const char *json, size_t len, size_t *ntok) { size_t tok_cap = 256; @@ -972,7 +972,7 @@ int parse_enum(void *ptr, const char *json, void *tok, const void *enum_type) { } else { return -1; } - return 0; + return 1; } int json_enum(const void *ptr, void *bufp, int indent, int flags, const void *enum_type) { @@ -1030,7 +1030,7 @@ static void map_resize_table(model_map* m) { } } -static struct model_map_entry *find_map_entry(model_map *m, const char *key, uint32_t *hash_out) { +static struct model_map_entry *find_map_entry(const model_map *m, const char *key, uint32_t *hash_out) { uint32_t kh = key_hash(key); if (hash_out) { *hash_out = kh; @@ -1046,7 +1046,7 @@ static struct model_map_entry *find_map_entry(model_map *m, const char *key, uin return NULL; } -size_t model_map_size(model_map *m) { +size_t model_map_size(const model_map *m) { return m->impl ? m->impl->size : 0; } @@ -1084,8 +1084,8 @@ void *model_map_set(model_map *m, const char *key, void *val) { return NULL; } -void* model_map_get(model_map *m, const char* key) { - if (m->impl == NULL) { +void* model_map_get(const model_map *m, const char* key) { + if (m == NULL || m->impl == NULL) { return NULL; } @@ -1128,12 +1128,12 @@ void model_map_clear(model_map *map, _free_f free_func) { FREE(map->impl); } -model_map_iter model_map_iterator(model_map *m) { +model_map_iter model_map_iterator(const model_map *m) { if (m->impl == NULL) { return NULL; } return LIST_FIRST(&m->impl->entries); } -const char *model_map_it_key(model_map_iter *it) { +const char *model_map_it_key(const model_map_iter *it) { return it != NULL ? ((struct model_map_entry *) it)->key : NULL; } @@ -1158,7 +1158,7 @@ model_map_iter model_map_it_remove(model_map_iter it) { return next; } -static int model_map_compare(model_map *lh, model_map *rh, type_meta *m) { +static int model_map_compare(const model_map *lh, const model_map *rh, type_meta *m) { null_checks(lh, rh) int rc = 0;