Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lyd_insert_after sets prev/next pointers incorrectly #19

Closed
lukasmacko opened this issue Feb 9, 2016 · 0 comments
Closed

lyd_insert_after sets prev/next pointers incorrectly #19

lukasmacko opened this issue Feb 9, 2016 · 0 comments
Assignees

Comments

@lukasmacko
Copy link
Contributor

The program creates node in order l1, l2, l3 and the tries to adjust the order to be l2, l1, l3.

#include <stdio.h>
#include <stdlib.h>
#include <libyang/libyang.h>

int main(int argc, char **argv)
{
    struct ly_ctx *ctx = ly_ctx_new(".");
    const struct lys_module *test_module = ly_ctx_load_module(ctx, "test-module", NULL);

    if (NULL == test_module){
        puts("load module failed");
        return 1;
    }   

    struct lyd_node *l1 = lyd_new(NULL, test_module, "list");
    lyd_new_leaf(l1, test_module, "key", "A");

    struct lyd_node *l2 = lyd_new(NULL, test_module, "list");
    lyd_new_leaf(l2, test_module, "key", "B");


    struct lyd_node *l3 = lyd_new(NULL, test_module, "list");
    lyd_new_leaf(l3, test_module, "key", "C");

    lyd_insert_after(l1, l2);
    lyd_insert_after(l2, l3);

    /* ERROR*/
    lyd_insert_after(l2, l1); 

   /* THIS WORK as expected
    lyd_insert_before(l1, l2); */

    lyd_free_withsiblings(l1);

    ly_ctx_destroy(ctx, NULL);
    return 0;
}

It might be related to the fact that reordered nodes has no parent (top-level nodes)

The program sets pointer like this:
incorrect

The expected state(in comment):
expected

test-module.yang

module test-module {
  namespace "urn:ietf:params:xml:ns:yang:test-module";
  prefix tm;

  organization "organization";
  description
    "example yang module";

  list list {
    key "key";
    leaf key {
      type string;
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants