| 337 cxFreeDefault(tmp); |
337 cxFreeDefault(tmp); |
| 338 |
338 |
| 339 return 0; |
339 return 0; |
| 340 } |
340 } |
| 341 |
341 |
| 342 static int cx_list_ccmp_safe_memcmp(const void *a, const void *b, void *c) { |
342 static int cx_list_cmpfunc2_safe_memcmp(const void *a, const void *b, void *c) { |
| 343 // it is not safe to store a pointer to the size in the list |
343 // it is not safe to store a pointer to the size in the list |
| 344 // because the entire list structure might get reallocated |
344 // because the entire list structure might get reallocated |
| 345 size_t elem_size = (size_t)(uintptr_t)c; |
345 size_t elem_size = (size_t)(uintptr_t)c; |
| 346 return memcmp(a, b, elem_size); |
346 return memcmp(a, b, elem_size); |
| 347 } |
347 } |
| 357 list->collection.size = 0; |
357 list->collection.size = 0; |
| 358 list->collection.sorted = false; // should be set by the implementation |
358 list->collection.sorted = false; // should be set by the implementation |
| 359 if (elem_size > 0) { |
359 if (elem_size > 0) { |
| 360 list->collection.elem_size = elem_size; |
360 list->collection.elem_size = elem_size; |
| 361 list->collection.simple_cmp = NULL; |
361 list->collection.simple_cmp = NULL; |
| 362 list->collection.advanced_cmp = cx_list_ccmp_safe_memcmp; |
362 list->collection.advanced_cmp = cx_list_cmpfunc2_safe_memcmp; |
| 363 list->collection.cmp_data = (void*)(uintptr_t)list->collection.elem_size; |
363 list->collection.cmp_data = (void*)(uintptr_t)list->collection.elem_size; |
| 364 list->collection.store_pointer = false; |
364 list->collection.store_pointer = false; |
| 365 } else { |
365 } else { |
| 366 list->collection.elem_size = sizeof(void *); |
366 list->collection.elem_size = sizeof(void *); |
| 367 list->collection.simple_cmp = cx_cmp_ptr; |
367 list->collection.simple_cmp = cx_cmp_ptr; |