# HG changeset patch # User Mike Becker # Date 1681063244 -7200 # Node ID 19379743e5a0f101004424a4ccffc96ef8c4828c # Parent 022fbd4bc0577fa0f463c4d4477e31d820a40cc0 fix wrong operator precedence in destructor macros diff -r 022fbd4bc057 -r 19379743e5a0 src/cx/collection.h --- a/src/cx/collection.h Sun Apr 09 19:37:00 2023 +0200 +++ b/src/cx/collection.h Sun Apr 09 20:00:44 2023 +0200 @@ -112,7 +112,7 @@ * @param e the element */ #define cx_invoke_simple_destructor(c, e) \ - (c)->simple_destructor((c)->store_pointer ? (*((void **) e)) : e) + (c)->simple_destructor((c)->store_pointer ? (*((void **) (e))) : (e)) /** * Invokes the advanced destructor function for a specific element. @@ -125,7 +125,7 @@ */ #define cx_invoke_advanced_destructor(c, e) \ (c)->advanced_destructor((c)->destructor_data, \ - (c)->store_pointer ? (*((void **) e)) : e) + (c)->store_pointer ? (*((void **) (e))) : (e)) #define cx_invoke_destructor(c, e) \ diff -r 022fbd4bc057 -r 19379743e5a0 src/list.c --- a/src/list.c Sun Apr 09 19:37:00 2023 +0200 +++ b/src/list.c Sun Apr 09 20:00:44 2023 +0200 @@ -219,11 +219,11 @@ CxList const *list, CxList const *other ) { - if (list->cl->compare == other->cl->compare) { - // same compare function, lists are compatible - return list->cl->compare(list, other); - } else { - // different compare functions, use iterator + if ((list->store_pointer ^ other->store_pointer) || + ((list->climpl == NULL) ^ (other->climpl != NULL)) || + ((list->climpl != NULL ? list->climpl->compare : list->cl->compare) != + (other->climpl != NULL ? other->climpl->compare : other->cl->compare))) { + // lists are definitely different - cannot use internal compare function if (list->size == other->size) { CxIterator left = cxListIterator(list); CxIterator right = cxListIterator(other); @@ -241,6 +241,9 @@ } else { return list->size < other->size ? -1 : 1; } + } else { + // lists are compatible + return list->cl->compare(list, other); } } diff -r 022fbd4bc057 -r 19379743e5a0 tests/test_list.cpp --- a/tests/test_list.cpp Sun Apr 09 19:37:00 2023 +0200 +++ b/tests/test_list.cpp Sun Apr 09 20:00:44 2023 +0200 @@ -751,8 +751,6 @@ cxListClear(list); EXPECT_EQ(testdata_len, destr_test_ctr); EXPECT_EQ(testdata.data[testdata_len - 1], destr_last_value + off); - - } void verifySimpleDestructor(CxList *list) {