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

Feature request: Wrapper for lyd_compare_single and lyd_compare_siblings #19

Closed
rbu9fe opened this issue Nov 24, 2023 · 7 comments
Closed

Comments

@rbu9fe
Copy link

rbu9fe commented Nov 24, 2023

As the title says the wrapper lacks support for lyd_compare_single and lyd_compare_siblings as the data node's operator== only compares whether the two nodes point to the very same item rather than comparing whether they have the same contents.
Is there a chance to get this functionality?

@jktjkt
Copy link
Contributor

jktjkt commented Nov 24, 2023

Sure. This is an opportunity for getting the API "right", so I wonder which of these you would prefer. Given this definition:

auto node1 = ...;
auto node2 = ...;

Either a symbolic approach:

if (node1.siblings() == node2.siblings()) {
    // ...
}

if (node1.wholeTree() == node2.wholeTree()) {
    // ...
}

or a C-like approach:

if (siblingsEqual(node1, node2)) {
    // ...
}

if (subtreesEqual(node1, node2))  {
  // ...
}

In the symbolic approach, wholeTree would be just as proxy class for comparisons, while siblings is a Collection<T, U> already, so it's just a matter for adding a suitable comparison operator.

@rbu9fe
Copy link
Author

rbu9fe commented Nov 24, 2023

Great! I guess I would prefer the symbolic approach, but I'm fine with whatever fits bests into the current design.

@syyyr
Copy link
Contributor

syyyr commented Nov 24, 2023

Could also go with the "java" approach:

if (node1.siblingsEqual(node2)) {
    // ...
}

if (node1.subtreesEqual(node2)) {
    // ...
}

It's easier to find methods like these through code completion (more than the operator== or the free function version IMHO).

It would also sort of follow the principle of how we wrap the functions - foo(node, args...) turns into node.foo(args...).

Also, lyd_compare_single has a "Data compare options" argument. Would it be possible to specify this argument, if we were to use operator== version?

@syyyr
Copy link
Contributor

syyyr commented Nov 24, 2023

Maybe I have missed that .wholeTree() is probably specifying the LYD_COMPARE_FULL_RECURSION flag... that would solve the options issue (but idk about LYD_COMPARE_DEFAULTS or LYD_COMPARE_OPAQ). Anyway, the Java approach is still an option.

@rbu9fe
Copy link
Author

rbu9fe commented Jan 17, 2024

Just curious, is there any progress on this?

@jktjkt
Copy link
Contributor

jktjkt commented Jan 19, 2024

jktjkt added a commit that referenced this issue Jan 19, 2024
Bug: #19
Change-Id: I5c48212a90cc4b538fa6582a5682a3b52b88785f
@rbu9fe
Copy link
Author

rbu9fe commented Jan 19, 2024

Looks nice to me!

@jktjkt jktjkt closed this as completed Apr 16, 2024
jktjkt pushed a commit that referenced this issue Sep 6, 2024
There is ODR violation in libyang tests reported by ASan which breaks
our CI builds. This commit temporarily (until this gets solved in
upstream) pins the libyang version to 3.0.18 which builds just fine.

The log from ASan:

  52/60 Test #31: utest_plugins .....................***Failed    1.22 sec
  [==========] tests: Running 4 test(s).
  [ RUN      ] test_add_invalid
  [       OK ] test_add_invalid
  [ RUN      ] test_add_simple
  =================================================================
  ==2826==ERROR: AddressSanitizer: odr-violation (0x7f6d170dcb40):
    [1] size=24 'ly_version_so' /home/ci/src/cesnet-gerrit-public/github/CESNET/libyang/src/ly_common.c:43
    [2] size=24 'ly_version_so' /home/ci/src/cesnet-gerrit-public/github/CESNET/libyang/src/ly_common.c:43
  These globals were registered at these points:
    [1]:
      #0 0x437ffa in __asan_register_globals (/home/ci/build/github/CESNET/libyang/tests/utest_plugins+0x437ffa) (BuildId: e79d14f37e59b6533b66d19363b25fea9e324edb)
      #1 0x7f6d16691b9e in asan.module_ctor ly_common.c
      #2 0x7f6d1aad7236 in call_init /usr/src/debug/glibc-2.37-18.fc38.x86_64/elf/dl-init.c:74:3
      #3 0x7f6d1aad7236 in call_init /usr/src/debug/glibc-2.37-18.fc38.x86_64/elf/dl-init.c:26:1
      #4 0x7f6d1aad732c in _dl_init /usr/src/debug/glibc-2.37-18.fc38.x86_64/elf/dl-init.c:121:5
      #5 0x7f6d1aad35c1 in _dl_catch_exception /usr/src/debug/glibc-2.37-18.fc38.x86_64/elf/dl-catch.c:211:7
      #6 0x7f6d1aaddeeb in dl_open_worker /usr/src/debug/glibc-2.37-18.fc38.x86_64/elf/dl-open.c:827:5
      #7 0x7f6d1aad3522 in _dl_catch_exception /usr/src/debug/glibc-2.37-18.fc38.x86_64/elf/dl-catch.c:237:8
      #8 0x7f6d1aade2e3 in _dl_open /usr/src/debug/glibc-2.37-18.fc38.x86_64/elf/dl-open.c:903:17
      #9 0x7f6d1a7b5713 in dlopen_doit /usr/src/debug/glibc-2.37-18.fc38.x86_64/dlfcn/dlopen.c:56:15
      #10 0x7f6d1aad3522 in _dl_catch_exception /usr/src/debug/glibc-2.37-18.fc38.x86_64/elf/dl-catch.c:237:8
      #11 0x7f6d1aad3678 in _dl_catch_error /usr/src/debug/glibc-2.37-18.fc38.x86_64/elf/dl-catch.c:256:19
      #12 0x7f6d1a7b51f2 in _dlerror_run /usr/src/debug/glibc-2.37-18.fc38.x86_64/dlfcn/dlerror.c:138:17
      #13 0x7f6d1a7b57ce  /usr/src/debug/glibc-2.37-18.fc38.x86_64/dlfcn/dlopen.c:71:10
      #14 0x7f6d1a7b57ce in dlopen@@GLIBC_2.34 /usr/src/debug/glibc-2.37-18.fc38.x86_64/dlfcn/dlopen.c:81:12
      #15 0x485f82 in dlopen (/home/ci/build/github/CESNET/libyang/tests/utest_plugins+0x485f82) (BuildId: e79d14f37e59b6533b66d19363b25fea9e324edb)
      #16 0xcb5ee3 in plugins_load_module /home/ci/src/cesnet-gerrit-public/github/CESNET/libyang/src/plugins.c:378:17
      #17 0xcb5e67 in lyplg_add /home/ci/src/cesnet-gerrit-public/github/CESNET/libyang/src/plugins.c:589:11
      #18 0xea2a60 in test_add_simple /home/ci/src/cesnet-gerrit-public/github/CESNET/libyang/tests/utests/basic/test_plugins.c:50:5
      #19 0x7f6d1aac218f  (/lib64/libcmocka.so.0+0x618f) (BuildId: 785844a0941c0bde763740a981d056f60aa9c7b7)
      #20 0x7f6d1aac2904 in _cmocka_run_group_tests (/lib64/libcmocka.so.0+0x6904) (BuildId: 785844a0941c0bde763740a981d056f60aa9c7b7)
      #21 0xea21a2 in main /home/ci/src/cesnet-gerrit-public/github/CESNET/libyang/tests/utests/basic/test_plugins.c:152:12

Change-Id: Id8a4771296d2e85de2ec29fbd17046d280d2eda2
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

3 participants