From ed35d6590e72c23c568af1e3b8ac6e4e2d883888 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sat, 2 May 2020 17:04:08 +0200 Subject: dynbuf: introduce internal generic dynamic buffer functions A common set of functions instead of many separate implementations for creating buffers that can grow when appending data to them. Existing functionality has been ported over. In my early basic testing, the total number of allocations seem at roughly the same amount as before, possibly a few less. See docs/DYNBUF.md for a description of the API. Closes #5300 --- tests/data/test558 | 1 - tests/libtest/Makefile.inc | 2 +- tests/server/Makefile.inc | 8 ++++++-- tests/unit/unit1650.c | 5 +++-- 4 files changed, 10 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/data/test558 b/tests/data/test558 index dccb8080a..946979677 100644 --- a/tests/data/test558 +++ b/tests/data/test558 @@ -38,7 +38,6 @@ nothing MEM lib558.c: malloc() MEM lib558.c: free() -MEM escape.c: malloc() MEM strdup.c: realloc() MEM strdup.c: realloc() MEM escape.c: free() diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc index 1651308b1..5d1c773e5 100644 --- a/tests/libtest/Makefile.inc +++ b/tests/libtest/Makefile.inc @@ -59,7 +59,7 @@ noinst_PROGRAMS = chkhostname libauthretry libntlmconnect \ lib2033 chkdecimalpoint_SOURCES = chkdecimalpoint.c ../../lib/mprintf.c \ - ../../lib/curl_ctype.c + ../../lib/curl_ctype.c ../../lib/dynbuf.c ../../lib/strdup.c chkdecimalpoint_LDADD = chkdecimalpoint_CPPFLAGS = $(AM_CPPFLAGS) -DCURL_STATICLIB \ -DCURLX_NO_MEMORY_CALLBACKS diff --git a/tests/server/Makefile.inc b/tests/server/Makefile.inc index fb13d79cb..5dfe8076b 100644 --- a/tests/server/Makefile.inc +++ b/tests/server/Makefile.inc @@ -28,14 +28,18 @@ CURLX_SRCS = \ ../../lib/nonblock.c \ ../../lib/strtoofft.c \ ../../lib/warnless.c \ - ../../lib/curl_ctype.c + ../../lib/curl_ctype.c \ + ../../lib/dynbuf.c \ + ../../lib/strdup.c CURLX_HDRS = \ ../../lib/curlx.h \ ../../lib/nonblock.h \ ../../lib/strtoofft.h \ ../../lib/warnless.h \ - ../../lib/curl_ctype.h + ../../lib/curl_ctype.h \ + ../../lib/dynbuf.h \ + ../../lib/strdup.h USEFUL = \ getpart.c \ diff --git a/tests/unit/unit1650.c b/tests/unit/unit1650.c index e656c073a..b2fc89efa 100644 --- a/tests/unit/unit1650.c +++ b/tests/unit/unit1650.c @@ -22,6 +22,7 @@ #include "curlcheck.h" #include "doh.h" +#include "dynbuf.h" static CURLcode unit_setup(void) { @@ -184,7 +185,7 @@ UNITTEST_START char *ptr; size_t len; int u; - memset(&d, 0, sizeof(d)); + de_init(&d); rc = doh_decode((const unsigned char *)resp[i].packet, resp[i].size, resp[i].type, &d); if(rc != resp[i].rc) { @@ -222,7 +223,7 @@ UNITTEST_START } for(u = 0; u < d.numcname; u++) { size_t o; - msnprintf(ptr, len, "%s ", d.cname[u].alloc); + msnprintf(ptr, len, "%s ", Curl_dyn_ptr(&d.cname[u])); o = strlen(ptr); len -= o; ptr += o; -- cgit v1.2.3