#include "memory.h"
#include "string2.h"
-/**
- * mutt_buffer_new - Create and initialise a Buffer
- * @retval ptr New Buffer
- *
- * Call mutt_buffer_free() to release the Buffer.
- */
-struct Buffer *mutt_buffer_new(void)
-{
- struct Buffer *b = mutt_mem_malloc(sizeof(struct Buffer));
-
- mutt_buffer_init(b);
-
- return b;
-}
-
/**
* mutt_buffer_init - Initialise a new Buffer
* @param buf Buffer to initialise
return len;
}
-/**
- * mutt_buffer_free - Release a Buffer and its contents
- * @param[out] p Buffer pointer to free and NULL
- */
-void mutt_buffer_free(struct Buffer **p)
-{
- if (!p || !*p)
- return;
-
- FREE(&(*p)->data);
- /* dptr is just an offset to data and shouldn't be freed */
- FREE(p);
-}
-
/**
* buffer_printf - Format a string into a Buffer
* @param buf Buffer
void mutt_buffer_alloc (struct Buffer *buf, size_t size);
void mutt_buffer_dealloc (struct Buffer *buf);
void mutt_buffer_fix_dptr (struct Buffer *buf);
-void mutt_buffer_free (struct Buffer **p);
struct Buffer *mutt_buffer_init (struct Buffer *buf);
bool mutt_buffer_is_empty (const struct Buffer *buf);
size_t mutt_buffer_len (const struct Buffer *buf);
-struct Buffer *mutt_buffer_new (void);
void mutt_buffer_reset (struct Buffer *buf);
// Functions that APPEND to a Buffer
static size_t BufferPoolInitialBufferSize = 1024;
static struct Buffer **BufferPool = NULL;
+/**
+ * buffer_new - Allocate a new Buffer on the heap
+ * @retval buf A newly allocated Buffer
+ * @note call buffer_free to release the memory
+ */
+static struct Buffer *buffer_new(void)
+{
+ struct Buffer *b = mutt_mem_malloc(sizeof(struct Buffer));
+ mutt_buffer_init(b);
+ return b;
+}
+
+/**
+ * buffer_free - Release a Buffer and its contents
+ * @param[out] p Buffer pointer to free and NULL
+ */
+static void buffer_free(struct Buffer **p)
+{
+ if (!p || !*p)
+ return;
+
+ mutt_buffer_dealloc(*p);
+ FREE(p);
+}
+
/**
* increase_buffer_pool - Increase the size of the Buffer pool
*/
mutt_mem_realloc(&BufferPool, BufferPoolLen * sizeof(struct Buffer *));
while (BufferPoolCount < BufferPoolIncrement)
{
- struct Buffer *newbuf = mutt_buffer_new();
+ struct Buffer *newbuf = buffer_new();
mutt_buffer_alloc(newbuf, BufferPoolInitialBufferSize);
BufferPool[BufferPoolCount++] = newbuf;
}
mutt_debug(LL_DEBUG1, "%zu of %zu returned to pool\n", BufferPoolCount, BufferPoolLen);
while (BufferPoolCount)
- mutt_buffer_free(&BufferPool[--BufferPoolCount]);
+ buffer_free(&BufferPool[--BufferPoolCount]);
FREE(&BufferPool);
BufferPoolLen = 0;
}
if (BufferPoolCount >= BufferPoolLen)
{
mutt_debug(LL_DEBUG1, "Internal buffer pool error\n");
- mutt_buffer_free(pbuf);
+ buffer_free(pbuf);
return;
}
test/buffer/mutt_buffer_alloc.o \
test/buffer/mutt_buffer_concat_path.o \
test/buffer/mutt_buffer_fix_dptr.o \
- test/buffer/mutt_buffer_free.o \
test/buffer/mutt_buffer_init.o \
test/buffer/mutt_buffer_is_empty.o \
test/buffer/mutt_buffer_len.o \
- test/buffer/mutt_buffer_new.o \
test/buffer/mutt_buffer_pool_free.o \
test/buffer/mutt_buffer_pool_get.o \
test/buffer/mutt_buffer_pool_release.o \
+++ /dev/null
-/**
- * @file
- * Test code for mutt_buffer_free()
- *
- * @authors
- * Copyright (C) 2019 Richard Russon <rich@flatcap.org>
- *
- * @copyright
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 2 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#define TEST_NO_MAIN
-#include "acutest.h"
-#include "config.h"
-#include "mutt/mutt.h"
-
-void test_mutt_buffer_free(void)
-{
- // void mutt_buffer_free(struct Buffer **p);
-
- {
- mutt_buffer_free(NULL);
- TEST_CHECK_(1, "mutt_buffer_free(NULL)");
- }
-
- {
- struct Buffer *buf = NULL;
- mutt_buffer_free(&buf);
- TEST_CHECK_(1, "mutt_buffer_free(&buf)");
- TEST_CHECK(buf == NULL);
- }
-
- {
- struct Buffer *buf = mutt_buffer_new();
- mutt_buffer_free(&buf);
- TEST_CHECK_(1, "mutt_buffer_free(&buf)");
- TEST_CHECK(buf == NULL);
- }
-}
+++ /dev/null
-/**
- * @file
- * Test code for mutt_buffer_new()
- *
- * @authors
- * Copyright (C) 2019 Richard Russon <rich@flatcap.org>
- *
- * @copyright
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 2 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#define TEST_NO_MAIN
-#include "acutest.h"
-#include "config.h"
-#include "mutt/mutt.h"
-
-void test_mutt_buffer_new(void)
-{
- // struct Buffer *mutt_buffer_new(void);
-
- {
- struct Buffer *buf = NULL;
- TEST_CHECK((buf = mutt_buffer_new()) != NULL);
-
- mutt_buffer_free(&buf);
- }
-}
NEOMUTT_TEST_ITEM(test_mutt_buffer_alloc) \
NEOMUTT_TEST_ITEM(test_mutt_buffer_concat_path) \
NEOMUTT_TEST_ITEM(test_mutt_buffer_fix_dptr) \
- NEOMUTT_TEST_ITEM(test_mutt_buffer_free) \
NEOMUTT_TEST_ITEM(test_mutt_buffer_init) \
NEOMUTT_TEST_ITEM(test_mutt_buffer_is_empty) \
NEOMUTT_TEST_ITEM(test_mutt_buffer_len) \
- NEOMUTT_TEST_ITEM(test_mutt_buffer_new) \
NEOMUTT_TEST_ITEM(test_mutt_buffer_pool_free) \
NEOMUTT_TEST_ITEM(test_mutt_buffer_pool_get) \
NEOMUTT_TEST_ITEM(test_mutt_buffer_pool_release) \