@@ -899,18 +899,21 @@ static void
899
899
set_init (struct lyxp_set * new , const struct lyxp_set * set )
900
900
{
901
901
memset (new , 0 , sizeof * new );
902
- if (set ) {
903
- new -> non_child_axis = set -> non_child_axis ;
904
- new -> ctx = set -> ctx ;
905
- new -> cur_node = set -> cur_node ;
906
- new -> root_type = set -> root_type ;
907
- new -> context_op = set -> context_op ;
908
- new -> tree = set -> tree ;
909
- new -> cur_mod = set -> cur_mod ;
910
- new -> format = set -> format ;
911
- new -> prefix_data = set -> prefix_data ;
912
- new -> vars = set -> vars ;
902
+ if (!set ) {
903
+ return ;
913
904
}
905
+
906
+ new -> non_child_axis = set -> non_child_axis ;
907
+ new -> not_found = set -> not_found ;
908
+ new -> ctx = set -> ctx ;
909
+ new -> cur_node = set -> cur_node ;
910
+ new -> root_type = set -> root_type ;
911
+ new -> context_op = set -> context_op ;
912
+ new -> tree = set -> tree ;
913
+ new -> cur_mod = set -> cur_mod ;
914
+ new -> format = set -> format ;
915
+ new -> prefix_data = set -> prefix_data ;
916
+ new -> vars = set -> vars ;
914
917
}
915
918
916
919
/**
@@ -7522,7 +7525,11 @@ eval_predicate(const struct lyxp_expr *exp, uint32_t *tok_idx, struct lyxp_set *
7522
7525
* tok_idx = orig_exp ;
7523
7526
7524
7527
rc = eval_expr_select (exp , tok_idx , 0 , & set2 , options );
7525
- if (rc != LY_SUCCESS ) {
7528
+ if (!rc && set2 .not_found ) {
7529
+ set -> not_found = 1 ;
7530
+ break ;
7531
+ }
7532
+ if (rc ) {
7526
7533
lyxp_set_free_content (& set2 );
7527
7534
return rc ;
7528
7535
}
@@ -7571,6 +7578,9 @@ eval_predicate(const struct lyxp_expr *exp, uint32_t *tok_idx, struct lyxp_set *
7571
7578
* tok_idx = orig_exp ;
7572
7579
7573
7580
rc = eval_expr_select (exp , tok_idx , 0 , set , options );
7581
+ if (!rc && set -> not_found ) {
7582
+ break ;
7583
+ }
7574
7584
LY_CHECK_RET (rc );
7575
7585
7576
7586
set -> val .scnodes [i ].in_ctx = pred_in_ctx ;
@@ -7590,7 +7600,7 @@ eval_predicate(const struct lyxp_expr *exp, uint32_t *tok_idx, struct lyxp_set *
7590
7600
set_fill_set (& set2 , set );
7591
7601
7592
7602
rc = eval_expr_select (exp , tok_idx , 0 , & set2 , options );
7593
- if (rc != LY_SUCCESS ) {
7603
+ if (rc ) {
7594
7604
lyxp_set_free_content (& set2 );
7595
7605
return rc ;
7596
7606
}
@@ -8205,8 +8215,7 @@ eval_name_test_with_predicate(const struct lyxp_expr *exp, uint32_t *tok_idx, en
8205
8215
8206
8216
if (options & LYXP_SCNODE_ERROR ) {
8207
8217
/* error */
8208
- rc = LY_ENOTFOUND ;
8209
- goto cleanup ;
8218
+ set -> not_found = 1 ;
8210
8219
}
8211
8220
8212
8221
/* skip the predicates and the rest of this path to not generate invalid warnings */
@@ -8248,10 +8257,8 @@ eval_name_test_with_predicate(const struct lyxp_expr *exp, uint32_t *tok_idx, en
8248
8257
/* restore options */
8249
8258
options &= ~LYXP_SKIP_EXPR ;
8250
8259
}
8251
- if (!(options & LYXP_SKIP_EXPR )) {
8252
- lydict_remove (set -> ctx , ncname_dict );
8253
- ly_path_predicates_free (set -> ctx , predicates );
8254
- }
8260
+ lydict_remove (set -> ctx , ncname_dict );
8261
+ ly_path_predicates_free (set -> ctx , predicates );
8255
8262
return rc ;
8256
8263
}
8257
8264
@@ -8423,8 +8430,9 @@ eval_relative_location_path(const struct lyxp_expr *exp, uint32_t *tok_idx, ly_b
8423
8430
rc = eval_name_test_with_predicate (exp , tok_idx , axis , all_desc , set , options );
8424
8431
if (rc == LY_ENOT ) {
8425
8432
assert (options & LYXP_SCNODE_ALL );
8426
- /* skip the rest of this path */
8427
8433
rc = LY_SUCCESS ;
8434
+
8435
+ /* skip the rest of this path */
8428
8436
scnode_skip_path = 1 ;
8429
8437
options |= LYXP_SKIP_EXPR ;
8430
8438
}
@@ -8673,8 +8681,9 @@ eval_function_call(const struct lyxp_expr *exp, uint32_t *tok_idx, struct lyxp_s
8673
8681
8674
8682
rc = eval_expr_select (exp , tok_idx , 0 , args [0 ], options );
8675
8683
LY_CHECK_GOTO (rc , cleanup );
8684
+ set -> not_found = args [0 ]-> not_found ;
8676
8685
} else {
8677
- rc = eval_expr_select (exp , tok_idx , 0 , set , options | LYXP_SKIP_EXPR );
8686
+ rc = eval_expr_select (exp , tok_idx , 0 , set , options );
8678
8687
LY_CHECK_GOTO (rc , cleanup );
8679
8688
}
8680
8689
}
@@ -8696,8 +8705,11 @@ eval_function_call(const struct lyxp_expr *exp, uint32_t *tok_idx, struct lyxp_s
8696
8705
8697
8706
rc = eval_expr_select (exp , tok_idx , 0 , args [arg_count - 1 ], options );
8698
8707
LY_CHECK_GOTO (rc , cleanup );
8708
+ if (args [arg_count - 1 ]-> not_found ) {
8709
+ set -> not_found = 1 ;
8710
+ }
8699
8711
} else {
8700
- rc = eval_expr_select (exp , tok_idx , 0 , set , options | LYXP_SKIP_EXPR );
8712
+ rc = eval_expr_select (exp , tok_idx , 0 , set , options );
8701
8713
LY_CHECK_GOTO (rc , cleanup );
8702
8714
}
8703
8715
}
@@ -8990,8 +9002,9 @@ static LY_ERR
8990
9002
eval_union_expr (const struct lyxp_expr * exp , uint32_t * tok_idx , uint32_t repeat , struct lyxp_set * set , uint32_t options )
8991
9003
{
8992
9004
LY_ERR rc = LY_SUCCESS ;
8993
- struct lyxp_set orig_set , set2 ;
8994
9005
uint32_t i ;
9006
+ struct lyxp_set orig_set , set2 ;
9007
+ ly_bool found = 0 ;
8995
9008
8996
9009
assert (repeat );
8997
9010
@@ -9002,6 +9015,11 @@ eval_union_expr(const struct lyxp_expr *exp, uint32_t *tok_idx, uint32_t repeat,
9002
9015
9003
9016
rc = eval_expr_select (exp , tok_idx , LYXP_EXPR_UNION , set , options );
9004
9017
LY_CHECK_GOTO (rc , cleanup );
9018
+ if (set -> not_found ) {
9019
+ set -> not_found = 0 ;
9020
+ } else {
9021
+ found = 1 ;
9022
+ }
9005
9023
9006
9024
/* ('|' PathExpr)* */
9007
9025
for (i = 0 ; i < repeat ; ++ i ) {
@@ -9019,6 +9037,9 @@ eval_union_expr(const struct lyxp_expr *exp, uint32_t *tok_idx, uint32_t repeat,
9019
9037
set_fill_set (& set2 , & orig_set );
9020
9038
rc = eval_expr_select (exp , tok_idx , LYXP_EXPR_UNION , & set2 , options );
9021
9039
LY_CHECK_GOTO (rc , cleanup );
9040
+ if (!set2 .not_found ) {
9041
+ found = 1 ;
9042
+ }
9022
9043
9023
9044
/* eval */
9024
9045
if (options & LYXP_SCNODE_ALL ) {
@@ -9032,6 +9053,9 @@ eval_union_expr(const struct lyxp_expr *exp, uint32_t *tok_idx, uint32_t repeat,
9032
9053
cleanup :
9033
9054
lyxp_set_free_content (& orig_set );
9034
9055
lyxp_set_free_content (& set2 );
9056
+ if (!found ) {
9057
+ set -> not_found = 1 ;
9058
+ }
9035
9059
return rc ;
9036
9060
}
9037
9061
@@ -9099,7 +9123,7 @@ static LY_ERR
9099
9123
eval_multiplicative_expr (const struct lyxp_expr * exp , uint32_t * tok_idx , uint32_t repeat , struct lyxp_set * set ,
9100
9124
uint32_t options )
9101
9125
{
9102
- LY_ERR rc ;
9126
+ LY_ERR rc = LY_SUCCESS ;
9103
9127
uint32_t i , this_op ;
9104
9128
struct lyxp_set orig_set , set2 ;
9105
9129
@@ -9131,6 +9155,9 @@ eval_multiplicative_expr(const struct lyxp_expr *exp, uint32_t *tok_idx, uint32_
9131
9155
set_fill_set (& set2 , & orig_set );
9132
9156
rc = eval_expr_select (exp , tok_idx , LYXP_EXPR_MULTIPLICATIVE , & set2 , options );
9133
9157
LY_CHECK_GOTO (rc , cleanup );
9158
+ if (set2 .not_found ) {
9159
+ set -> not_found = 1 ;
9160
+ }
9134
9161
9135
9162
/* eval */
9136
9163
if (options & LYXP_SCNODE_ALL ) {
@@ -9166,7 +9193,7 @@ eval_multiplicative_expr(const struct lyxp_expr *exp, uint32_t *tok_idx, uint32_
9166
9193
static LY_ERR
9167
9194
eval_additive_expr (const struct lyxp_expr * exp , uint32_t * tok_idx , uint32_t repeat , struct lyxp_set * set , uint32_t options )
9168
9195
{
9169
- LY_ERR rc ;
9196
+ LY_ERR rc = LY_SUCCESS ;
9170
9197
uint32_t i , this_op ;
9171
9198
struct lyxp_set orig_set , set2 ;
9172
9199
@@ -9198,6 +9225,9 @@ eval_additive_expr(const struct lyxp_expr *exp, uint32_t *tok_idx, uint32_t repe
9198
9225
set_fill_set (& set2 , & orig_set );
9199
9226
rc = eval_expr_select (exp , tok_idx , LYXP_EXPR_ADDITIVE , & set2 , options );
9200
9227
LY_CHECK_GOTO (rc , cleanup );
9228
+ if (set2 .not_found ) {
9229
+ set -> not_found = 1 ;
9230
+ }
9201
9231
9202
9232
/* eval */
9203
9233
if (options & LYXP_SCNODE_ALL ) {
@@ -9235,7 +9265,7 @@ eval_additive_expr(const struct lyxp_expr *exp, uint32_t *tok_idx, uint32_t repe
9235
9265
static LY_ERR
9236
9266
eval_relational_expr (const struct lyxp_expr * exp , uint32_t * tok_idx , uint32_t repeat , struct lyxp_set * set , uint32_t options )
9237
9267
{
9238
- LY_ERR rc ;
9268
+ LY_ERR rc = LY_SUCCESS ;
9239
9269
uint32_t i , this_op ;
9240
9270
struct lyxp_set orig_set , set2 ;
9241
9271
@@ -9267,6 +9297,9 @@ eval_relational_expr(const struct lyxp_expr *exp, uint32_t *tok_idx, uint32_t re
9267
9297
set_fill_set (& set2 , & orig_set );
9268
9298
rc = eval_expr_select (exp , tok_idx , LYXP_EXPR_RELATIONAL , & set2 , options );
9269
9299
LY_CHECK_GOTO (rc , cleanup );
9300
+ if (set2 .not_found ) {
9301
+ set -> not_found = 1 ;
9302
+ }
9270
9303
9271
9304
/* eval */
9272
9305
if (options & LYXP_SCNODE_ALL ) {
@@ -9304,7 +9337,7 @@ eval_relational_expr(const struct lyxp_expr *exp, uint32_t *tok_idx, uint32_t re
9304
9337
static LY_ERR
9305
9338
eval_equality_expr (const struct lyxp_expr * exp , uint32_t * tok_idx , uint32_t repeat , struct lyxp_set * set , uint32_t options )
9306
9339
{
9307
- LY_ERR rc ;
9340
+ LY_ERR rc = LY_SUCCESS ;
9308
9341
uint32_t i , this_op ;
9309
9342
struct lyxp_set orig_set , set2 ;
9310
9343
@@ -9336,6 +9369,9 @@ eval_equality_expr(const struct lyxp_expr *exp, uint32_t *tok_idx, uint32_t repe
9336
9369
set_fill_set (& set2 , & orig_set );
9337
9370
rc = eval_expr_select (exp , tok_idx , LYXP_EXPR_EQUALITY , & set2 , options );
9338
9371
LY_CHECK_GOTO (rc , cleanup );
9372
+ if (set2 .not_found ) {
9373
+ set -> not_found = 1 ;
9374
+ }
9339
9375
9340
9376
/* eval */
9341
9377
if (options & LYXP_SCNODE_ALL ) {
@@ -9374,7 +9410,7 @@ eval_equality_expr(const struct lyxp_expr *exp, uint32_t *tok_idx, uint32_t repe
9374
9410
static LY_ERR
9375
9411
eval_and_expr (const struct lyxp_expr * exp , uint32_t * tok_idx , uint32_t repeat , struct lyxp_set * set , uint32_t options )
9376
9412
{
9377
- LY_ERR rc ;
9413
+ LY_ERR rc = LY_SUCCESS ;
9378
9414
struct lyxp_set orig_set , set2 ;
9379
9415
uint32_t i ;
9380
9416
@@ -9414,6 +9450,9 @@ eval_and_expr(const struct lyxp_expr *exp, uint32_t *tok_idx, uint32_t repeat, s
9414
9450
set_fill_set (& set2 , & orig_set );
9415
9451
rc = eval_expr_select (exp , tok_idx , LYXP_EXPR_AND , & set2 , options );
9416
9452
LY_CHECK_GOTO (rc , cleanup );
9453
+ if (set2 .not_found ) {
9454
+ set -> not_found = 1 ;
9455
+ }
9417
9456
9418
9457
/* eval - just get boolean value actually */
9419
9458
if (set -> type == LYXP_SET_SCNODE_SET ) {
@@ -9446,7 +9485,7 @@ eval_and_expr(const struct lyxp_expr *exp, uint32_t *tok_idx, uint32_t repeat, s
9446
9485
static LY_ERR
9447
9486
eval_or_expr (const struct lyxp_expr * exp , uint32_t * tok_idx , uint32_t repeat , struct lyxp_set * set , uint32_t options )
9448
9487
{
9449
- LY_ERR rc ;
9488
+ LY_ERR rc = LY_SUCCESS ;
9450
9489
struct lyxp_set orig_set , set2 ;
9451
9490
uint32_t i ;
9452
9491
@@ -9488,6 +9527,9 @@ eval_or_expr(const struct lyxp_expr *exp, uint32_t *tok_idx, uint32_t repeat, st
9488
9527
* but it does not matter */
9489
9528
rc = eval_expr_select (exp , tok_idx , LYXP_EXPR_OR , & set2 , options );
9490
9529
LY_CHECK_GOTO (rc , cleanup );
9530
+ if (set2 .not_found ) {
9531
+ set -> not_found = 1 ;
9532
+ }
9491
9533
9492
9534
/* eval - just get boolean value actually */
9493
9535
if (set -> type == LYXP_SET_SCNODE_SET ) {
@@ -9674,7 +9716,10 @@ lyxp_eval(const struct ly_ctx *ctx, const struct lyxp_expr *exp, const struct ly
9674
9716
9675
9717
/* evaluate */
9676
9718
rc = eval_expr_select (exp , & tok_idx , 0 , set , options );
9677
- if (rc != LY_SUCCESS ) {
9719
+ if (!rc && set -> not_found ) {
9720
+ rc = LY_ENOTFOUND ;
9721
+ }
9722
+ if (rc ) {
9678
9723
lyxp_set_free_content (set );
9679
9724
}
9680
9725
@@ -9915,7 +9960,7 @@ lyxp_atomize(const struct ly_ctx *ctx, const struct lyxp_expr *exp, const struct
9915
9960
LY_VALUE_FORMAT format , void * prefix_data , const struct lysc_node * cur_scnode ,
9916
9961
const struct lysc_node * ctx_scnode , struct lyxp_set * set , uint32_t options )
9917
9962
{
9918
- LY_ERR ret ;
9963
+ LY_ERR rc ;
9919
9964
uint32_t tok_idx = 0 ;
9920
9965
9921
9966
LY_CHECK_ARG_RET (ctx , ctx , exp , set , LY_EINVAL );
@@ -9943,10 +9988,13 @@ lyxp_atomize(const struct ly_ctx *ctx, const struct lyxp_expr *exp, const struct
9943
9988
LOG_LOCSET (set -> cur_scnode , NULL , NULL , NULL );
9944
9989
9945
9990
/* evaluate */
9946
- ret = eval_expr_select (exp , & tok_idx , 0 , set , options );
9991
+ rc = eval_expr_select (exp , & tok_idx , 0 , set , options );
9992
+ if (!rc && set -> not_found ) {
9993
+ rc = LY_ENOTFOUND ;
9994
+ }
9947
9995
9948
9996
LOG_LOCBACK (set -> cur_scnode ? 1 : 0 , 0 , 0 , 0 );
9949
- return ret ;
9997
+ return rc ;
9950
9998
}
9951
9999
9952
10000
LIBYANG_API_DEF const char *
0 commit comments