diff options
Diffstat (limited to 'src/printer_lyb.c')
-rw-r--r-- | src/printer_lyb.c | 53 |
1 files changed, 22 insertions, 31 deletions
diff --git a/src/printer_lyb.c b/src/printer_lyb.c index 686c2d8..820e81e 100644 --- a/src/printer_lyb.c +++ b/src/printer_lyb.c @@ -81,7 +81,7 @@ lyb_ptr_equal_cb(void *val1_p, void *val2_p, ly_bool UNUSED(mod), void *UNUSED(c * @return LY_EEXIST when the whole hash sequence sollides. */ static LY_ERR -lyb_hash_sequence_check(struct hash_table *ht, struct lysc_node *sibling, LYB_HASH ht_col_id, LYB_HASH compare_col_id) +lyb_hash_sequence_check(struct ly_ht *ht, struct lysc_node *sibling, LYB_HASH ht_col_id, LYB_HASH compare_col_id) { struct lysc_node **col_node; @@ -123,9 +123,9 @@ lyb_hash_sequence_check(struct hash_table *ht, struct lysc_node *sibling, LYB_HA * @return LY_ERR value. */ static LY_ERR -lyb_hash_siblings(struct lysc_node *sibling, struct hash_table **ht_p) +lyb_hash_siblings(struct lysc_node *sibling, struct ly_ht **ht_p) { - struct hash_table *ht; + struct ly_ht *ht; const struct lysc_node *parent; const struct lys_module *mod; LYB_HASH i; @@ -172,7 +172,7 @@ lyb_hash_siblings(struct lysc_node *sibling, struct hash_table **ht_p) if (lyht_insert(ht, &sibling, lyb_get_hash(sibling, i), NULL)) { LOGINT(sibling->module->ctx); lyht_set_cb(ht, lyb_hash_equal_cb); - lyht_free(ht); + lyht_free(ht, NULL); return LY_EINT; } lyht_set_cb(ht, lyb_hash_equal_cb); @@ -184,7 +184,7 @@ lyb_hash_siblings(struct lysc_node *sibling, struct hash_table **ht_p) if (i == LYB_HASH_BITS) { /* wow */ LOGINT(sibling->module->ctx); - lyht_free(ht); + lyht_free(ht, NULL); return LY_EINT; } } @@ -205,7 +205,7 @@ lyb_hash_siblings(struct lysc_node *sibling, struct hash_table **ht_p) * @return LY_ERR value. */ static LY_ERR -lyb_hash_find(struct hash_table *ht, struct lysc_node *node, LYB_HASH *hash_p) +lyb_hash_find(struct ly_ht *ht, struct lysc_node *node, LYB_HASH *hash_p) { LYB_HASH hash; uint32_t i; @@ -701,7 +701,7 @@ lyb_print_term_value(struct lyd_node_term *term, struct ly_out *out, struct lyly if (value_len > UINT32_MAX) { LOGERR(lybctx->ctx, LY_EINT, "The maximum length of the LYB data " - "from a term node must not exceed %lu.", UINT32_MAX); + "from a term node must not exceed %" PRIu32 ".", UINT32_MAX); ret = LY_EINT; goto cleanup; } @@ -856,7 +856,7 @@ lyb_print_attributes(struct ly_out *out, const struct lyd_node_opaq *node, struc * @return LY_ERR value. */ static LY_ERR -lyb_print_schema_hash(struct ly_out *out, struct lysc_node *schema, struct hash_table **sibling_ht, struct lylyb_ctx *lybctx) +lyb_print_schema_hash(struct ly_out *out, struct lysc_node *schema, struct ly_ht **sibling_ht, struct lylyb_ctx *lybctx) { LY_ARRAY_COUNT_TYPE u; uint32_t i; @@ -1205,7 +1205,7 @@ lyb_print_node_list(struct ly_out *out, const struct lyd_node *node, struct lyd_ * @return LY_ERR value. */ static LY_ERR -lyb_print_node(struct ly_out *out, const struct lyd_node **printed_node, struct hash_table **sibling_ht, +lyb_print_node(struct ly_out *out, const struct lyd_node **printed_node, struct ly_ht **sibling_ht, struct lyd_lyb_ctx *lybctx) { const struct lyd_node *node = *printed_node; @@ -1256,32 +1256,23 @@ lyb_print_node(struct ly_out *out, const struct lyd_node **printed_node, struct static LY_ERR lyb_print_siblings(struct ly_out *out, const struct lyd_node *node, struct lyd_lyb_ctx *lybctx) { - struct hash_table *sibling_ht = NULL; + struct ly_ht *sibling_ht = NULL; const struct lys_module *prev_mod = NULL; - ly_bool top_level; - - top_level = !LY_ARRAY_COUNT(lybctx->lybctx->siblings); LY_CHECK_RET(lyb_write_start_siblings(out, lybctx->lybctx)); - if (top_level) { - /* write all the siblings */ - LY_LIST_FOR(node, node) { - /* do not reuse sibling hash tables from different modules */ - if (!node->schema || (node->schema->module != prev_mod)) { - sibling_ht = NULL; - prev_mod = node->schema ? node->schema->module : NULL; - } + /* write all the siblings */ + LY_LIST_FOR(node, node) { + /* do not reuse top-level sibling hash tables from different modules */ + if (!node->schema || (!lysc_data_parent(node->schema) && (node->schema->module != prev_mod))) { + sibling_ht = NULL; + prev_mod = node->schema ? node->schema->module : NULL; + } - LY_CHECK_RET(lyb_print_node(out, &node, &sibling_ht, lybctx)); + LY_CHECK_RET(lyb_print_node(out, &node, &sibling_ht, lybctx)); - if (!(lybctx->print_options & LYD_PRINT_WITHSIBLINGS)) { - break; - } - } - } else { - LY_LIST_FOR(node, node) { - LY_CHECK_RET(lyb_print_node(out, &node, &sibling_ht, lybctx)); + if (!lyd_parent(node) && !(lybctx->print_options & LYD_PRINT_WITHSIBLINGS)) { + break; } } @@ -1299,9 +1290,9 @@ lyb_print_data(struct ly_out *out, const struct lyd_node *root, uint32_t options const struct ly_ctx *ctx = root ? LYD_CTX(root) : NULL; lybctx = calloc(1, sizeof *lybctx); - LY_CHECK_ERR_RET(!lybctx, LOGMEM(ctx), LY_EMEM); + LY_CHECK_ERR_GOTO(!lybctx, LOGMEM(ctx); ret = LY_EMEM, cleanup); lybctx->lybctx = calloc(1, sizeof *lybctx->lybctx); - LY_CHECK_ERR_RET(!lybctx->lybctx, LOGMEM(ctx), LY_EMEM); + LY_CHECK_ERR_GOTO(!lybctx->lybctx, LOGMEM(ctx); ret = LY_EMEM, cleanup); lybctx->print_options = options; if (root) { |