You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

222 lines
9.5 KiB

  1. Index: libyang-0.16-r3/src/parser.c
  2. ===================================================================
  3. --- libyang-0.16-r3.orig/src/parser.c
  4. +++ libyang-0.16-r3/src/parser.c
  5. @@ -1210,7 +1210,7 @@ lyp_parse_value(struct lys_type *type, c
  6. unsigned int i, j;
  7. int64_t num;
  8. uint64_t unum, uind, u = 0;
  9. - const char *ptr, *value = *value_, *itemname;
  10. + const char *ptr, *value = *value_, *itemname, *old_val_str;
  11. struct lys_type_bit **bits = NULL;
  12. struct lys_ident *ident;
  13. lyd_val *val, old_val;
  14. @@ -1245,7 +1245,8 @@ lyp_parse_value(struct lys_type *type, c
  15. /* fully clear the value */
  16. if (store) {
  17. - lyd_free_value(*val, *val_type, *val_flags, type, &old_val, &old_val_type, &old_val_flags);
  18. + old_val_str = lydict_insert(ctx, *value_, 0);
  19. + lyd_free_value(*val, *val_type, *val_flags, type, old_val_str, &old_val, &old_val_type, &old_val_flags);
  20. *val_flags &= ~LY_VALUE_UNRES;
  21. }
  22. @@ -1907,7 +1908,7 @@ lyp_parse_value(struct lys_type *type, c
  23. if (store) {
  24. /* erase possible present and invalid value data */
  25. - lyd_free_value(*val, *val_type, *val_flags, t, NULL, NULL, NULL);
  26. + lyd_free_value(*val, *val_type, *val_flags, t, *value_, NULL, NULL, NULL);
  27. memset(val, 0, sizeof(lyd_val));
  28. }
  29. }
  30. @@ -1946,7 +1947,8 @@ lyp_parse_value(struct lys_type *type, c
  31. /* free backup */
  32. if (store) {
  33. - lyd_free_value(old_val, old_val_type, old_val_flags, type, NULL, NULL, NULL);
  34. + lyd_free_value(old_val, old_val_type, old_val_flags, type, old_val_str, NULL, NULL, NULL);
  35. + lydict_remove(ctx, old_val_str);
  36. }
  37. return type;
  38. @@ -1956,6 +1958,7 @@ error:
  39. *val = old_val;
  40. *val_type = old_val_type;
  41. *val_flags = old_val_flags;
  42. + lydict_remove(ctx, old_val_str);
  43. }
  44. return NULL;
  45. }
  46. Index: libyang-0.16-r3/src/parser.h
  47. ===================================================================
  48. --- libyang-0.16-r3.orig/src/parser.h
  49. +++ libyang-0.16-r3/src/parser.h
  50. @@ -267,10 +267,10 @@ int lytype_store(const struct lys_module
  51. /**
  52. * @brief Free a user type stored value.
  53. *
  54. - * @param[in] mod Module of the type.
  55. - * @param[in] type_name Type (typedef) name.
  56. + * @param[in] type Type of the value.
  57. * @param[in] value Value union to free.
  58. + * @param[in] value_str String value of the value.
  59. */
  60. -void lytype_free(const struct lys_module *mod, const char *type_name, lyd_val value);
  61. +void lytype_free(const struct lys_type *type, lyd_val value, const char *value_str);
  62. #endif /* LY_PARSER_H_ */
  63. Index: libyang-0.16-r3/src/plugins.c
  64. ===================================================================
  65. --- libyang-0.16-r3.orig/src/plugins.c
  66. +++ libyang-0.16-r3/src/plugins.c
  67. @@ -603,11 +603,40 @@ lytype_store(const struct lys_module *mo
  68. }
  69. void
  70. -lytype_free(const struct lys_module *mod, const char *type_name, lyd_val value)
  71. +lytype_free(const struct lys_type *type, lyd_val value, const char *value_str)
  72. {
  73. struct lytype_plugin_list *p;
  74. + struct lys_node_leaf sleaf;
  75. + struct lyd_node_leaf_list leaf;
  76. + struct lys_module *mod;
  77. - p = lytype_find(mod->name, mod->rev_size ? mod->rev[0].date : NULL, type_name);
  78. + assert(type->der && type->der->module);
  79. +
  80. + mod = type->der->module;
  81. + memset(&sleaf, 0, sizeof sleaf);
  82. + memset(&leaf, 0, sizeof leaf);
  83. +
  84. + if (type->base == LY_TYPE_UNION) {
  85. + /* create a fake schema node */
  86. + sleaf.module = mod;
  87. + sleaf.name = "fake-leaf";
  88. + sleaf.type = *type;
  89. + sleaf.nodetype = LYS_LEAF;
  90. +
  91. + /* and a fake data node */
  92. + leaf.schema = (struct lys_node *)&sleaf;
  93. + leaf.value = value;
  94. + leaf.value_str = value_str;
  95. +
  96. + /* find the original type */
  97. + type = lyd_leaf_type(&leaf);
  98. + if (!type) {
  99. + LOGINT(mod->ctx);
  100. + return;
  101. + }
  102. + }
  103. +
  104. + p = lytype_find(mod->name, mod->rev_size ? mod->rev[0].date : NULL, type->der->name);
  105. if (!p) {
  106. LOGINT(mod->ctx);
  107. return;
  108. Index: libyang-0.16-r3/src/resolve.c
  109. ===================================================================
  110. --- libyang-0.16-r3.orig/src/resolve.c
  111. +++ libyang-0.16-r3/src/resolve.c
  112. @@ -3630,7 +3630,7 @@ check_default(struct lys_type *type, con
  113. }
  114. cleanup:
  115. - lyd_free_value(node.value, node.value_type, node.value_flags, type, NULL, NULL, NULL);
  116. + lyd_free_value(node.value, node.value_type, node.value_flags, type, node.value_str, NULL, NULL, NULL);
  117. lydict_remove(ctx, node.value_str);
  118. if (tpdf && node.schema) {
  119. free((char *)node.schema->name);
  120. @@ -7923,7 +7923,7 @@ resolve_union(struct lyd_node_leaf_list
  121. if (store) {
  122. lyd_free_value(leaf->value, leaf->value_type, leaf->value_flags, &((struct lys_node_leaf *)leaf->schema)->type,
  123. - NULL, NULL, NULL);
  124. + leaf->value_str, NULL, NULL, NULL);
  125. memset(&leaf->value, 0, sizeof leaf->value);
  126. }
  127. @@ -8012,7 +8012,7 @@ resolve_union(struct lyd_node_leaf_list
  128. /* erase possible present and invalid value data */
  129. if (store) {
  130. - lyd_free_value(leaf->value, leaf->value_type, leaf->value_flags, t, NULL, NULL, NULL);
  131. + lyd_free_value(leaf->value, leaf->value_type, leaf->value_flags, t, leaf->value_str, NULL, NULL, NULL);
  132. memset(&leaf->value, 0, sizeof leaf->value);
  133. }
  134. }
  135. Index: libyang-0.16-r3/src/tree_data.c
  136. ===================================================================
  137. --- libyang-0.16-r3.orig/src/tree_data.c
  138. +++ libyang-0.16-r3/src/tree_data.c
  139. @@ -2442,7 +2442,7 @@ lyd_merge_node_update(struct lyd_node *t
  140. NULL, trg_leaf, NULL, NULL, 1, src_leaf->dflt, 0);
  141. } else {
  142. lyd_free_value(trg_leaf->value, trg_leaf->value_type, trg_leaf->value_flags,
  143. - &((struct lys_node_leaf *)trg_leaf->schema)->type, NULL, NULL, NULL);
  144. + &((struct lys_node_leaf *)trg_leaf->schema)->type, trg_leaf->value_str, NULL, NULL, NULL);
  145. trg_leaf->value = src_leaf->value;
  146. }
  147. src_leaf->value = (lyd_val)0;
  148. @@ -2492,7 +2492,7 @@ lyd_merge_node_update(struct lyd_node *t
  149. lydict_remove(ctx, trg_leaf->value_str);
  150. trg_leaf->value_str = lydict_insert(ctx, src_leaf->value_str, 0);
  151. lyd_free_value(trg_leaf->value, trg_leaf->value_type, trg_leaf->value_flags,
  152. - &((struct lys_node_leaf *)trg_leaf->schema)->type, NULL, NULL, NULL);
  153. + &((struct lys_node_leaf *)trg_leaf->schema)->type, trg_leaf->value_str, NULL, NULL, NULL);
  154. trg_leaf->value_type = src_leaf->value_type;
  155. trg_leaf->dflt = src_leaf->dflt;
  156. @@ -5866,7 +5866,7 @@ lyd_free_attr(struct ly_ctx *ctx, struct
  157. lydict_remove(ctx, attr->name);
  158. type = lys_ext_complex_get_substmt(LY_STMT_TYPE, attr->annotation, NULL);
  159. assert(type);
  160. - lyd_free_value(attr->value, attr->value_type, attr->value_flags, *type, NULL, NULL, NULL);
  161. + lyd_free_value(attr->value, attr->value_type, attr->value_flags, *type, attr->value_str, NULL, NULL, NULL);
  162. lydict_remove(ctx, attr->value_str);
  163. free(attr);
  164. }
  165. @@ -5975,8 +5975,8 @@ lyd_insert_attr(struct lyd_node *parent,
  166. }
  167. void
  168. -lyd_free_value(lyd_val value, LY_DATA_TYPE value_type, uint8_t value_flags, struct lys_type *type, lyd_val *old_val,
  169. - LY_DATA_TYPE *old_val_type, uint8_t *old_val_flags)
  170. +lyd_free_value(lyd_val value, LY_DATA_TYPE value_type, uint8_t value_flags, struct lys_type *type, const char *value_str,
  171. + lyd_val *old_val, LY_DATA_TYPE *old_val_type, uint8_t *old_val_flags)
  172. {
  173. if (old_val) {
  174. *old_val = value;
  175. @@ -5988,8 +5988,7 @@ lyd_free_value(lyd_val value, LY_DATA_TY
  176. /* otherwise the value is correctly freed */
  177. if (value_flags & LY_VALUE_USER) {
  178. - assert(type->der && type->der->module);
  179. - lytype_free(type->der->module, type->der->name, value);
  180. + lytype_free(type, value, value_str);
  181. } else {
  182. switch (value_type) {
  183. case LY_TYPE_BITS:
  184. @@ -6062,7 +6061,7 @@ _lyd_free_node(struct lyd_node *node)
  185. case LYS_LEAFLIST:
  186. leaf = (struct lyd_node_leaf_list *)node;
  187. lyd_free_value(leaf->value, leaf->value_type, leaf->value_flags, &((struct lys_node_leaf *)leaf->schema)->type,
  188. - NULL, NULL, NULL);
  189. + leaf->value_str, NULL, NULL, NULL);
  190. lydict_remove(leaf->schema->module->ctx, leaf->value_str);
  191. break;
  192. default:
  193. Index: libyang-0.16-r3/src/tree_internal.h
  194. ===================================================================
  195. --- libyang-0.16-r3.orig/src/tree_internal.h
  196. +++ libyang-0.16-r3/src/tree_internal.h
  197. @@ -496,8 +496,8 @@ int lyd_get_unique_default(const char* u
  198. int lyd_build_relative_data_path(const struct lys_module *module, const struct lyd_node *node, const char *schema_id,
  199. char *buf);
  200. -void lyd_free_value(lyd_val value, LY_DATA_TYPE value_type, uint8_t value_flags, struct lys_type *type, lyd_val *old_val,
  201. - LY_DATA_TYPE *old_val_type, uint8_t *old_val_flags);
  202. +void lyd_free_value(lyd_val value, LY_DATA_TYPE value_type, uint8_t value_flags, struct lys_type *type,
  203. + const char *value_str, lyd_val *old_val, LY_DATA_TYPE *old_val_type, uint8_t *old_val_flags);
  204. int lyd_list_equal(struct lyd_node *node1, struct lyd_node *node2, int with_defaults);