weixin_39980893
weixin_39980893
2020-12-01 18:43

lys_xpath_atomize works unexpectedly

Hi, it seems lys_xpath_atomize can not work in latest devel branch, below is my test code:

c
int main(void)
{
    struct ly_ctx *ly_ctx = ly_ctx_new(NULL, 0);

    const struct lys_module *module = lys_parse_path(ly_ctx, "a.yang", LYS_IN_YANG);
    printf("load a %s\n", module ? "success" : "failure");
    const struct lys_module *module2 = lys_parse_path(ly_ctx, "b.yang", LYS_IN_YANG);
    printf("load b %s\n", module2 ? "success" : "failure");

    struct ly_set *set = lys_xpath_atomize(module->data, LYXP_NODE_ELEM,
            "/a:A/A1/b:B[k1=1]/C[k2=1]", 0);
    assert(set);
    assert(set->number);
    printf("count: %d, last: %s\n", set->number, set->set.s[set->number - 1]->name);
    ly_set_free(set);

    ly_ctx_destroy(ly_ctx, NULL);
    return 0;
}

the output is


load a success
load b success
exe: /root/svn/nfoam/libyang/src/xpath.c:6847: eval_predicate: Assertion `exp->tokens[*exp_idx] == LYXP_TOKEN_BRACK2' failed.
Aborted

a.yang.txt b.yang.txt

该提问来源于开源项目:CESNET/libyang

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • weixin_39980893 weixin_39980893 4月前

    Hi, Oh, it's also the documentation that made me thought it should use data path here. In fact, I got this issue from sysrepo, which also used lys_xpath_atomize with data path in JSON format. Have you already notified sysrepo guys about this change?

    点赞 评论 复制链接分享
  • weixin_39980893 weixin_39980893 4月前

    I just want to tell sysrepo also used lys_xpath_atomize with data path like /a:A/A1/b:B[k1=1]/C[k2=1]. :)

    点赞 评论 复制链接分享
  • weixin_39857792 weixin_39857792 4月前

    Hi, I was hoping for a more specific report, but I think I found the place where data paths were used instead schema ones and the pull request should fix it (recent devel of libyang is required). Please, try it again and let me know whether it works fine now or not, thanks.

    Regards, Michal

    点赞 评论 复制链接分享
  • weixin_39980893 weixin_39980893 4月前

    Hi, I have got latest libyang and your patch(sysrepo/sysrepo#964), and it fixed my issue. Thanks for your help.

    点赞 评论 复制链接分享