Skip to content

Commit 1dab65e

Browse files
committed
libyang CHANGE path generation optimization refactored
Fixes #242
1 parent a9b2da1 commit 1dab65e

File tree

14 files changed

+59
-75
lines changed

14 files changed

+59
-75
lines changed

src/common.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ uint8_t ly_vlog_hide_def;
3737
static pthread_once_t ly_err_once = PTHREAD_ONCE_INIT;
3838
static pthread_key_t ly_err_key;
3939
#ifdef __linux__
40-
struct ly_err ly_err_main = {LY_SUCCESS, LYVE_SUCCESS, 0, 0, 0, 0, NULL, NULL + 1, {0}, {0}, {0}, {0}};
40+
struct ly_err ly_err_main = {LY_SUCCESS, LYVE_SUCCESS, 0, 0, 0, NULL, {0}, {0}, {0}, {0}};
4141
#endif
4242

4343
static void
@@ -96,7 +96,6 @@ ly_err_location(void)
9696
{
9797
#endif /* __linux__ */
9898
e = calloc(1, sizeof *e);
99-
e->path_obj = NULL + 1; /* hack - invalid address as an initial value */
10099
}
101100
pthread_setspecific(ly_err_key, e);
102101
}
@@ -572,7 +571,7 @@ transform_xml2json(struct ly_ctx *ctx, const char *expr, struct lyxml_elem *xml,
572571
if (!ns) {
573572
if (log) {
574573
LOGVAL(LYE_XML_INVAL, LY_VLOG_XML, xml, "namespace prefix");
575-
LOGVAL(LYE_SPEC, LY_VLOG_XML, xml,
574+
LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL,
576575
"XML namespace with prefix \"%.*s\" not defined.", pref_len, cur_expr);
577576
}
578577
goto error;
@@ -581,7 +580,7 @@ transform_xml2json(struct ly_ctx *ctx, const char *expr, struct lyxml_elem *xml,
581580
if (!mod) {
582581
if (log) {
583582
LOGVAL(LYE_XML_INVAL, LY_VLOG_XML, xml, "module namespace");
584-
LOGVAL(LYE_SPEC, LY_VLOG_XML, xml,
583+
LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL,
585584
"Module with the namespace \"%s\" could not be found.", ns->value);
586585
}
587586
goto error;
@@ -624,7 +623,7 @@ transform_xml2json(struct ly_ctx *ctx, const char *expr, struct lyxml_elem *xml,
624623
if (!ns) {
625624
if (log) {
626625
LOGVAL(LYE_XML_INVAL, LY_VLOG_XML, xml, "namespace prefix");
627-
LOGVAL(LYE_SPEC, LY_VLOG_XML, xml,
626+
LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL,
628627
"XML namespace with prefix \"%.*s\" not defined.", pref_len, cur_expr);
629628
}
630629
goto error;

src/common.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ struct ly_err {
7575
uint8_t vlog_hide;
7676
uint8_t buf_used;
7777
uint16_t path_index;
78-
uint8_t path_obj_type;
7978
struct ly_err_item *errlist; /* list of stored errors */
80-
const void *path_obj;
8179
char msg[LY_BUF_SIZE];
8280
char path[LY_BUF_SIZE];
8381
char apptag[LY_APPTAG_LEN];
@@ -236,7 +234,8 @@ enum LY_VLOG_ELEM {
236234
LY_VLOG_XML, /* struct lyxml_elem* */
237235
LY_VLOG_LYS, /* struct lys_node* */
238236
LY_VLOG_LYD, /* struct lyd_node* */
239-
LY_VLOG_STR /* const char* */
237+
LY_VLOG_STR, /* const char* */
238+
LY_VLOG_PREV /* use exact same previous path */
240239
};
241240

242241
/*

src/log.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@ log_vprintf(LY_LOG_LEVEL level, uint8_t hide, const char *format, const char *pa
8282
if (!path) {
8383
/* erase previous path */
8484
e->path_index = LY_BUF_SIZE - 1;
85-
if (e->path_obj != NULL + 1) {
86-
e->path_obj = NULL;
87-
}
8885
}
8986

9087
/* if the error-app-tag should be set, do it after calling LOGVAL */
@@ -477,14 +474,7 @@ ly_vlog(LY_ECODE code, enum LY_VLOG_ELEM elem_type, const void *elem, ...)
477474
/* resolve path */
478475
path = ((struct ly_err *)&ly_errno)->path;
479476
index = &((struct ly_err *)&ly_errno)->path_index;
480-
if (elem_type) { /* != LY_VLOG_NONE */
481-
/* check if the path is equal to the last one */
482-
if (elem && elem_type == ((struct ly_err *)&ly_errno)->path_obj_type &&
483-
(elem_type == LY_VLOG_LYD ? ((struct lyd_node *)elem)->schema : elem) == ((struct ly_err *)&ly_errno)->path_obj) {
484-
/* path is up-to-date (same as the last one) */
485-
goto log;
486-
}
487-
477+
if ((elem_type != LY_VLOG_NONE) && (elem_type != LY_VLOG_PREV)) { /* != LY_VLOG_NONE */
488478
/* update path */
489479
(*index) = LY_BUF_SIZE - 1;
490480
path[(*index)] = '\0';
@@ -493,11 +483,8 @@ ly_vlog(LY_ECODE code, enum LY_VLOG_ELEM elem_type, const void *elem, ...)
493483
path[--(*index)] = '/';
494484
} else {
495485
ly_vlog_build_path_reverse(elem_type, elem, path, index);
496-
/* store the source of the path */
497-
((struct ly_err *)&ly_errno)->path_obj_type = elem_type;
498-
((struct ly_err *)&ly_errno)->path_obj = elem_type == LY_VLOG_LYD ? ((struct lyd_node *)elem)->schema : elem;
499486
}
500-
} else {
487+
} else if (elem_type == LY_VLOG_NONE) {
501488
/* erase path, the rest will be erased by log_vprintf() since it will get NULL path parameter */
502489
path[(*index)] = '\0';
503490
}

src/parser.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ validate_length_range(uint8_t kind, uint64_t unum, int64_t snum, int64_t fnum, u
650650

651651
LOGVAL(LYE_NOCONSTR, LY_VLOG_LYD, node, (val_str ? val_str : ""), restr ? restr->expr : "");
652652
if (restr && restr->emsg) {
653-
LOGVAL(LYE_SPEC, LY_VLOG_LYD, node, restr->emsg);
653+
LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, restr->emsg);
654654
}
655655
if (restr && restr->eapptag) {
656656
strncpy(((struct ly_err *)&ly_errno)->apptag, restr->eapptag, LY_APPTAG_LEN - 1);
@@ -687,7 +687,7 @@ validate_pattern(const char *val_str, struct lys_type *type, struct lyd_node *no
687687
if ((rc && type->info.str.patterns[i].expr[0] == 0x06) || (!rc && type->info.str.patterns[i].expr[0] == 0x15)) {
688688
LOGVAL(LYE_NOCONSTR, LY_VLOG_LYD, node, val_str, &type->info.str.patterns[i].expr[1]);
689689
if (type->info.str.patterns[i].emsg) {
690-
LOGVAL(LYE_SPEC, LY_VLOG_LYD, node, type->info.str.patterns[i].emsg);
690+
LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, type->info.str.patterns[i].emsg);
691691
}
692692
if (type->info.str.patterns[i].eapptag) {
693693
strncpy(((struct ly_err *)&ly_errno)->apptag, type->info.str.patterns[i].eapptag, LY_APPTAG_LEN - 1);
@@ -1165,7 +1165,7 @@ lyp_parse_value(struct lys_type *type, const char **value_, struct lyxml_elem *x
11651165
if (unum & 3) {
11661166
/* base64 length must be multiple of 4 chars */
11671167
LOGVAL(LYE_INVAL, LY_VLOG_LYD, leaf, value, leaf->schema->name);
1168-
LOGVAL(LYE_SPEC, LY_VLOG_LYD, leaf, "Base64 encoded value length must be divisible by 4.");
1168+
LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, "Base64 encoded value length must be divisible by 4.");
11691169
goto cleanup;
11701170
}
11711171
len = (unum / 4) * 3;
@@ -1233,7 +1233,7 @@ lyp_parse_value(struct lys_type *type, const char **value_, struct lyxml_elem *x
12331233
for (j = 0; j < type->info.bits.bit[i].iffeature_size; j++) {
12341234
if (!resolve_iffeature(&type->info.bits.bit[i].iffeature[i])) {
12351235
LOGVAL(LYE_INVAL, LY_VLOG_LYD, leaf, value, leaf->schema->name);
1236-
LOGVAL(LYE_SPEC, LY_VLOG_LYD, leaf,
1236+
LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL,
12371237
"Bit \"%s\" is disabled by its if-feature condition.", type->info.bits.bit[i].name);
12381238

12391239
free(bits);
@@ -1243,7 +1243,7 @@ lyp_parse_value(struct lys_type *type, const char **value_, struct lyxml_elem *x
12431243
/* check that the value was not already set */
12441244
if (bits[i]) {
12451245
LOGVAL(LYE_INVAL, LY_VLOG_LYD, leaf, value, leaf->schema->name);
1246-
LOGVAL(LYE_SPEC, LY_VLOG_LYD, leaf, "Bit \"%s\" used multiple times.",
1246+
LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, "Bit \"%s\" used multiple times.",
12471247
type->info.bits.bit[i].name);
12481248
free(bits);
12491249
goto cleanup;
@@ -1335,7 +1335,7 @@ lyp_parse_value(struct lys_type *type, const char **value_, struct lyxml_elem *x
13351335
for (j = 0; j < type->info.enums.enm[i].iffeature_size; j++) {
13361336
if (!resolve_iffeature(&type->info.enums.enm[i].iffeature[i])) {
13371337
LOGVAL(LYE_INVAL, LY_VLOG_LYD, leaf, value, leaf->schema->name);
1338-
LOGVAL(LYE_SPEC, LY_VLOG_LYD, leaf, "Enum \"%s\" is disabled by its if-feature condition.",
1338+
LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, "Enum \"%s\" is disabled by its if-feature condition.",
13391339
value);
13401340
goto cleanup;
13411341
}

src/parser_json.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,15 +1044,15 @@ json_parse_data(struct ly_ctx *ctx, const char *data, const struct lys_node *sch
10441044
if (schema->nodetype & (LYS_RPC | LYS_ACTION)) {
10451045
if (!(options & LYD_OPT_RPC) || *act_notif) {
10461046
LOGVAL(LYE_INELEM, LY_VLOG_LYD, result, schema->name);
1047-
LOGVAL(LYE_SPEC, LY_VLOG_LYD, result, "Unexpected %s node \"%s\".",
1047+
LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, "Unexpected %s node \"%s\".",
10481048
(schema->nodetype == LYS_RPC ? "rpc" : "action"), schema->name);
10491049
goto error;
10501050
}
10511051
*act_notif = result;
10521052
} else if (schema->nodetype == LYS_NOTIF) {
10531053
if (!(options & LYD_OPT_NOTIF) || *act_notif) {
10541054
LOGVAL(LYE_INELEM, LY_VLOG_LYD, result, schema->name);
1055-
LOGVAL(LYE_SPEC, LY_VLOG_LYD, result, "Unexpected notification node \"%s\".", schema->name);
1055+
LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, "Unexpected notification node \"%s\".", schema->name);
10561056
goto error;
10571057
}
10581058
*act_notif = result;

src/parser_xml.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ xml_parse_data(struct ly_ctx *ctx, struct lyxml_elem *xml, struct lyd_node *pare
242242
/* out of order insertion - insert list's key to the correct position, before the diter */
243243
if (options & LYD_OPT_STRICT) {
244244
LOGVAL(LYE_INORDER, LY_VLOG_LYD, *result, schema->name, diter->schema->name);
245-
LOGVAL(LYE_SPEC, LY_VLOG_LYD, *result, "Invalid position of the key \"%s\" in a list \"%s\".",
245+
LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, "Invalid position of the key \"%s\" in a list \"%s\".",
246246
schema->name, parent->schema->name);
247247
free(*result);
248248
*result = NULL;
@@ -404,15 +404,15 @@ xml_parse_data(struct ly_ctx *ctx, struct lyxml_elem *xml, struct lyd_node *pare
404404
} else if (schema->nodetype & (LYS_RPC | LYS_ACTION)) {
405405
if (!(options & LYD_OPT_RPC) || *act_notif) {
406406
LOGVAL(LYE_INELEM, LY_VLOG_LYD, (*result), schema->name);
407-
LOGVAL(LYE_SPEC, LY_VLOG_LYD, (*result), "Unexpected %s node \"%s\".",
407+
LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, "Unexpected %s node \"%s\".",
408408
(schema->nodetype == LYS_RPC ? "rpc" : "action"), schema->name);
409409
goto error;
410410
}
411411
*act_notif = *result;
412412
} else if (schema->nodetype == LYS_NOTIF) {
413413
if (!(options & LYD_OPT_NOTIF) || *act_notif) {
414414
LOGVAL(LYE_INELEM, LY_VLOG_LYD, (*result), schema->name);
415-
LOGVAL(LYE_SPEC, LY_VLOG_LYD, (*result), "Unexpected notification node \"%s\".", schema->name);
415+
LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, "Unexpected notification node \"%s\".", schema->name);
416416
goto error;
417417
}
418418
*act_notif = *result;
@@ -433,7 +433,7 @@ xml_parse_data(struct ly_ctx *ctx, struct lyxml_elem *xml, struct lyd_node *pare
433433
!ly_strequal((*result)->schema->module->name, "ietf-netconf", 0)) {
434434
if (options & LYD_OPT_STRICT) {
435435
LOGVAL(LYE_INATTR, LY_VLOG_LYD, (*result), attr->name, xml->name);
436-
LOGVAL(LYE_SPEC, LY_VLOG_LYD, (*result), "Attribute \"%s\" with no namespace (schema).",
436+
LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, "Attribute \"%s\" with no namespace (schema).",
437437
attr->name);
438438
goto error;
439439
} else {
@@ -475,7 +475,7 @@ xml_parse_data(struct ly_ctx *ctx, struct lyxml_elem *xml, struct lyd_node *pare
475475
free(dattr);
476476
if (options & LYD_OPT_STRICT) {
477477
LOGVAL(LYE_INATTR, LY_VLOG_LYD, (*result), attr->name, xml->name);
478-
LOGVAL(LYE_SPEC, LY_VLOG_LYD, (*result), "Attribute \"%s\" from unknown schema (\"%s\").",
478+
LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, "Attribute \"%s\" from unknown schema (\"%s\").",
479479
attr->name, attr->ns->value);
480480
goto error;
481481
} else {

src/parser_yang.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2628,7 +2628,7 @@ store_flags(struct lys_node *node, uint8_t flags, int config_opt)
26282628

26292629
if (!elem && (node->flags & LYS_CONFIG_W) && node->parent && (node->parent->flags & LYS_CONFIG_R)) {
26302630
LOGVAL(LYE_INARG, LY_VLOG_LYS, node, "true", "config");
2631-
LOGVAL(LYE_SPEC, LY_VLOG_LYS, node, "State nodes cannot have configuration nodes as children.");
2631+
LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, "State nodes cannot have configuration nodes as children.");
26322632
return EXIT_FAILURE;
26332633
}
26342634
}

src/parser_yang_bis.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5210,7 +5210,7 @@ YYLTYPE yylloc = yyloc_default;
52105210
if ((yyvsp[-1].nodes).node.ptr_leaf->dflt && ((yyvsp[-1].nodes).node.ptr_leaf->flags & LYS_MAND_TRUE)) {
52115211
/* RFC 6020, 7.6.4 - default statement must not with mandatory true */
52125212
LOGVAL(LYE_INCHILDSTMT, LY_VLOG_LYS, (yyvsp[-1].nodes).node.ptr_leaf, "mandatory", "leaf");
5213-
LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "The \"mandatory\" statement is forbidden on leaf with \"default\".");
5213+
LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, "The \"mandatory\" statement is forbidden on leaf with \"default\".");
52145214
YYABORT;
52155215
}
52165216
if (unres_schema_add_node(trg, unres, &(yyvsp[-1].nodes).node.ptr_leaf->type, UNRES_TYPE_DFLT,
@@ -5425,7 +5425,7 @@ YYLTYPE yylloc = yyloc_default;
54255425
}
54265426
if ((yyvsp[-1].nodes).node.ptr_leaflist->dflt_size && (yyvsp[-1].nodes).node.ptr_leaflist->min) {
54275427
LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "min-elements", "leaf-list");
5428-
LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL,
5428+
LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL,
54295429
"The \"min-elements\" statement with non-zero value is forbidden on leaf-lists with the \"default\" statement.");
54305430
YYABORT;
54315431
}

src/parser_yin.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3431,7 +3431,7 @@ read_yin_choice(struct lys_module *module, struct lys_node *parent, struct lyxml
34313431
/* check - default is prohibited in combination with mandatory */
34323432
if (dflt && (choice->flags & LYS_MAND_TRUE)) {
34333433
LOGVAL(LYE_INCHILDSTMT, LY_VLOG_LYS, retval, "default", "choice");
3434-
LOGVAL(LYE_SPEC, LY_VLOG_LYS, retval, "The \"default\" statement is forbidden on choices with \"mandatory\".");
3434+
LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, "The \"default\" statement is forbidden on choices with \"mandatory\".");
34353435
goto error;
34363436
}
34373437

@@ -3709,7 +3709,7 @@ read_yin_leaf(struct lys_module *module, struct lys_node *parent, struct lyxml_e
37093709
}
37103710
if (leaf->dflt && (leaf->flags & LYS_MAND_TRUE)) {
37113711
LOGVAL(LYE_INCHILDSTMT, LY_VLOG_LYS, retval, "mandatory", "leaf");
3712-
LOGVAL(LYE_SPEC, LY_VLOG_LYS, retval,
3712+
LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL,
37133713
"The \"mandatory\" statement is forbidden on leaf with the \"default\" statement.");
37143714
goto error;
37153715
}
@@ -3893,7 +3893,7 @@ read_yin_leaflist(struct lys_module *module, struct lys_node *parent, struct lyx
38933893
llist->min = (uint32_t) val;
38943894
if (llist->max && (llist->min > llist->max)) {
38953895
LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name);
3896-
LOGVAL(LYE_SPEC, LY_VLOG_LYS, retval, "\"min-elements\" is bigger than \"max-elements\".");
3896+
LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, "\"min-elements\" is bigger than \"max-elements\".");
38973897
goto error;
38983898
}
38993899
} else if (!strcmp(sub->name, "max-elements")) {
@@ -3922,7 +3922,7 @@ read_yin_leaflist(struct lys_module *module, struct lys_node *parent, struct lyx
39223922
llist->max = (uint32_t) val;
39233923
if (llist->min > llist->max) {
39243924
LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name);
3925-
LOGVAL(LYE_SPEC, LY_VLOG_LYS, retval, "\"max-elements\" is smaller than \"min-elements\".");
3925+
LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, "\"max-elements\" is smaller than \"min-elements\".");
39263926
goto error;
39273927
}
39283928
}
@@ -3995,7 +3995,7 @@ read_yin_leaflist(struct lys_module *module, struct lys_node *parent, struct lyx
39953995
for (r = 0; r < llist->dflt_size; r++) {
39963996
if (ly_strequal(llist->dflt[r], value, 1)) {
39973997
LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, "default");
3998-
LOGVAL(LYE_SPEC, LY_VLOG_LYS, retval, "Duplicated default value \"%s\".", value);
3998+
LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, "Duplicated default value \"%s\".", value);
39993999
goto error;
40004000
}
40014001
}
@@ -4012,7 +4012,7 @@ read_yin_leaflist(struct lys_module *module, struct lys_node *parent, struct lyx
40124012

40134013
if (llist->dflt_size && llist->min) {
40144014
LOGVAL(LYE_INCHILDSTMT, LY_VLOG_LYS, retval, "min-elements", "leaf-list");
4015-
LOGVAL(LYE_SPEC, LY_VLOG_LYS, retval,
4015+
LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL,
40164016
"The \"min-elements\" statement with non-zero value is forbidden on leaf-lists with the \"default\" statement.");
40174017
goto error;
40184018
}
@@ -4188,7 +4188,7 @@ read_yin_list(struct lys_module *module, struct lys_node *parent, struct lyxml_e
41884188
list->min = (uint32_t) val;
41894189
if (list->max && (list->min > list->max)) {
41904190
LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name);
4191-
LOGVAL(LYE_SPEC, LY_VLOG_LYS, retval, "\"min-elements\" is bigger than \"max-elements\".");
4191+
LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, "\"min-elements\" is bigger than \"max-elements\".");
41924192
lyxml_free(module->ctx, sub);
41934193
goto error;
41944194
}
@@ -4219,7 +4219,7 @@ read_yin_list(struct lys_module *module, struct lys_node *parent, struct lyxml_e
42194219
list->max = (uint32_t) val;
42204220
if (list->min > list->max) {
42214221
LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name);
4222-
LOGVAL(LYE_SPEC, LY_VLOG_LYS, retval, "\"max-elements\" is smaller than \"min-elements\".");
4222+
LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, "\"max-elements\" is smaller than \"min-elements\".");
42234223
goto error;
42244224
}
42254225
}

0 commit comments

Comments
 (0)