diff src/dmgrowbuf.h @ 1697:1036b0dcccb5

Refactor DMGrowBuf so that there can be buffers that grow "backwards". This also removes some support functions like the buffer state push/pop.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 05 Jun 2018 12:55:17 +0300
parents e568535e1a96
children f71cd6691e05
line wrap: on
line diff
--- a/src/dmgrowbuf.h	Tue Jun 05 11:36:55 2018 +0300
+++ b/src/dmgrowbuf.h	Tue Jun 05 12:55:17 2018 +0300
@@ -16,12 +16,21 @@
 
 typedef struct
 {
-    Uint8 *data, *adata;
-    size_t len, size, mingrow, offs;
-    BOOL allocated;
+    Uint8
+        *data;      // Actually allocated data pointer
 
-    int nstack;
-    struct { size_t offs, len; } stack[32];
+    size_t
+        offs,       // Current offset
+        min_offs,
+        max_offs,
+        size,       // Actual allocated size
+        len,        // Size requested
+        mingrow;    // Minimum amount of bytes the allocation size grows by
+
+    BOOL
+        allocated,  // TRUE if this structure itself has been allocated and can be freed, FALSE if static
+        backwards,  // TRUE if the buffer grows backwards (e.g. "offs" moves backwards)
+        literal;    // TRUE if dmGrowBufPut*() functions stores data "literally" in backwards mode
 } DMGrowBuf;
 
 
@@ -30,15 +39,11 @@
 int    dmGrowBufNew(DMGrowBuf **pbuf, const size_t initial, const size_t mingrow);
 void   dmGrowBufFree(DMGrowBuf *buf);
 
-void   dmGrowBufPush(DMGrowBuf *buf);
-void   dmGrowBufPop(DMGrowBuf *buf);
-
 BOOL   dmGrowBufGrow(DMGrowBuf *buf, const size_t amount);
 BOOL   dmGrowBufCheckGrow(DMGrowBuf *buf, const size_t nsize);
 
+BOOL   dmGrowBufPut(DMGrowBuf *buf, const Uint8 *data, const size_t len);
 BOOL   dmGrowBufPutU8(DMGrowBuf *buf, const Uint8 value);
-BOOL   dmGrowBufPut(DMGrowBuf *buf, const void *str, const size_t len);
-
 BOOL   dmGrowBufPutU16BE(DMGrowBuf *buf, const Uint16 val);
 BOOL   dmGrowBufPutU16LE(DMGrowBuf *buf, const Uint16 val);
 BOOL   dmGrowBufPutU32BE(DMGrowBuf *buf, const Uint32 val);