Sun, 14 Dec 2025 15:41:02 +0100
change signature of cxBufferInit() and cxBufferCreate()
relates to #780
| CHANGELOG | file | annotate | diff | comparison | revisions | |
| docs/Writerside/topics/about.md | file | annotate | diff | comparison | revisions | |
| docs/Writerside/topics/buffer.h.md | file | annotate | diff | comparison | revisions | |
| docs/Writerside/topics/streams.h.md | file | annotate | diff | comparison | revisions | |
| docs/Writerside/topics/test.h.md | file | annotate | diff | comparison | revisions | |
| src/buffer.c | file | annotate | diff | comparison | revisions | |
| src/cx/buffer.h | file | annotate | diff | comparison | revisions | |
| src/json.c | file | annotate | diff | comparison | revisions | |
| src/properties.c | file | annotate | diff | comparison | revisions | |
| tests/test_buffer.c | file | annotate | diff | comparison | revisions | |
| tests/test_json.c | file | annotate | diff | comparison | revisions | |
| tests/test_printf.c | file | annotate | diff | comparison | revisions | |
| tests/test_streams.c | file | annotate | diff | comparison | revisions |
--- a/CHANGELOG Sun Dec 14 14:29:27 2025 +0100 +++ b/CHANGELOG Sun Dec 14 15:41:02 2025 +0100 @@ -10,10 +10,12 @@ * adds cxBufferMaximumCapacity() * adds cxBufferAppendString() * adds CX_BUFFER_DO_NOT_FREE buffer flag + * changes parameter order of cxBufferInit() and cxBufferCreate() * changes cxBufferReserve() to allow reducing the capacity * changes cxBufferTerminate() to automatically shrink the buffer * changes cxBufferTerminate() so that position and size are equal a after successful operation * changes cxBufferPutString() to accept any kind of string that cx_strcast() supports + * changes the entire low-level array-list API by making it much simpler * changes the members of CxJson and CxJsonValue * changes the return value of cxJsonObjIter() to CxMapIterator * changes CxTree structure so that it now inherits CX_COLLECTION_BASE @@ -30,6 +32,7 @@ * removes the sort_members feature from CxJsonWriter * removes the source and sink API from properties.h * removes the flush feature from CxBuffer + * removes several unnecessary convenience functions Version 3.2 - 2025-11-30 ------------------------
--- a/docs/Writerside/topics/about.md Sun Dec 14 14:29:27 2025 +0100 +++ b/docs/Writerside/topics/about.md Sun Dec 14 15:41:02 2025 +0100 @@ -37,10 +37,12 @@ * adds cxBufferMaximumCapacity() * adds cxBufferAppendString() * adds CX_BUFFER_DO_NOT_FREE buffer flag +* changes parameter order of cxBufferInit() and cxBufferCreate() * changes cxBufferReserve() to allow reducing the capacity * changes cxBufferTerminate() to automatically shrink the buffer * changes cxBufferTerminate() so that position and size are equal after a successful operation * changes cxBufferPutString() to accept any kind of string that cx_strcast() supports +* changes the entire low-level array-list API by making it much simpler * changes the members of CxJson and CxJsonValue * changes the return value of cxJsonObjIter() to CxMapIterator * changes CxTree structure so that it now inherits CX_COLLECTION_BASE @@ -57,6 +59,7 @@ * removes the sort_members feature from CxJsonWriter * removes the source and sink API from properties.h * removes the flush feature from CxBuffer +* removes several unnecessary convenience functions ### Version 3.2 - 2025-11-30 {collapsible="true"}
--- a/docs/Writerside/topics/buffer.h.md Sun Dec 14 14:29:27 2025 +0100 +++ b/docs/Writerside/topics/buffer.h.md Sun Dec 14 15:41:02 2025 +0100 @@ -33,9 +33,8 @@ // initialize buffer and use stack memory for small requests char stackmem[128]; CxBuffer buf; - cxBufferInit( + cxBufferInit(cxDefaultAllocator, &buf, stackmem, sizeof(stackmem), - cxDefaultAllocator, CX_BUFFER_COPY_ON_EXTEND // move to heap when request is larger ); @@ -66,11 +65,12 @@ ```C #include <cx/buffer.h> -int cxBufferInit(CxBuffer *buffer, void *space, size_t capacity, - const CxAllocator *allocator, int flags); +int cxBufferInit(CxBuffer *buffer, + const CxAllocator *allocator, + void *space, size_t capacity, int flags); -CxBuffer *cxBufferCreate(void *space,size_t capacity, - const CxAllocator *allocator, int flags); +CxBuffer *cxBufferCreate(const CxAllocator *allocator, + void *space,size_t capacity, int flags); // available flags: #define CX_BUFFER_DEFAULT
--- a/docs/Writerside/topics/streams.h.md Sun Dec 14 14:29:27 2025 +0100 +++ b/docs/Writerside/topics/streams.h.md Sun Dec 14 15:41:02 2025 +0100 @@ -59,7 +59,7 @@ FILE *inputfile = fopen(infilename, "r"); if (inputfile) { CxBuffer fbuf; - cxBufferInit(&fbuf, NULL, 4096, NULL, CX_BUFFER_AUTO_EXTEND); + cxBufferInit(&fbuf, NULL, NULL, 4096, CX_BUFFER_AUTO_EXTEND); cx_stream_copy(inputfile, &fbuf, (cx_read_func) fread, cxBufferWriteFunc);
--- a/docs/Writerside/topics/test.h.md Sun Dec 14 14:29:27 2025 +0100 +++ b/docs/Writerside/topics/test.h.md Sun Dec 14 15:41:02 2025 +0100 @@ -73,7 +73,7 @@ <code-block lang="C"> // for example: UCX buffer CxBuffer buf; -cxBufferInit(&buf, NULL, 1024, NULL, 0); +cxBufferInit(&buf, NULL, NULL, 1024, 0); cx_test_run(suite, &buf, cxBufferWriteFunc); // do something with the buffer cxBufferDestroy(&buf);
--- a/src/buffer.c Sun Dec 14 14:29:27 2025 +0100 +++ b/src/buffer.c Sun Dec 14 15:41:02 2025 +0100 @@ -45,11 +45,11 @@ int cxBufferInit( CxBuffer *buffer, + const CxAllocator *allocator, void *space, size_t capacity, - const CxAllocator *allocator, int flags -) { + ) { if (allocator == NULL) { allocator = cxDefaultAllocator; } @@ -82,17 +82,17 @@ } CxBuffer *cxBufferCreate( + const CxAllocator *allocator, void *space, size_t capacity, - const CxAllocator *allocator, int flags -) { + ) { if (allocator == NULL) { allocator = cxDefaultAllocator; } CxBuffer *buf = cxMalloc(allocator, sizeof(CxBuffer)); if (buf == NULL) return NULL; // LCOV_EXCL_LINE - if (0 == cxBufferInit(buf, space, capacity, allocator, flags)) { + if (0 == cxBufferInit(buf, allocator, space, capacity, flags)) { return buf; } else { // LCOV_EXCL_START
--- a/src/cx/buffer.h Sun Dec 14 14:29:27 2025 +0100 +++ b/src/cx/buffer.h Sun Dec 14 15:41:02 2025 +0100 @@ -168,18 +168,18 @@ * space will be leaking after the copy-on-write operation. * * @param buffer the buffer to initialize + * @param allocator the allocator this buffer shall use for automatic + * memory management + * (if @c NULL, the cxDefaultAllocator will be used) * @param space pointer to the memory area, or @c NULL to allocate * new memory * @param capacity the capacity of the buffer - * @param allocator the allocator this buffer shall use for automatic - * memory management - * (if @c NULL, the cxDefaultAllocator will be used) * @param flags buffer features (see cx_buffer_s.flags) * @return zero on success, non-zero if a required allocation failed */ cx_attr_nonnull_arg(1) -CX_EXPORT int cxBufferInit(CxBuffer *buffer, void *space, size_t capacity, - const CxAllocator *allocator, int flags); +CX_EXPORT int cxBufferInit(CxBuffer *buffer, const CxAllocator *allocator, + void *space, size_t capacity, int flags); /** * Destroys the buffer contents. @@ -219,18 +219,18 @@ * Then this function will allocate the space and enforce * the #CX_BUFFER_FREE_CONTENTS flag. * + * @param allocator the allocator to use for allocating the structure and the automatic + * memory management within the buffer + * (if @c NULL, the cxDefaultAllocator will be used) * @param space pointer to the memory area, or @c NULL to allocate * new memory * @param capacity the capacity of the buffer - * @param allocator the allocator to use for allocating the structure and the automatic - * memory management within the buffer - * (if @c NULL, the cxDefaultAllocator will be used) * @param flags buffer features (see cx_buffer_s.flags) * @return a pointer to the buffer on success, @c NULL if a required allocation failed */ cx_attr_malloc cx_attr_dealloc(cxBufferFree, 1) cx_attr_nodiscard -CX_EXPORT CxBuffer *cxBufferCreate(void *space, size_t capacity, - const CxAllocator *allocator, int flags); +CX_EXPORT CxBuffer *cxBufferCreate(const CxAllocator *allocator, void *space, + size_t capacity, int flags); /** * Shifts the contents of the buffer by the given offset.
--- a/src/json.c Sun Dec 14 14:29:27 2025 +0100 +++ b/src/json.c Sun Dec 14 15:41:02 2025 +0100 @@ -410,7 +410,7 @@ size_t capa = str.length + 32; char *space = cxMallocDefault(capa); if (space == NULL) return cx_mutstrn(NULL, 0); - cxBufferInit(&buf, space, capa, NULL, CX_BUFFER_AUTO_EXTEND); + cxBufferInit(&buf, NULL, space, capa, CX_BUFFER_AUTO_EXTEND); cxBufferWrite(str.ptr, 1, i, &buf); all_printable = false; } @@ -575,8 +575,8 @@ // reinitialize the buffer cxBufferDestroy(&json->buffer); if (buf == NULL) buf = ""; // buffer must not be initialized with NULL - cxBufferInit(&json->buffer, (char*) buf, size, - NULL, CX_BUFFER_AUTO_EXTEND | CX_BUFFER_COPY_ON_WRITE); + cxBufferInit(&json->buffer, NULL, (char*) buf, + size, CX_BUFFER_AUTO_EXTEND | CX_BUFFER_COPY_ON_WRITE); json->buffer.size = size; return 0; } else { @@ -1424,8 +1424,8 @@ static cxmutstr cx_json_to_string(CxJsonValue *value, const CxAllocator *allocator, CxJsonWriter *writer) { if (allocator == NULL) allocator = cxDefaultAllocator; CxBuffer buffer; - if (cxBufferInit(&buffer, NULL, 128, allocator, - CX_BUFFER_AUTO_EXTEND | CX_BUFFER_DO_NOT_FREE)) { + if (cxBufferInit(&buffer, allocator, NULL, 128, + CX_BUFFER_AUTO_EXTEND | CX_BUFFER_DO_NOT_FREE)) { return (cxmutstr){NULL, 0}; } if (cx_json_write_rec(&buffer, value, cxBufferWriteFunc, writer, 0)
--- a/src/properties.c Sun Dec 14 14:29:27 2025 +0100 +++ b/src/properties.c Sun Dec 14 15:41:02 2025 +0100 @@ -68,8 +68,8 @@ if (cxBufferEof(&prop->input)) { // destroy a possible previously initialized buffer cxBufferDestroy(&prop->input); - cxBufferInit(&prop->input, (void*) buf, len, - NULL, CX_BUFFER_COPY_ON_WRITE | CX_BUFFER_AUTO_EXTEND); + cxBufferInit(&prop->input, NULL, (void*) buf, + len, CX_BUFFER_COPY_ON_WRITE | CX_BUFFER_AUTO_EXTEND); prop->input.size = len; } else { if (cxBufferAppend(buf, 1, len, &prop->input) < len) return -1; @@ -82,7 +82,7 @@ char *buf, size_t capacity ) { - cxBufferInit(&prop->buffer, buf, capacity, NULL, CX_BUFFER_COPY_ON_EXTEND); + cxBufferInit(&prop->buffer, NULL, buf, capacity, CX_BUFFER_COPY_ON_EXTEND); } CxPropertiesStatus cxPropertiesNext( @@ -190,7 +190,7 @@ assert(cxBufferEof(&prop->buffer)); if (prop->buffer.space == NULL) { // initialize a rescue buffer, if the user did not provide one - cxBufferInit(&prop->buffer, NULL, 256, NULL, CX_BUFFER_AUTO_EXTEND); + cxBufferInit(&prop->buffer, NULL, NULL, 256, CX_BUFFER_AUTO_EXTEND); } else { // from a previous rescue there might be already read data // reset the buffer to avoid unnecessary buffer extension @@ -251,7 +251,7 @@ if (current_buffer != &prop->buffer) { // move value to the rescue buffer if (prop->buffer.space == NULL) { - cxBufferInit(&prop->buffer, NULL, 256, NULL, CX_BUFFER_AUTO_EXTEND); + cxBufferInit(&prop->buffer, NULL, NULL, 256, CX_BUFFER_AUTO_EXTEND); } prop->buffer.size = 0; prop->buffer.pos = 0;
--- a/tests/test_buffer.c Sun Dec 14 14:29:27 2025 +0100 +++ b/tests/test_buffer.c Sun Dec 14 15:41:02 2025 +0100 @@ -39,7 +39,7 @@ CX_TEST_DO { CxBuffer buf; void *space = cxMalloc(alloc, 16); - cxBufferInit(&buf, space, 16, alloc, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, alloc, space, 16, CX_BUFFER_DEFAULT); CX_TEST_ASSERT(buf.space == space); CX_TEST_ASSERT((buf.flags & CX_BUFFER_AUTO_EXTEND) == 0); CX_TEST_ASSERT((buf.flags & CX_BUFFER_FREE_CONTENTS) == 0); @@ -63,7 +63,7 @@ CX_TEST_DO { CxBuffer buf; void *space = cxMalloc(alloc, 16); - cxBufferInit(&buf, space, 16, alloc, CX_BUFFER_AUTO_EXTEND); + cxBufferInit(&buf, alloc, space, 16, CX_BUFFER_AUTO_EXTEND); CX_TEST_ASSERT(buf.space == space); CX_TEST_ASSERT((buf.flags & CX_BUFFER_AUTO_EXTEND) == CX_BUFFER_AUTO_EXTEND); CX_TEST_ASSERT((buf.flags & CX_BUFFER_FREE_CONTENTS) == 0); @@ -87,7 +87,7 @@ CX_TEST_DO { CxBuffer buf; void *space = cxMalloc(alloc, 16); - cxBufferInit(&buf, space, 16, alloc, CX_BUFFER_FREE_CONTENTS); + cxBufferInit(&buf, alloc, space, 16, CX_BUFFER_FREE_CONTENTS); CX_TEST_ASSERT(buf.space == space); CX_TEST_ASSERT((buf.flags & CX_BUFFER_AUTO_EXTEND) == 0); CX_TEST_ASSERT((buf.flags & CX_BUFFER_FREE_CONTENTS) == CX_BUFFER_FREE_CONTENTS); @@ -109,7 +109,7 @@ CxAllocator *alloc = &talloc.base; CX_TEST_DO { CxBuffer buf; - cxBufferInit(&buf, NULL, 8, alloc, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, alloc, NULL, 8, CX_BUFFER_DEFAULT); CX_TEST_ASSERT(buf.space != NULL); CX_TEST_ASSERT((buf.flags & CX_BUFFER_AUTO_EXTEND) == 0); CX_TEST_ASSERT((buf.flags & CX_BUFFER_FREE_CONTENTS) == CX_BUFFER_FREE_CONTENTS); @@ -132,7 +132,7 @@ CX_TEST_DO { CxBuffer *buf; void *space = cxMalloc(alloc, 16); - buf = cxBufferCreate(space, 16, alloc, CX_BUFFER_FREE_CONTENTS); + buf = cxBufferCreate(alloc, space, 16, CX_BUFFER_FREE_CONTENTS); CX_TEST_ASSERT(buf != NULL); CX_TEST_ASSERT(buf->space == space); CX_TEST_ASSERT((buf->flags & CX_BUFFER_AUTO_EXTEND) == 0); @@ -151,7 +151,7 @@ CX_TEST(test_buffer_create_defaulted_allocator) { CX_TEST_DO { CxBuffer *buf; - buf = cxBufferCreate(NULL, 16, NULL, 0); + buf = cxBufferCreate(NULL, NULL, 16, 0); CX_TEST_ASSERT(buf != NULL); CX_TEST_ASSERT(buf->space != NULL); CX_TEST_ASSERT((buf->flags & CX_BUFFER_AUTO_EXTEND) == 0); @@ -172,7 +172,7 @@ CX_TEST_DO { void *space = cxMalloc(alloc, 8); CxBuffer buf; - cxBufferInit(&buf, space, 8, alloc, CX_BUFFER_FREE_CONTENTS); + cxBufferInit(&buf, alloc, space, 8, CX_BUFFER_FREE_CONTENTS); memcpy(space, "Testing", 8); buf.size = 8; cxBufferMinimumCapacity(&buf, 6); @@ -192,7 +192,7 @@ CX_TEST_DO { void *space = cxMalloc(alloc, 8); CxBuffer buf; - cxBufferInit(&buf, space, 8, alloc, CX_BUFFER_FREE_CONTENTS); // NO auto extend! + cxBufferInit(&buf, alloc, space, 8, CX_BUFFER_FREE_CONTENTS); // NO auto extend! memcpy(space, "Testing", 8); buf.size = 8; cxBufferMinimumCapacity(&buf, 16); @@ -216,7 +216,7 @@ CX_TEST(test_buffer_maximum_capacity) { CxBuffer buf; - cxBufferInit(&buf, NULL, 256, NULL, CX_BUFFER_AUTO_EXTEND); + cxBufferInit(&buf, NULL, NULL, 256, CX_BUFFER_AUTO_EXTEND); CX_TEST_DO { // set maximum capacity CX_TEST_ASSERT(0 == cxBufferMaximumCapacity(&buf, 512)); @@ -258,7 +258,7 @@ CxAllocator *alloc = &talloc.base; CX_TEST_DO { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, alloc, CX_BUFFER_FREE_CONTENTS); + cxBufferInit(&buf, alloc, NULL, 16, CX_BUFFER_FREE_CONTENTS); cxBufferPutString(&buf, "Testing"); CX_TEST_ASSERT(buf.capacity == 16); CX_TEST_ASSERT(buf.size == 7); @@ -279,7 +279,7 @@ CX_TEST_DO { CxBuffer buf; const char* space = "Testing"; - cxBufferInit(&buf, (void*)space, 16, alloc, CX_BUFFER_COPY_ON_WRITE); + cxBufferInit(&buf, alloc, (void*)space, 16, CX_BUFFER_COPY_ON_WRITE); buf.size = 8; CX_TEST_ASSERT(buf.capacity == 16); cxBufferShrink(&buf, 4); @@ -300,7 +300,7 @@ CX_TEST_DO { CxBuffer buf; char space[16] = "Testing"; - cxBufferInit(&buf, space, 16, alloc, CX_BUFFER_COPY_ON_EXTEND); + cxBufferInit(&buf, alloc, space, 16, CX_BUFFER_COPY_ON_EXTEND); buf.size = 8; CX_TEST_ASSERT(buf.capacity == 16); cxBufferShrink(&buf, 4); @@ -321,7 +321,7 @@ CX_TEST_DO { CxBuffer buf; char space[16] = "Testing"; - cxBufferInit(&buf, space, 16, alloc, CX_BUFFER_COPY_ON_EXTEND); + cxBufferInit(&buf, alloc, space, 16, CX_BUFFER_COPY_ON_EXTEND); buf.size = 8; CX_TEST_ASSERT(buf.capacity == 16); CX_TEST_ASSERT(talloc.alloc_total == 0); @@ -353,7 +353,7 @@ char space[16]; strcpy(space, "clear test"); CxBuffer buf; - cxBufferInit(&buf, space, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, space, 16, CX_BUFFER_DEFAULT); CX_TEST_DO { CX_TEST_ASSERT(buf.size == 0); // only clear the used part of the buffer @@ -373,7 +373,7 @@ char space[16]; strcpy(space, "clear test"); CxBuffer buf; - cxBufferInit(&buf, space, 16, cxDefaultAllocator, CX_BUFFER_COPY_ON_WRITE); + cxBufferInit(&buf, cxDefaultAllocator, space, 16, CX_BUFFER_COPY_ON_WRITE); CX_TEST_DO { buf.size = 5; buf.pos = 3; @@ -389,7 +389,7 @@ char space[16]; strcpy(space, "reset test"); CxBuffer buf; - cxBufferInit(&buf, space, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, space, 16, CX_BUFFER_DEFAULT); CX_TEST_DO { buf.size = 5; buf.pos = 3; @@ -403,7 +403,7 @@ CX_TEST(test_buffer_seek_set_zero) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); buf.size = 6; buf.pos = 3; CX_TEST_DO { @@ -416,7 +416,7 @@ CX_TEST(test_buffer_seek_set_valid) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); buf.size = 6; buf.pos = 3; CX_TEST_DO { @@ -429,7 +429,7 @@ CX_TEST(test_buffer_seek_set_invalid) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); buf.size = 6; buf.pos = 3; CX_TEST_DO { @@ -442,7 +442,7 @@ CX_TEST(test_buffer_seek_cur_zero) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); buf.size = 6; buf.pos = 3; CX_TEST_DO { @@ -455,7 +455,7 @@ CX_TEST(test_buffer_seek_cur_valid_positive) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); buf.size = 6; buf.pos = 3; CX_TEST_DO { @@ -468,7 +468,7 @@ CX_TEST(test_buffer_seek_cur_valid_negative) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); buf.size = 6; buf.pos = 3; CX_TEST_DO { @@ -481,7 +481,7 @@ CX_TEST(test_buffer_seek_cur_invalid_positive) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); buf.size = 6; buf.pos = 3; CX_TEST_DO { @@ -494,7 +494,7 @@ CX_TEST(test_buffer_seek_cur_invalid_negative) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); buf.size = 6; buf.pos = 3; CX_TEST_DO { @@ -507,7 +507,7 @@ CX_TEST(test_buffer_seek_end_zero) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); buf.size = 6; buf.pos = 3; CX_TEST_DO { @@ -520,7 +520,7 @@ CX_TEST(test_buffer_seek_end_valid) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); buf.size = 6; buf.pos = 3; CX_TEST_DO { @@ -533,7 +533,7 @@ CX_TEST(test_buffer_seek_end_invalid) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); buf.size = 6; buf.pos = 3; CX_TEST_DO { @@ -546,7 +546,7 @@ CX_TEST(test_buffer_seek_whence_invalid) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); buf.size = 6; buf.pos = 3; CX_TEST_DO { @@ -560,7 +560,7 @@ CX_TEST(test_buffer_eof_reached) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); buf.size = buf.pos = 3; CX_TEST_DO { CX_TEST_ASSERT(cxBufferEof(&buf)); @@ -574,7 +574,7 @@ CX_TEST(test_buffer_eof_not_reached) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); buf.size = 6; CX_TEST_DO { buf.pos = buf.size - 1; @@ -591,7 +591,7 @@ cx_testing_allocator_init(&talloc); \ CxAllocator *alloc = &talloc.base; \ CxBuffer buf; \ - cxBufferInit(&buf, NULL, 16, alloc, CX_BUFFER_DEFAULT); \ + cxBufferInit(&buf, alloc, NULL, 16, CX_BUFFER_DEFAULT); \ memcpy(buf.space, "test____XXXXXXXX", 16); \ buf.capacity = 8; \ buf.pos = 4; \ @@ -803,7 +803,7 @@ CX_TEST(test_buffer_write_size_one_fit) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16); buf.capacity = 8; buf.size = buf.pos = 4; @@ -822,7 +822,7 @@ CX_TEST(test_buffer_write_size_one_discard) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16); buf.capacity = 8; buf.size = buf.pos = 4; @@ -840,7 +840,7 @@ CX_TEST(test_buffer_write_size_one_extend) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16); buf.capacity = 8; buf.size = buf.pos = 4; @@ -860,7 +860,7 @@ CX_TEST(test_buffer_write_copy_on_write) { CxBuffer buf; char original[16] = "preparedXXXXXXX"; - cxBufferInit(&buf, original, 16, cxDefaultAllocator, CX_BUFFER_COPY_ON_WRITE); + cxBufferInit(&buf, cxDefaultAllocator, original, 16, CX_BUFFER_COPY_ON_WRITE); buf.capacity = 8; buf.size = 8; buf.pos = 0; @@ -881,7 +881,7 @@ CX_TEST(test_buffer_write_multibyte_fit) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16); buf.capacity = 8; buf.size = buf.pos = 4; @@ -899,7 +899,7 @@ CX_TEST(test_buffer_write_multibyte_discard) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16); buf.capacity = 8; buf.size = 4; @@ -919,7 +919,7 @@ CX_TEST(test_buffer_write_multibyte_extend) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16); buf.capacity = 8; buf.size = 4; @@ -940,7 +940,7 @@ CX_TEST(test_buffer_append) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_AUTO_EXTEND); memcpy(buf.space, "prepXXXX\0\0\0\0\0\0\0\0", 16); buf.capacity = 8; buf.size = 6; @@ -958,7 +958,7 @@ CX_TEST(test_buffer_append_string) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_AUTO_EXTEND); memcpy(buf.space, "prepXXXX\0\0\0\0\0\0\0\0", 16); buf.capacity = 8; buf.size = 6; @@ -976,7 +976,7 @@ CX_TEST(test_buffer_put_fit) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16); buf.capacity = 8; buf.size = buf.pos = 4; @@ -993,7 +993,7 @@ CX_TEST(test_buffer_put_discard) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16); buf.capacity = 8; buf.size = 4; @@ -1011,7 +1011,7 @@ CX_TEST(test_buffer_put_extend) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16); buf.capacity = 8; buf.size = 4; @@ -1031,7 +1031,7 @@ CX_TEST(test_buffer_put_copy_on_write) { CxBuffer buf; char original[16] = "preparedXXXXXXX"; - cxBufferInit(&buf, original, 16, cxDefaultAllocator, CX_BUFFER_COPY_ON_WRITE); + cxBufferInit(&buf, cxDefaultAllocator, original, 16, CX_BUFFER_COPY_ON_WRITE); buf.capacity = 8; buf.size = 8; buf.pos = 8; @@ -1064,7 +1064,7 @@ CX_TEST(test_buffer_put_string_fit) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16); buf.capacity = 8; buf.size = buf.pos = 4; @@ -1082,7 +1082,7 @@ CX_TEST(test_buffer_put_string_discard) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16); buf.capacity = 8; buf.size = buf.pos = 4; @@ -1100,7 +1100,7 @@ CX_TEST(test_buffer_put_string_extend) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16); buf.capacity = 8; buf.size = buf.pos = 4; @@ -1124,7 +1124,7 @@ CxBuffer buf; char original[16] = "preparedXXXXXXX"; CX_TEST_DO { - cxBufferInit(&buf, original, 16, alloc, CX_BUFFER_COPY_ON_EXTEND); + cxBufferInit(&buf, alloc, original, 16, CX_BUFFER_COPY_ON_EXTEND); buf.capacity = 8; buf.size = buf.pos = 4; size_t written = cxBufferPutString(&buf, "test"); @@ -1152,7 +1152,7 @@ CX_TEST(test_buffer_put_string_copy_on_write) { CxBuffer buf; char original[16] = "preparedXXXXXXX"; - cxBufferInit(&buf, original, 16, cxDefaultAllocator, CX_BUFFER_COPY_ON_WRITE); + cxBufferInit(&buf, cxDefaultAllocator, original, 16, CX_BUFFER_COPY_ON_WRITE); buf.capacity = 8; buf.size = 8; buf.pos = 4; @@ -1175,7 +1175,7 @@ CX_TEST(test_buffer_terminate) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); memcpy(buf.space, "prepAAAAAA\0\0\0\0\0\0", 16); buf.capacity = 8; buf.size = buf.pos = 4; @@ -1203,8 +1203,8 @@ cx_testing_allocator_init(&talloc); CxAllocator *alloc = &talloc.base; CxBuffer buf; - cxBufferInit(&buf, "prepAAAAAA\0\0\0\0\0\0", 16, alloc, - CX_BUFFER_COPY_ON_WRITE | CX_BUFFER_DO_NOT_FREE); + cxBufferInit(&buf, alloc, "prepAAAAAA\0\0\0\0\0\0", 16, + CX_BUFFER_COPY_ON_WRITE | CX_BUFFER_DO_NOT_FREE); buf.capacity = 8; buf.size = buf.pos = 4; CX_TEST_DO { @@ -1225,7 +1225,7 @@ CX_TEST(test_buffer_write_size_overflow) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16); buf.capacity = 8; buf.size = buf.pos = 4; @@ -1243,7 +1243,7 @@ CX_TEST(test_buffer_write_capacity_overflow) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); memcpy(buf.space, "prep\0\0\0\0\0\0\0\0\0\0\0\0", 16); buf.capacity = 8; buf.size = buf.pos = 4; @@ -1262,7 +1262,7 @@ CX_TEST(test_buffer_write_maximum_capacity_exceeded) { CxBuffer buf; - cxBufferInit(&buf, NULL, 8, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 8, CX_BUFFER_AUTO_EXTEND); CX_TEST_DO { cxBufferMaximumCapacity(&buf, 30); size_t written = cxBufferPutString(&buf, "Hello, World!\nHello, Tester!"); @@ -1292,7 +1292,7 @@ CX_TEST(test_buffer_write_only_overwrite) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); memcpy(buf.space, "preptest\0\0\0\0\0\0\0\0", 16); buf.capacity = 8; buf.pos = 3; @@ -1311,7 +1311,7 @@ CX_TEST(test_buffer_pop) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); cxBufferPutString(&buf, "teststring"); CX_TEST_DO { CX_TEST_ASSERT(buf.pos == 10); @@ -1347,7 +1347,7 @@ CX_TEST(test_buffer_get) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); memcpy(buf.space, "some data\0\0\0\0\0\0\0", 16); buf.capacity = 12; buf.size = 9; @@ -1364,7 +1364,7 @@ CX_TEST(test_buffer_get_eof) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); memcpy(buf.space, "some data\0\0\0\0\0\0\0", 16); buf.capacity = 12; buf.pos = buf.size = 9; @@ -1376,7 +1376,7 @@ CX_TEST(test_buffer_read) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); memcpy(buf.space, "some data\0\0\0\0\0\0\0", 16); buf.capacity = 12; buf.size = 9; @@ -1399,7 +1399,7 @@ CX_TEST(test_buffer_read_oob) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); memcpy(buf.space, "some data\0\0\0\0\0\0\0", 16); buf.capacity = 12; buf.size = 9; @@ -1416,7 +1416,7 @@ CX_TEST(test_buffer_read_oob_multibyte) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); memcpy(buf.space, "some data\0\0\0\0\0\0\0", 16); buf.capacity = 12; buf.size = 9; @@ -1434,7 +1434,7 @@ CX_TEST(test_buffer_read_eof) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, cxDefaultAllocator, NULL, 16, CX_BUFFER_DEFAULT); memcpy(buf.space, "some data\0\0\0\0\0\0\0", 16); buf.capacity = 12; buf.size = buf.pos = 9;
--- a/tests/test_json.c Sun Dec 14 14:29:27 2025 +0100 +++ b/tests/test_json.c Sun Dec 14 15:41:02 2025 +0100 @@ -1772,7 +1772,7 @@ // write it to a buffer CxBuffer buf; - cxBufferInit(&buf, NULL, 512, NULL, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, NULL, NULL, 512, CX_BUFFER_DEFAULT); int result = cxJsonWrite(&buf, obj, cxBufferWriteFunc, writer); cxBufferTerminate(&buf); // makes debugging easier CX_TEST_ASSERT(result == 0); @@ -1913,7 +1913,7 @@ CxJsonWriter writer = cxJsonWriterPretty(true); writer.indent = 8; CxBuffer buf; - cxBufferInit(&buf, NULL, 512, NULL, CX_BUFFER_DEFAULT); + cxBufferInit(&buf, NULL, NULL, 512, CX_BUFFER_DEFAULT); int result = cxJsonWrite(&buf, obj, cxBufferWriteFunc, &writer); cxBufferTerminate(&buf); // makes debugging easier CX_TEST_ASSERT(result == 0); @@ -1934,7 +1934,7 @@ CxJsonValue* num = cxJsonCreateNumber(NULL, 3.141592653589793); CxJsonWriter writer = cxJsonWriterCompact(); CxBuffer buf; - cxBufferInit(&buf, NULL, 32, NULL, 0); + cxBufferInit(&buf, NULL, NULL, 32, 0); CX_TEST_DO { // test default settings (6 digits) CX_TEST_ASSERT(0 == cxJsonWrite(&buf, num, cxBufferWriteFunc, &writer)); @@ -2000,7 +2000,7 @@ "hello\twörld\r\nthis is\\a \"string\"\b in \a string\f"); CxJsonWriter writer = cxJsonWriterCompact(); CxBuffer buf; - cxBufferInit(&buf, NULL, 128, NULL, 0); + cxBufferInit(&buf, NULL, NULL, 128, 0); CX_TEST_DO { CX_TEST_ASSERT(0 == cxJsonWrite(&buf, str, cxBufferWriteFunc, &writer)); CX_TEST_ASSERT(0 == cx_strcmp(cx_strn(buf.space, buf.size), @@ -2016,7 +2016,7 @@ "hello\twörld\r\nthis is\\a \"string\"\b in \a string\f", CX_JSON_TRUE); CxJsonWriter writer = cxJsonWriterCompact(); CxBuffer buf; - cxBufferInit(&buf, NULL, 128, NULL, 0); + cxBufferInit(&buf, NULL, NULL, 128, 0); CX_TEST_DO { CX_TEST_ASSERT(0 == cxJsonWrite(&buf, obj, cxBufferWriteFunc, &writer)); CX_TEST_ASSERT(0 == cx_strcmp(cx_strn(buf.space, buf.size), @@ -2030,7 +2030,7 @@ CxJsonValue* str = cxJsonCreateString(NULL,"test/solidus"); CxJsonWriter writer = cxJsonWriterCompact(); CxBuffer buf; - cxBufferInit(&buf, NULL, 16, NULL, 0); + cxBufferInit(&buf, NULL, NULL, 16, 0); CX_TEST_DO { // default: do not escape CX_TEST_ASSERT(0 == cxJsonWrite(&buf, str, cxBufferWriteFunc, &writer)); @@ -2048,7 +2048,7 @@ CX_TEST(test_json_write_nothing) { CxBuffer buf; - cxBufferInit(&buf, NULL, 16, NULL, 0); + cxBufferInit(&buf, NULL, NULL, 16, 0); CX_TEST_DO { CxJsonValue nothing; nothing.type = CX_JSON_NOTHING;
--- a/tests/test_printf.c Sun Dec 14 14:29:27 2025 +0100 +++ b/tests/test_printf.c Sun Dec 14 15:41:02 2025 +0100 @@ -51,7 +51,7 @@ CxAllocator *alloc = &talloc.base; CX_TEST_DO { CxBuffer buf; - cxBufferInit(&buf, NULL, 64, alloc, 0); + cxBufferInit(&buf, alloc, NULL, 64, 0); size_t r = cx_bprintf(&buf, "This %s aged %u years in a %2XSK.", "Test", 10, 0xca); CX_TEST_ASSERT(r == 34); CX_TEST_ASSERT(buf.size == 34); @@ -78,7 +78,7 @@ sprintf(expected, "After %s comes %s.", aaa, bbb); CX_TEST_DO { CxBuffer buf; - cxBufferInit(&buf, NULL, 64, alloc, CX_BUFFER_AUTO_EXTEND); + cxBufferInit(&buf, alloc, NULL, 64, CX_BUFFER_AUTO_EXTEND); size_t r = cx_bprintf(&buf, "After %s comes %s.", aaa, bbb); size_t er = 2*len-2+14; CX_TEST_ASSERT(r == er); @@ -102,7 +102,7 @@ memset(space, 'a', 20); CX_TEST_DO { CxBuffer buf; - cxBufferInit(&buf, space, 16, alloc, 0); + cxBufferInit(&buf, alloc, space, 16, 0); size_t r = cx_bprintf(&buf, "Hello %s with more than %d chars.", "string", 16); CX_TEST_ASSERT(r == 16); CX_TEST_ASSERT(buf.size == 16);
--- a/tests/test_streams.c Sun Dec 14 14:29:27 2025 +0100 +++ b/tests/test_streams.c Sun Dec 14 15:41:02 2025 +0100 @@ -35,8 +35,8 @@ CxBuffer source, target; char sbuf[32], tbuf[32]; memset(tbuf, 0, 32); - cxBufferInit(&source, sbuf, 32, NULL, 0); - cxBufferInit(&target, tbuf, 32, NULL, 0); + cxBufferInit(&source, NULL, sbuf, 32, 0); + cxBufferInit(&target, NULL, tbuf, 32, 0); cxBufferPutString(&source, "This is a stream copy test."); cxBufferSeek(&source, 0, SEEK_SET); char tmp[4]; @@ -75,8 +75,8 @@ CxBuffer source, target; char sbuf[32], tbuf[32]; memset(tbuf, 0, 32); - cxBufferInit(&source, sbuf, 32, NULL, 0); - cxBufferInit(&target, tbuf, 32, NULL, 0); + cxBufferInit(&source, NULL, sbuf, 32, 0); + cxBufferInit(&target, NULL, tbuf, 32, 0); cxBufferPutString(&source, "This is a stream copy test."); cxBufferSeek(&source, 0, SEEK_SET);