]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Simplify isc_mem_create() to always use defaults and never fail
authorOndřej Surý <ondrej@sury.org>
Thu, 5 Sep 2019 16:40:57 +0000 (18:40 +0200)
committerOndřej Surý <ondrej@sury.org>
Thu, 12 Sep 2019 07:26:09 +0000 (09:26 +0200)
Previously, the isc_mem_create() and isc_mem_createx() functions took `max_size`
and `target_size` as first two arguments.  Those values were never used in the
BIND 9 code.  The refactoring removes those arguments and let BIND 9 always use
the default values.

Previously, the isc_mem_create() and isc_mem_createx() functions could have
failed because of failed memory allocation.  As this was no longer true and the
functions have always returned ISC_R_SUCCESS, the have been refactored to return
void.

conftools/perllib/dnsconf/DNSConf.i
doc/design/logging
doc/dev/dev.md
lib/isc/include/isc/mem.h
lib/isc/mem.c

index 3238acb8504de18118d452aa96a89072fe95f671..6e1161a7465b0dbc7ad7dc581ec9c274126a8ef7 100644 (file)
@@ -60,8 +60,7 @@ int ctx_init(void) {
                goto done;
        }
 
-       if (isc_mem_create(0, 0, &ctx.mem) != ISC_R_SUCCESS)
-               goto done;
+       isc_mem_create(&ctx.mem);
 
        if (isc_log_create(ctx.mem, &ctx.log, &ctx.logcfg) != ISC_R_SUCCESS)
                goto done;
@@ -337,6 +336,3 @@ struct DNSConf {
        %readonly
        dns_c_ctx_t *confctx;
 };
-
-
-
index 84767954c611148eebab230f09a64e4cc0a2794b..ef9699202833ddf9eaf8626001c9bf1b2de63658 100644 (file)
@@ -282,8 +282,8 @@ rudimentary initialization of both.
   isc_log_t *lctx;
   isc_logconfig_t *lcfg;
 
-  if (isc_mem_create(0, 0, &mctx) != ISC_R_SUCCESS) ||
-      isc_log_create(mctx, &lctx, &lcfg) != ISC_R_SUCCESS))
+  isc_mem_create(&mctx);
+  if (isc_log_create(mctx, &lctx, &lcfg) != ISC_R_SUCCESS))
           oops_it_didnt_work();
 
 3) Initalize any additional libraries.  The convention for the name of
index de3177fe186f1163253d572e9954896377b959e0..d769d6f18b6596c3eeba2d3d03ce399df69a4e85 100644 (file)
@@ -504,7 +504,7 @@ memory has not been freed when BIND shuts down.
 To create a basic memory context, use:
 
         isc_mem_t *mctx = NULL;
-        result = isc_mem_create(0, 0, &mctx);
+        isc_mem_create(&mctx);
 
 (The zeroes are tuning parameters, `max_size` and `target_size`: Any
 allocations smaller than `max_size` will be satisfied by getting
@@ -1069,9 +1069,10 @@ the following steps need to be taken to initialize it.
         isc_log_t *lctx;
         isc_logconfig_t *lcfg;
 
-        if (isc_mem_create(0, 0, &mctx) != ISC_R_SUCCESS) ||
-            isc_log_create(mctx, &lctx, &lcfg) != ISC_R_SUCCESS))
+        isc_mem_create(&mctx);
+        if (isc_log_create(mctx, &lctx, &lcfg) != ISC_R_SUCCESS)) {
                 oops_it_didnt_work();
+        }
 
 1. Initalize any additional libraries.  The convention for the name of
    the initialization function is `{library}_log_init()`, with a pointer to
index 75ba5a650547b81fa2f1b190e9b3086e65c7bacb..804e00ad02a520a4092c51e9847b21d2aad50ae7 100644 (file)
@@ -252,30 +252,16 @@ struct isc_mempool {
        } while (0)
 
 /*@{*/
-isc_result_t
-isc_mem_create(size_t max_size, size_t target_size,
-              isc_mem_t **mctxp);
+void
+isc_mem_create(isc_mem_t **mctxp);
 
-isc_result_t
-isc_mem_createx(size_t max_size, size_t target_size,
-               isc_memalloc_t memalloc, isc_memfree_t memfree,
+void
+isc_mem_createx(isc_memalloc_t memalloc, isc_memfree_t memfree,
                void *arg, isc_mem_t **mctxp, unsigned int flags);
 
 /*!<
  * \brief Create a memory context.
  *
- * 'max_size' and 'target_size' are tuning parameters.  When
- * ISC_MEMFLAG_INTERNAL is set, allocations smaller than 'max_size'
- * will be satisfied by getting blocks of size 'target_size' from the
- * system allocator and breaking them up into pieces; larger allocations
- * will use the system allocator directly. If 'max_size' and/or
- * 'target_size' are zero, default values will be * used.  When
- * ISC_MEMFLAG_INTERNAL is not set, 'target_size' is ignored.
- *
- * 'max_size' is also used to size the statistics arrays and the array
- * used to record active memory when ISC_MEM_DEBUGRECORD is set.  Setting
- * 'max_size' too low can have detrimental effects on performance.
- *
  * A memory context created using isc_mem_createx() will obtain
  * memory from the system by calling 'memalloc' and 'memfree',
  * passing them the argument 'arg'.  A memory context created
index fcfce2350382a50c1e01d6ef0911261f61926afe..494578f07593301d91a80dfad73e927eb9530868 100644 (file)
@@ -725,9 +725,8 @@ initialize_action(void) {
  * Public.
  */
 
-isc_result_t
-isc_mem_createx(size_t init_max_size, size_t target_size,
-               isc_memalloc_t memalloc, isc_memfree_t memfree, void *arg,
+void
+isc_mem_createx(isc_memalloc_t memalloc, isc_memfree_t memfree, void *arg,
                isc_mem_t **ctxp, unsigned int flags)
 {
        isc__mem_t *ctx;
@@ -748,10 +747,7 @@ isc_mem_createx(size_t init_max_size, size_t target_size,
                isc_mutex_init(&ctx->lock);
        }
 
-       if (init_max_size == 0U)
-               ctx->max_size = DEF_MAX_SIZE;
-       else
-               ctx->max_size = init_max_size;
+       ctx->max_size = DEF_MAX_SIZE;
        ctx->flags = flags;
        isc_refcount_init(&ctx->references, 1);
        memset(ctx->name, 0, sizeof(ctx->name));
@@ -798,10 +794,7 @@ isc_mem_createx(size_t init_max_size, size_t target_size,
        ctx->maxmalloced += (ctx->max_size+1) * sizeof(struct stats);
 
        if ((flags & ISC_MEMFLAG_INTERNAL) != 0) {
-               if (target_size == 0U)
-                       ctx->mem_target = DEF_MEM_TARGET;
-               else
-                       ctx->mem_target = target_size;
+               ctx->mem_target = DEF_MEM_TARGET;
                ctx->freelists = (memalloc)(arg, ctx->max_size *
                                                 sizeof(element *));
                RUNTIME_CHECK(ctx->freelists != NULL);
@@ -830,8 +823,6 @@ isc_mem_createx(size_t init_max_size, size_t target_size,
        UNLOCK(&contextslock);
 
        *ctxp = (isc_mem_t *)ctx;
-
-       return (ISC_R_SUCCESS);
 }
 
 static void
@@ -2371,11 +2362,10 @@ isc_mem_renderjson(void *memobj0) {
 }
 #endif /* HAVE_JSON_C */
 
-isc_result_t
-isc_mem_create(size_t init_max_size, size_t target_size, isc_mem_t **mctxp) {
-       return (isc_mem_createx(init_max_size, target_size,
-                               default_memalloc, default_memfree,
-                               NULL, mctxp, isc_mem_defaultflags));
+void
+isc_mem_create(isc_mem_t **mctxp) {
+       isc_mem_createx(default_memalloc, default_memfree,
+                       NULL, mctxp, isc_mem_defaultflags);
 }
 
 void *