Sun, 26 Oct 2025 11:50:33 +0100
default NULL allocator to cxDefaultAllocator
| docs/Writerside/topics/allocator.h.md | file | annotate | diff | comparison | revisions | |
| src/list.c | file | annotate | diff | comparison | revisions | |
| src/map.c | file | annotate | diff | comparison | revisions |
--- 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
--- 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 +}
--- 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)) {