adds new CX_BUFFER_DO_NOT_FREE buffer flag

Thu, 11 Dec 2025 22:43:13 +0100

author
Mike Becker <universe@uap-core.de>
date
Thu, 11 Dec 2025 22:43:13 +0100
changeset 1572
0499bf03aef3
parent 1571
25ead2ffb9b5
child 1573
cd2e974410ad

adds new CX_BUFFER_DO_NOT_FREE buffer flag

CHANGELOG file | annotate | diff | comparison | revisions
docs/Writerside/topics/about.md file | annotate | diff | comparison | revisions
src/buffer.c file | annotate | diff | comparison | revisions
src/cx/buffer.h file | annotate | diff | comparison | revisions
--- 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
--- 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
--- 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));
--- 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
  */

mercurial