# HG changeset patch # User Mike Becker # Date 1761475833 -3600 # Node ID 5732947cbcc2bcfedfaca308d6bf91db86b6250e # Parent e8089a590b71197e85faf350e8f5a9de81b956ae default NULL allocator to cxDefaultAllocator diff -r e8089a590b71 -r 5732947cbcc2 docs/Writerside/topics/allocator.h.md --- a/docs/Writerside/topics/allocator.h.md Sat Oct 25 21:33:56 2025 +0200 +++ b/docs/Writerside/topics/allocator.h.md Sun Oct 26 11:50:33 2025 +0100 @@ -191,6 +191,8 @@ The `source` pointer is never `NULL` and points to the source object. The optional `data` pointer can be used to pass additional state. +All allocations should be performed by the specified allocator, which is guaranteed to be not `NULL`. + A very basic clone function that performs a deep copy of a struct with two strings is shown below. ```C diff -r e8089a590b71 -r 5732947cbcc2 src/list.c --- a/src/list.c Sat Oct 25 21:33:56 2025 +0200 +++ b/src/list.c Sun Oct 26 11:50:33 2025 +0100 @@ -806,7 +806,8 @@ } int cxListClone(CxList *dst, const CxList *src, cx_clone_func clone_func, - const CxAllocator *clone_allocator, void *data) { + const CxAllocator *clone_allocator, void *data) { + if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator; // remember the original size size_t orig_size = dst->collection.size; @@ -861,4 +862,4 @@ } return 0; -} \ No newline at end of file +} diff -r e8089a590b71 -r 5732947cbcc2 src/map.c --- a/src/map.c Sat Oct 25 21:33:56 2025 +0200 +++ b/src/map.c Sun Oct 26 11:50:33 2025 +0100 @@ -142,6 +142,7 @@ int cxMapClone(CxMap *dst, const CxMap *src, cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data) { + if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator; CxMapIterator src_iter = cxMapIterator(src); if (cxCollectionStoresPointers(dst)) { for (size_t i = 0; i < cxMapSize(src); i++) { @@ -177,6 +178,8 @@ int cxMapDifference(CxMap *dst, const CxMap *minuend, const CxMap *subtrahend, cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data) { + if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator; + const bool map_was_not_empty = cxMapSize(dst) > 0; CxMapIterator src_iter = cxMapIterator(minuend); if (cxCollectionStoresPointers(dst)) {