# HG changeset patch # User Mike Becker # Date 1705164702 -3600 # Node ID 5136f2fc32ecdd5e492285bd6da152a1c0996de5 # Parent 0711d869ce4d536f2c16de6a045663e0dd6243ae add CX_DISABLE_ARRAY_LIST_SWAP_SBO flag diff -r 0711d869ce4d -r 5136f2fc32ec src/array_list.c --- a/src/array_list.c Fri Jan 12 20:24:29 2024 +0100 +++ b/src/array_list.c Sat Jan 13 17:51:42 2024 +0100 @@ -107,6 +107,8 @@ #define CX_ARRAY_SWAP_SBO_SIZE 128 #endif +bool CX_DISABLE_ARRAY_LIST_SWAP_SBO = false; + void cx_array_swap( void *arr, size_t elem_size, @@ -122,7 +124,7 @@ void *tmp; // decide if we can use the local buffer - if (elem_size > CX_ARRAY_SWAP_SBO_SIZE) { + if (elem_size > CX_ARRAY_SWAP_SBO_SIZE || CX_DISABLE_ARRAY_LIST_SWAP_SBO) { tmp = malloc(elem_size); // we don't want to enforce error handling if (tmp == NULL) abort(); diff -r 0711d869ce4d -r 5136f2fc32ec src/cx/array_list.h --- a/src/cx/array_list.h Fri Jan 12 20:24:29 2024 +0100 +++ b/src/cx/array_list.h Sat Jan 13 17:51:42 2024 +0100 @@ -45,6 +45,12 @@ #endif /** + * Set this flag to true, if you want to disable the use of SBO for + * array list swap operations. + */ +extern bool CX_DISABLE_ARRAY_LIST_SWAP_SBO; + +/** * Defines a reallocation mechanism for arrays. */ struct cx_array_reallocator_s { diff -r 0711d869ce4d -r 5136f2fc32ec tests/test_list.c --- a/tests/test_list.c Fri Jan 12 20:24:29 2024 +0100 +++ b/tests/test_list.c Sat Jan 13 17:51:42 2024 +0100 @@ -1086,8 +1086,9 @@ CX_TEST_CALL_SUBROUTINE(test_list_verify_swap, list, isptrlist, true); CX_DISABLE_LINKED_LIST_SWAP_SBO = false; } else { - // TODO: currently, SBO for swap operation cannot be disabled for array lists - CX_TEST_ASSERT(true); + CX_DISABLE_ARRAY_LIST_SWAP_SBO = true; + CX_TEST_CALL_SUBROUTINE(test_list_verify_swap, list, isptrlist, false); + CX_DISABLE_ARRAY_LIST_SWAP_SBO = false; } })