# HG changeset patch # User Mike Becker # Date 1765489393 -3600 # Node ID 0499bf03aef367313acfb8763c39830708fde28a # Parent 25ead2ffb9b5b33da4564d3abe4c73b65403e0cd adds new CX_BUFFER_DO_NOT_FREE buffer flag diff -r 25ead2ffb9b5 -r 0499bf03aef3 CHANGELOG --- a/CHANGELOG Thu Dec 11 17:08:17 2025 +0100 +++ b/CHANGELOG Thu Dec 11 22:43:13 2025 +0100 @@ -5,6 +5,7 @@ * adds cxJsonFromString() * adds line continuation support to CxProperties / CxPropertiesConfig * adds cxBufferMaximumCapacity() + * adds CX_BUFFER_DO_NOT_FREE buffer flag * changes cxFreeDefault() from a macro to a function so that it can be used as a simple destructor * changes cxBufferReserve() to allow reducing the capacity * changes the members of CxJson and CxJsonValue diff -r 25ead2ffb9b5 -r 0499bf03aef3 docs/Writerside/topics/about.md --- a/docs/Writerside/topics/about.md Thu Dec 11 17:08:17 2025 +0100 +++ b/docs/Writerside/topics/about.md Thu Dec 11 22:43:13 2025 +0100 @@ -32,6 +32,7 @@ * adds cxJsonFromString() * adds line continuation support to CxProperties / CxPropertiesConfig * adds cxBufferMaximumCapacity() +* adds CX_BUFFER_DO_NOT_FREE buffer flag * changes cxFreeDefault() from a macro to a function so that it can be used as a simple destructor * changes cxBufferReserve() to allow reducing the capacity * changes the members of CxJson and CxJsonValue diff -r 25ead2ffb9b5 -r 0499bf03aef3 src/buffer.c --- a/src/buffer.c Thu Dec 11 17:08:17 2025 +0100 +++ b/src/buffer.c Thu Dec 11 22:43:13 2025 +0100 @@ -74,7 +74,8 @@ } void cxBufferDestroy(CxBuffer *buffer) { - if (buffer->flags & CX_BUFFER_FREE_CONTENTS) { + if ((buffer->flags & (CX_BUFFER_FREE_CONTENTS | CX_BUFFER_DO_NOT_FREE)) + == CX_BUFFER_FREE_CONTENTS) { cxFree(buffer->allocator, buffer->bytes); } memset(buffer, 0, sizeof(CxBuffer)); diff -r 25ead2ffb9b5 -r 0499bf03aef3 src/cx/buffer.h --- a/src/cx/buffer.h Thu Dec 11 17:08:17 2025 +0100 +++ b/src/cx/buffer.h Thu Dec 11 22:43:13 2025 +0100 @@ -89,6 +89,13 @@ #define CX_BUFFER_COPY_ON_EXTEND 0x08 /** + * If this flag is enabled, the buffer will never free its contents regardless of #CX_BUFFER_FREE_CONTENTS. + * + * This is useful, for example, when you want to keep a pointer to the data after destroying the buffer. + */ +#define CX_BUFFER_DO_NOT_FREE 0x10 + +/** * Function pointer for cxBufferWrite that is compatible with cx_write_func. * @see cx_write_func */