weixin_39789979
weixin_39789979
2020-12-28 06:29

lys_submodule_parse hangs?

Hi, We are making use of some libyang APIs for the ydk project. libyang seems to have an issue with parsing submodule with lys_submodule_parse. First the yang module is retrieved by calling the set module callback (which is set using ly_ctx_set_module_clb). Then lys_submodule_parse is called in context.c and this function hangs...

To reproduce, use the below test case and attached models:


struct ly_ctx *g_ctx;

char* get_module_callback(const char* module_name, const char* module_rev, const char *submod_name, const char *sub_rev,  void* user_data, LYS_INFORMAT* format, void (**free_module_data)(void *model_data))
{
    char* strp = NULL;
    struct ly_ctx* ctx = g_ctx; 
    const struct lys_submodule* submodule = ly_ctx_get_submodule(ctx, module_name, module_rev, submod_name, sub_rev);
    if(!lys_print_mem(&strp, (const struct lys_module*)submodule, LYS_OUT_YANG, NULL))
    {
        return strp;
    }
    return NULL;
}

static void test_submodule_callback(void **state)
{
    LYS_INFORMAT format = LYS_IN_YANG;
    struct ly_ctx* ctx = ly_ctx_new(TESTS_DIR"/schema/yang/files");
    void (*module_data_free)(void *module_data) = NULL;
    const struct lys_module * module = ly_ctx_load_module(ctx, "b",NULL);
    g_ctx = ctx;

    ly_ctx_set_module_clb(ctx, get_module_callback, (&ctx));

    struct ly_ctx* newctx;
    ly_module_clb clb = ly_ctx_get_module_clb(ctx, (void**)&newctx);

    char * module_data = clb("b",NULL,"bsub",NULL,&newctx, &format, &module_data_free);
    printf("%s", module_data); // printf shows the submodule is retrieved correctly

    const struct lys_module * m = lys_submodule_parse(module, module_data, format, NULL); //program hangs at this point
     assert_ptr_not_equal(m, NULL);
}

Any idea what the issue could be?

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

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

4条回答

  • weixin_39857792 weixin_39857792 3月前

    Hi, lys_submodule_parse() is not part of the public API, why are you calling it?

    Regards, Michal

    点赞 评论 复制链接分享
  • weixin_39789979 weixin_39789979 3月前

    Hi Michal,

    Sorry should have clarified above. We're not directly calling this function. We are setting the ly_ctx_set_module_clb. Then when we create the libyang context,. It is getting called in context.c. however at this point, the program is hanging.

    Thanks, Abhi

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

    Hi Abhi, okay, then please provide a use-case I can replicate the issue with. But looking at the code, your callback is probably the problem. I tried to clarify the description, but it said even before that the callback is for missing imports and includes. In your case it is called first when libyang is searching for the submodule bsub and instead providing the submodule data, you are asking libyang for it back. Generally, you do not need to define module callback, it is needed only for quite specific cases.

    Regards, Michal

    点赞 评论 复制链接分享
  • weixin_39789979 weixin_39789979 3月前

    Thanks. I modified the callback to not look into the context, and now the issue is no longer there.

    点赞 评论 复制链接分享