]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Remove unused isc_mem_createx() function
authorOndřej Surý <ondrej@sury.org>
Fri, 6 Sep 2019 09:31:15 +0000 (11:31 +0200)
committerOndřej Surý <ondrej@sury.org>
Thu, 12 Sep 2019 07:26:09 +0000 (09:26 +0200)
The isc_mem_createx() function was only used in the tests to eliminate using the
default flags (which as of writing this commit message was ISC_MEMFLAG_INTERNAL
and ISC_MEMFLAG_FILL).  This commit removes the isc_mem_createx() function from
the public API.

lib/isc/include/isc/mem.h
lib/isc/mem.c
lib/isc/tests/Makefile.in
lib/isc/tests/ht_test.c
lib/isc/tests/mem_test.c
lib/isc/win32/libisc.def.in

index 804e00ad02a520a4092c51e9847b21d2aad50ae7..54d1cfffd1ea4039c3b36404dbe5e41bb1a9e57f 100644 (file)
@@ -28,9 +28,6 @@ ISC_LANG_BEGINDECLS
 #define ISC_MEM_HIWATER 1
 typedef void (*isc_mem_water_t)(void *, int);
 
-typedef void * (*isc_memalloc_t)(void *, size_t);
-typedef void (*isc_memfree_t)(void *, void *);
-
 /*%
  * Define ISC_MEM_TRACKLINES=1 to turn on detailed tracing of memory
  * allocation and freeing by file and line number.
@@ -123,14 +120,14 @@ LIBISC_EXTERNAL_DATA extern unsigned int isc_mem_defaultflags;
 #endif
 
 /*
- * Flags for isc_mem_createx() calls.
+ * Flags for isc_mem_create() calls.
  */
 #define ISC_MEMFLAG_NOLOCK     0x00000001       /* no lock is necessary */
 #define ISC_MEMFLAG_INTERNAL   0x00000002       /* use internal malloc */
 #define ISC_MEMFLAG_FILL       0x00000004       /* fill with pattern after alloc and frees */
 
 #if !ISC_MEM_USE_INTERNAL_MALLOC
-#define ISC_MEMFLAG_DEFAULT    0
+#define ISC_MEMFLAG_DEFAULT    0
 #else
 #define ISC_MEMFLAG_DEFAULT    ISC_MEMFLAG_INTERNAL|ISC_MEMFLAG_FILL
 #endif
@@ -255,25 +252,9 @@ struct isc_mempool {
 void
 isc_mem_create(isc_mem_t **mctxp);
 
-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.
  *
- * 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
- * using isc_mem_create() will use the standard library malloc()
- * and free().
- *
- * If ISC_MEMFLAG_NOLOCK is set in 'flags', the corresponding memory context
- * will be accessed without locking.  The user who creates the context must
- * ensure there be no race.  Since this can be a source of bug, it is generally
- * inadvisable to use this flag unless the user is very sure about the race
- * condition and the access to the object is highly performance sensitive.
- *
  * Requires:
  * mctxp != NULL && *mctxp == NULL */
 /*@}*/
index 494578f07593301d91a80dfad73e927eb9530868..a2709f240da11bb19b856a45f933e8666bc00789 100644 (file)
@@ -126,15 +126,17 @@ static isc_mutex_t                contextslock;
  */
 static uint64_t                totallost;
 
+typedef void * (*isc__memalloc_t)(size_t);
+typedef void (*isc__memfree_t)(void *);
+
 struct isc__mem {
        isc_mem_t               common;
        unsigned int            flags;
        isc_mutex_t             lock;
-       isc_memalloc_t          memalloc;
-       isc_memfree_t           memfree;
-       void *                  arg;
+       isc__memalloc_t         memalloc;
+       isc__memfree_t          memfree;
        size_t                  max_size;
-       bool            checkfree;
+       bool                    checkfree;
        struct stats *          stats;
        isc_refcount_t          references;
        char                    name[16];
@@ -146,8 +148,8 @@ struct isc__mem {
        size_t                  maxmalloced;
        size_t                  hi_water;
        size_t                  lo_water;
-       bool            hi_called;
-       bool            is_overmem;
+       bool                    hi_called;
+       bool                    is_overmem;
        isc_mem_water_t         water;
        void *                  water_arg;
        ISC_LIST(isc__mempool_t) pools;
@@ -360,8 +362,7 @@ more_basic_blocks(isc__mem_t *ctx) {
        INSIST(ctx->basic_table_count <= ctx->basic_table_size);
        if (ctx->basic_table_count == ctx->basic_table_size) {
                table_size = ctx->basic_table_size + TABLE_INCREMENT;
-               table = (ctx->memalloc)(ctx->arg,
-                                       table_size * sizeof(unsigned char *));
+               table = (ctx->memalloc)(table_size * sizeof(unsigned char *));
                RUNTIME_CHECK(table != NULL);
                ctx->malloced += table_size * sizeof(unsigned char *);
                if (ctx->malloced > ctx->maxmalloced)
@@ -370,7 +371,7 @@ more_basic_blocks(isc__mem_t *ctx) {
                        memmove(table, ctx->basic_table,
                                ctx->basic_table_size *
                                  sizeof(unsigned char *));
-                       (ctx->memfree)(ctx->arg, ctx->basic_table);
+                       (ctx->memfree)(ctx->basic_table);
                        ctx->malloced -= ctx->basic_table_size *
                                         sizeof(unsigned char *);
                }
@@ -378,7 +379,7 @@ more_basic_blocks(isc__mem_t *ctx) {
                ctx->basic_table_size = table_size;
        }
 
-       tmp = (ctx->memalloc)(ctx->arg, NUM_BASIC_BLOCKS * ctx->mem_target);
+       tmp = (ctx->memalloc)(NUM_BASIC_BLOCKS * ctx->mem_target);
        RUNTIME_CHECK(tmp != NULL);
        ctx->total += NUM_BASIC_BLOCKS * ctx->mem_target;;
        ctx->basic_table[ctx->basic_table_count] = tmp;
@@ -471,7 +472,7 @@ mem_getunlocked(isc__mem_t *ctx, size_t size) {
                /*
                 * memget() was called on something beyond our upper limit.
                 */
-               ret = (ctx->memalloc)(ctx->arg, size);
+               ret = (ctx->memalloc)(size);
                RUNTIME_CHECK(ret != NULL);
                ctx->total += size;
                ctx->inuse += size;
@@ -550,7 +551,7 @@ mem_putunlocked(isc__mem_t *ctx, void *mem, size_t size) {
                if (ISC_UNLIKELY((ctx->flags & ISC_MEMFLAG_FILL) != 0))
                        memset(mem, 0xde, size); /* Mnemonic for "dead". */
 
-               (ctx->memfree)(ctx->arg, mem);
+               (ctx->memfree)(mem);
                INSIST(ctx->stats[ctx->max_size].gets != 0U);
                ctx->stats[ctx->max_size].gets--;
                INSIST(size <= ctx->inuse);
@@ -594,7 +595,7 @@ mem_get(isc__mem_t *ctx, size_t size) {
 #if ISC_MEM_CHECKOVERRUN
        size += 1;
 #endif
-       ret = (ctx->memalloc)(ctx->arg, size);
+       ret = (ctx->memalloc)(size);
        RUNTIME_CHECK(ret != NULL);
 
        if (ISC_UNLIKELY((ctx->flags & ISC_MEMFLAG_FILL) != 0)) {
@@ -623,7 +624,7 @@ mem_put(isc__mem_t *ctx, void *mem, size_t size) {
 #endif
        if (ISC_UNLIKELY((ctx->flags & ISC_MEMFLAG_FILL) != 0))
                memset(mem, 0xde, size); /* Mnemonic for "dead". */
-       (ctx->memfree)(ctx->arg, mem);
+       (ctx->memfree)(mem);
 }
 
 /*!
@@ -678,9 +679,8 @@ mem_putstats(isc__mem_t *ctx, void *ptr, size_t size) {
  */
 
 static void *
-default_memalloc(void *arg, size_t size) {
+default_memalloc(size_t size) {
        void *ptr;
-       UNUSED(arg);
 
        ptr = malloc(size);
 
@@ -709,8 +709,7 @@ default_memalloc(void *arg, size_t size) {
 }
 
 static void
-default_memfree(void *arg, void *ptr) {
-       UNUSED(arg);
+default_memfree(void *ptr) {
        free(ptr);
 }
 
@@ -721,27 +720,19 @@ initialize_action(void) {
        totallost = 0;
 }
 
-/*
- * Public.
- */
-
-void
-isc_mem_createx(isc_memalloc_t memalloc, isc_memfree_t memfree, void *arg,
-               isc_mem_t **ctxp, unsigned int flags)
+static void
+mem_create(isc_mem_t **ctxp, unsigned int flags)
 {
        isc__mem_t *ctx;
 
        REQUIRE(ctxp != NULL && *ctxp == NULL);
-       REQUIRE(memalloc != NULL);
-       REQUIRE(memfree != NULL);
 
        STATIC_ASSERT((ALIGNMENT_SIZE & (ALIGNMENT_SIZE - 1)) == 0,
                      "wrong alignment size");
 
        RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
 
-       ctx = (memalloc)(arg, sizeof(*ctx));
-       RUNTIME_CHECK(ctx != NULL);
+       ctx = (default_memalloc)(sizeof(*ctx));
 
        if ((flags & ISC_MEMFLAG_NOLOCK) == 0) {
                isc_mutex_init(&ctx->lock);
@@ -766,9 +757,8 @@ isc_mem_createx(isc_memalloc_t memalloc, isc_memfree_t memfree, void *arg,
        ctx->common.impmagic = MEM_MAGIC;
        ctx->common.magic = ISCAPI_MCTX_MAGIC;
        ctx->common.methods = (isc_memmethods_t *)&memmethods;
-       ctx->memalloc = memalloc;
-       ctx->memfree = memfree;
-       ctx->arg = arg;
+       ctx->memalloc = default_memalloc;
+       ctx->memfree = default_memfree;
        ctx->stats = NULL;
        ctx->checkfree = true;
 #if ISC_MEM_TRACKLINES
@@ -785,8 +775,7 @@ isc_mem_createx(isc_memalloc_t memalloc, isc_memfree_t memfree, void *arg,
        ctx->lowest = NULL;
        ctx->highest = NULL;
 
-       ctx->stats = (memalloc)(arg,
-                               (ctx->max_size+1) * sizeof(struct stats));
+       ctx->stats = (ctx->memalloc)((ctx->max_size+1) * sizeof(struct stats));
        RUNTIME_CHECK(ctx->stats != NULL);
 
        memset(ctx->stats, 0, (ctx->max_size + 1) * sizeof(struct stats));
@@ -795,7 +784,7 @@ isc_mem_createx(isc_memalloc_t memalloc, isc_memfree_t memfree, void *arg,
 
        if ((flags & ISC_MEMFLAG_INTERNAL) != 0) {
                ctx->mem_target = DEF_MEM_TARGET;
-               ctx->freelists = (memalloc)(arg, ctx->max_size *
+               ctx->freelists = (ctx->memalloc)(ctx->max_size *
                                                 sizeof(element *));
                RUNTIME_CHECK(ctx->freelists != NULL);
                memset(ctx->freelists, 0,
@@ -808,7 +797,7 @@ isc_mem_createx(isc_memalloc_t memalloc, isc_memfree_t memfree, void *arg,
        if (ISC_UNLIKELY((isc_mem_debugging & ISC_MEM_DEBUGRECORD) != 0)) {
                unsigned int i;
 
-               ctx->debuglist = (memalloc)(arg, (DEBUG_TABLE_COUNT *
+               ctx->debuglist = (ctx->memalloc)((DEBUG_TABLE_COUNT *
                                                  sizeof(debuglist_t)));
                RUNTIME_CHECK(ctx->debuglist != NULL);
                for (i = 0; i < DEBUG_TABLE_COUNT; i++)
@@ -825,6 +814,10 @@ isc_mem_createx(isc_memalloc_t memalloc, isc_memfree_t memfree, void *arg,
        *ctxp = (isc_mem_t *)ctx;
 }
 
+/*
+ * Public.
+ */
+
 static void
 destroy(isc__mem_t *ctx) {
        unsigned int i;
@@ -856,7 +849,7 @@ destroy(isc__mem_t *ctx) {
                                ctx->malloced -= sizeof(*dl);
                        }
 
-               (ctx->memfree)(ctx->arg, ctx->debuglist);
+               (ctx->memfree)(ctx->debuglist);
                ctx->malloced -= DEBUG_TABLE_COUNT * sizeof(debuglist_t);
        }
 #endif
@@ -877,18 +870,18 @@ destroy(isc__mem_t *ctx) {
                }
        }
 
-       (ctx->memfree)(ctx->arg, ctx->stats);
+       (ctx->memfree)(ctx->stats);
        ctx->malloced -= (ctx->max_size+1) * sizeof(struct stats);
 
        if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0) {
                for (i = 0; i < ctx->basic_table_count; i++) {
-                       (ctx->memfree)(ctx->arg, ctx->basic_table[i]);
+                       (ctx->memfree)(ctx->basic_table[i]);
                        ctx->malloced -= NUM_BASIC_BLOCKS * ctx->mem_target;
                }
-               (ctx->memfree)(ctx->arg, ctx->freelists);
+               (ctx->memfree)(ctx->freelists);
                ctx->malloced -= ctx->max_size * sizeof(element *);
                if (ctx->basic_table != NULL) {
-                       (ctx->memfree)(ctx->arg, ctx->basic_table);
+                       (ctx->memfree)(ctx->basic_table);
                        ctx->malloced -= ctx->basic_table_size *
                                         sizeof(unsigned char *);
                }
@@ -899,7 +892,7 @@ destroy(isc__mem_t *ctx) {
        ctx->malloced -= sizeof(*ctx);
        if (ctx->checkfree)
                INSIST(ctx->malloced == 0);
-       (ctx->memfree)(ctx->arg, ctx);
+       (ctx->memfree)(ctx);
 }
 
 void
@@ -2364,8 +2357,7 @@ isc_mem_renderjson(void *memobj0) {
 
 void
 isc_mem_create(isc_mem_t **mctxp) {
-       isc_mem_createx(default_memalloc, default_memfree,
-                       NULL, mctxp, isc_mem_defaultflags);
+       mem_create(mctxp, isc_mem_defaultflags);
 }
 
 void *
index 1f5e6b2f10e045cd2ebb0c3d3677c2806d74640a..abeca57a6273b42f7b1674da59ecb39f96e255bc 100644 (file)
@@ -16,7 +16,10 @@ VERSION=@BIND9_VERSION@
 @BIND9_MAKE_INCLUDES@
 
 CINCLUDES =    -I. -Iinclude ${ISC_INCLUDES} \
-               ${OPENSSL_CFLAGS} @CMOCKA_CFLAGS@
+               ${OPENSSL_CFLAGS} @CMOCKA_CFLAGS@ \
+               ${JSON_C_CFLAGS} \
+               ${LIBXML2_CFLAGS} \
+               ${ZLIB_CFLAGS}
 CDEFINES =     -DTESTS="\"${top_builddir}/lib/isc/tests/\""
 
 ISCLIBS =      ../libisc.@A@ ${OPENSSL_LIBS} ${JSON_C_LIBS} ${LIBXML2_LIBS}
index 9129365912785322009276b39b929d70b53465bc..40bfccbc75f7def1384849bffd62f1412574c081 100644 (file)
 #include <isc/string.h>
 #include <isc/util.h>
 
-static void *
-default_memalloc(void *arg, size_t size) {
-       UNUSED(arg);
-       if (size == 0U) {
-               size = 1;
-       }
-       return (malloc(size));
-}
-
-static void
-default_memfree(void *arg, void *ptr) {
-       UNUSED(arg);
-       free(ptr);
-}
-
 static void
 test_ht_full(int bits, uintptr_t count) {
        isc_ht_t *ht = NULL;
@@ -53,8 +38,7 @@ test_ht_full(int bits, uintptr_t count) {
        isc_mem_t *mctx = NULL;
        uintptr_t i;
 
-       isc_mem_createx(default_memalloc, default_memfree,
-                       NULL, &mctx, 0);
+       isc_mem_create(&mctx);
 
        result = isc_ht_init(&ht, mctx, bits);
        assert_int_equal(result, ISC_R_SUCCESS);
@@ -206,8 +190,7 @@ test_ht_iterator() {
        unsigned char key[16];
        size_t tksize;
 
-       isc_mem_createx(default_memalloc, default_memfree,
-                       NULL, &mctx, 0);
+       isc_mem_create(&mctx);
 
        result = isc_ht_init(&ht, mctx, 16);
        assert_int_equal(result, ISC_R_SUCCESS);
index 74c0fdf1fb9a78022d7ce926d559564309928258..bdf8c2a53c3f8e6405ea4cfd38bd81936e576ec5 100644 (file)
@@ -50,21 +50,6 @@ _setup(void **state) {
        return (0);
 }
 
-static void *
-default_memalloc(void *arg, size_t size) {
-       UNUSED(arg);
-       if (size == 0U) {
-               size = 1;
-       }
-       return (malloc(size));
-}
-
-static void
-default_memfree(void *arg, void *ptr) {
-       UNUSED(arg);
-       free(ptr);
-}
-
 static int
 _teardown(void **state) {
        UNUSED(state);
@@ -168,9 +153,7 @@ isc_mem_test(void **state) {
 
        isc_mem_destroy(&localmctx);
 
-       isc_mem_createx(default_memalloc, default_memfree,
-                       NULL, &localmctx,
-                       ISC_MEMFLAG_FILL | ISC_MEMFLAG_INTERNAL);
+       isc_mem_create(&localmctx);
 
        result = isc_mempool_create(localmctx, 2, &mp1);
        assert_int_equal(result, ISC_R_SUCCESS);
@@ -198,8 +181,7 @@ isc_mem_total_test(void **state) {
 
        /* Local alloc, free */
        mctx2 = NULL;
-       isc_mem_createx(default_memalloc, default_memfree,
-                                NULL, &mctx2, 0);
+       isc_mem_create(&mctx2);
 
        before = isc_mem_total(mctx2);
 
@@ -247,8 +229,7 @@ isc_mem_inuse_test(void **state) {
        UNUSED(state);
 
        mctx2 = NULL;
-       isc_mem_createx(default_memalloc, default_memfree,
-                       NULL, &mctx2, 0);
+       isc_mem_create(&mctx2);
 
        before = isc_mem_inuse(mctx2);
        ptr = isc_mem_allocate(mctx2, 1024000);
@@ -278,8 +259,7 @@ isc_mem_noflags_test(void **state) {
 
        UNUSED(state);
 
-       isc_mem_createx(default_memalloc, default_memfree,
-                       NULL, &mctx2, 0);
+       isc_mem_create(&mctx2);
        isc_mem_debugging = 0;
        ptr = isc_mem_get(mctx2, 2048);
        assert_non_null(ptr);
@@ -324,8 +304,7 @@ isc_mem_recordflag_test(void **state) {
 
        UNUSED(state);
 
-       isc_mem_createx(default_memalloc, default_memfree,
-                       NULL, &mctx2, 0);
+       isc_mem_create(&mctx2);
        ptr = isc_mem_get(mctx2, 2048);
        assert_non_null(ptr);
        isc__mem_printactive(mctx2, f);
@@ -368,8 +347,7 @@ isc_mem_traceflag_test(void **state) {
 
        UNUSED(state);
 
-       isc_mem_createx(default_memalloc, default_memfree,
-                       NULL, &mctx2, 0);
+       isc_mem_create(&mctx2);
        isc_mem_debugging = ISC_MEM_DEBUGTRACE;
        ptr = isc_mem_get(mctx2, 2048);
        assert_non_null(ptr);
index 77e021d486b5256e70674e06a4ac100ed455118b..96097ff1bcb5ab520ad25584cc4dfa08fe6da94b 100644 (file)
@@ -348,7 +348,6 @@ isc_md
 isc_mem_attach
 isc_mem_checkdestroyed
 isc_mem_create
-isc_mem_createx
 isc_mem_destroy
 isc_mem_detach
 isc_mem_getname