]> granicus.if.org Git - neomutt/commitdiff
Move buffer_new / buffer_free to static functions in pool.c
authorPietro Cerutti <gahr@gahr.ch>
Tue, 27 Aug 2019 11:32:30 +0000 (11:32 +0000)
committerRichard Russon <rich@flatcap.org>
Sat, 31 Aug 2019 00:51:08 +0000 (01:51 +0100)
mutt/buffer.c
mutt/buffer.h
mutt/pool.c
test/Makefile.autosetup
test/buffer/mutt_buffer_free.c [deleted file]
test/buffer/mutt_buffer_new.c [deleted file]
test/main.c

index 43c5ae131bb325b49ef20a35331b696e5d11d8b2..0cb146b6a9e8225c9370d8ca1f9e92fe7dfbfd85 100644 (file)
 #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
@@ -107,20 +92,6 @@ size_t mutt_buffer_addstr_n(struct Buffer *buf, const char *s, size_t len)
   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
index f8bbeacb3de66f3d47bab43b28d05b18f5e59018..ac2dce56c44f9aed8cde2bfa4eb0f2eaf949c09e 100644 (file)
@@ -45,11 +45,9 @@ struct 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
index 810d11bdf0df983da6c292203495fce46e29b07c..3ca1145fcaad55c763edaf8b436d966386cda470 100644 (file)
@@ -38,6 +38,31 @@ static size_t BufferPoolIncrement = 20;
 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
  */
@@ -49,7 +74,7 @@ static void increase_buffer_pool(void)
   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;
   }
@@ -63,7 +88,7 @@ void mutt_buffer_pool_free(void)
   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;
 }
@@ -91,7 +116,7 @@ void mutt_buffer_pool_release(struct Buffer **pbuf)
   if (BufferPoolCount >= BufferPoolLen)
   {
     mutt_debug(LL_DEBUG1, "Internal buffer pool error\n");
-    mutt_buffer_free(pbuf);
+    buffer_free(pbuf);
     return;
   }
 
index cdd1c959771efc390391955f1ced62b813a82bbd..b42af1d8aa02aa2c5072eebc38d1261fd790920f 100644 (file)
@@ -45,11 +45,9 @@ BUFFER_OBJS  = test/buffer/mutt_buffer_addch.o \
                  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 \
diff --git a/test/buffer/mutt_buffer_free.c b/test/buffer/mutt_buffer_free.c
deleted file mode 100644 (file)
index 8277a0a..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * @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);
-  }
-}
diff --git a/test/buffer/mutt_buffer_new.c b/test/buffer/mutt_buffer_new.c
deleted file mode 100644 (file)
index 941389c..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * @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);
-  }
-}
index c870f9fbca2d54f741b219168123114638143abf..eebf2ec89a263937949169f2623d870dee07ec41 100644 (file)
   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)                             \