From 7b8f19880964a009c4bd664de8bdfa27e28668b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Tue, 14 Jul 2020 11:19:18 +0200 Subject: [PATCH] Remove an extra level of indirection in memory context routines The memory context object formerly had an option to replace the memory routines with own implementation when used outside of BIND 9. The ability to actually replace these was removed some time ago as the libraries are now considered internal to BIND 9, and the default set of the routines was always used. The extra layer of indirection has been removed now as well. --- lib/isc/include/isc/mem.h | 23 ++++--------------- lib/isc/mem.c | 48 +++++++++++++-------------------------- 2 files changed, 21 insertions(+), 50 deletions(-) diff --git a/lib/isc/include/isc/mem.h b/lib/isc/include/isc/mem.h index 4c50bfaf35..77119fc92a 100644 --- a/lib/isc/include/isc/mem.h +++ b/lib/isc/include/isc/mem.h @@ -162,21 +162,6 @@ LIBISC_EXTERNAL_DATA extern unsigned int isc_mem_defaultflags; * \endcode */ -/*% memory and memory pool methods */ -typedef struct isc_memmethods { - void *(*memget)(isc_mem_t *mctx, size_t size _ISC_MEM_FLARG); - void (*memput)(isc_mem_t *mctx, void *ptr, size_t size _ISC_MEM_FLARG); - void (*memputanddetach)(isc_mem_t **mctxp, void *ptr, - size_t size _ISC_MEM_FLARG); - void *(*memallocate)(isc_mem_t *mctx, size_t size _ISC_MEM_FLARG); - void *(*memreallocate)(isc_mem_t *mctx, void *ptr, - size_t size _ISC_MEM_FLARG); - char *(*memstrdup)(isc_mem_t *mctx, const char *s _ISC_MEM_FLARG); - char *(*memstrndup)(isc_mem_t *mctx, const char *s, - size_t size _ISC_MEM_FLARG); - void (*memfree)(isc_mem_t *mctx, void *ptr _ISC_MEM_FLARG); -} isc_memmethods_t; - /*% * This structure is actually just the common prefix of a memory context * implementation's version of an isc_mem_t. @@ -187,9 +172,8 @@ typedef struct isc_memmethods { * invariants. */ struct isc_mem { - unsigned int impmagic; - unsigned int magic; - isc_memmethods_t *methods; + unsigned int impmagic; + unsigned int magic; }; #define ISCAPI_MCTX_MAGIC ISC_MAGIC('A', 'm', 'c', 'x') @@ -613,6 +597,7 @@ void ISCMEMPOOLFUNC(put)(isc_mempool_t *, void *_ISC_MEM_FLARG); #define isc_realloc(ptr, size) isc__realloc((ptr), (size)_ISC_MEM_FILELINE) #define isc_free(ptr) isc__free((ptr)_ISC_MEM_FILELINE) #define isc_strdup(str) isc__strdup((str)_ISC_MEM_FILELINE) +#define isc_strndup(str) isc__strndup((str)_ISC_MEM_FILELINE) void * isc__malloc(size_t size _ISC_MEM_FLARG); @@ -624,6 +609,8 @@ void isc__free(void *ptr _ISC_MEM_FLARG); char * isc__strdup(const char *str _ISC_MEM_FLARG); +char * +isc__strndup(const char *str _ISC_MEM_FLARG); ISC_LANG_ENDDECLS diff --git a/lib/isc/mem.c b/lib/isc/mem.c index 1afea66d66..91719df740 100644 --- a/lib/isc/mem.c +++ b/lib/isc/mem.c @@ -232,29 +232,6 @@ print_active(isc__mem_t *ctx, FILE *out); #endif /* ISC_MEM_TRACKLINES */ -static void * -isc___mem_get(isc_mem_t *ctx, size_t size FLARG); -static void -isc___mem_put(isc_mem_t *ctx, void *ptr, size_t size FLARG); -static void -isc___mem_putanddetach(isc_mem_t **ctxp, void *ptr, size_t size FLARG); -static void * -isc___mem_allocate(isc_mem_t *ctx, size_t size FLARG); -static void * -isc___mem_reallocate(isc_mem_t *ctx, void *ptr, size_t size FLARG); -static char * -isc___mem_strdup(isc_mem_t *mctx, const char *s FLARG); -static char * -isc___mem_strndup(isc_mem_t *mctx, const char *s, size_t size FLARG); -static void -isc___mem_free(isc_mem_t *ctx, void *ptr FLARG); - -static isc_memmethods_t memmethods = { - isc___mem_get, isc___mem_put, isc___mem_putanddetach, - isc___mem_allocate, isc___mem_reallocate, isc___mem_strdup, - isc___mem_strndup, isc___mem_free, -}; - #if ISC_MEM_TRACKLINES /*! * mctx must be locked. @@ -784,7 +761,6 @@ mem_create(isc_mem_t **ctxp, unsigned int flags) { ctx->water_arg = NULL; ctx->common.impmagic = MEM_MAGIC; ctx->common.magic = ISCAPI_MCTX_MAGIC; - ctx->common.methods = (isc_memmethods_t *)&memmethods; ctx->memalloc = default_memalloc; ctx->memfree = default_memfree; ctx->stats = NULL; @@ -959,7 +935,7 @@ isc_mem_detach(isc_mem_t **ctxp) { */ void -isc___mem_putanddetach(isc_mem_t **ctxp, void *ptr, size_t size FLARG) { +isc__mem_putanddetach(isc_mem_t **ctxp, void *ptr, size_t size FLARG) { REQUIRE(ctxp != NULL && VALID_CONTEXT(*ctxp)); REQUIRE(ptr != NULL); @@ -1026,7 +1002,7 @@ isc_mem_destroy(isc_mem_t **ctxp) { } void * -isc___mem_get(isc_mem_t *ctx0, size_t size FLARG) { +isc__mem_get(isc_mem_t *ctx0, size_t size FLARG) { REQUIRE(VALID_CONTEXT(ctx0)); isc__mem_t *ctx = (isc__mem_t *)ctx0; @@ -1077,7 +1053,7 @@ isc___mem_get(isc_mem_t *ctx0, size_t size FLARG) { } void -isc___mem_put(isc_mem_t *ctx0, void *ptr, size_t size FLARG) { +isc__mem_put(isc_mem_t *ctx0, void *ptr, size_t size FLARG) { REQUIRE(VALID_CONTEXT(ctx0)); REQUIRE(ptr != NULL); @@ -1279,7 +1255,7 @@ mem_allocateunlocked(isc_mem_t *ctx0, size_t size) { } void * -isc___mem_allocate(isc_mem_t *ctx0, size_t size FLARG) { +isc__mem_allocate(isc_mem_t *ctx0, size_t size FLARG) { REQUIRE(VALID_CONTEXT(ctx0)); isc__mem_t *ctx = (isc__mem_t *)ctx0; @@ -1323,7 +1299,7 @@ isc___mem_allocate(isc_mem_t *ctx0, size_t size FLARG) { } void * -isc___mem_reallocate(isc_mem_t *ctx0, void *ptr, size_t size FLARG) { +isc__mem_reallocate(isc_mem_t *ctx0, void *ptr, size_t size FLARG) { REQUIRE(VALID_CONTEXT(ctx0)); void *new_ptr = NULL; @@ -1363,7 +1339,7 @@ isc___mem_reallocate(isc_mem_t *ctx0, void *ptr, size_t size FLARG) { } void -isc___mem_free(isc_mem_t *ctx0, void *ptr FLARG) { +isc__mem_free(isc_mem_t *ctx0, void *ptr FLARG) { REQUIRE(VALID_CONTEXT(ctx0)); REQUIRE(ptr != NULL); @@ -1422,7 +1398,7 @@ isc___mem_free(isc_mem_t *ctx0, void *ptr FLARG) { */ char * -isc___mem_strdup(isc_mem_t *mctx0, const char *s FLARG) { +isc__mem_strdup(isc_mem_t *mctx0, const char *s FLARG) { REQUIRE(VALID_CONTEXT(mctx0)); REQUIRE(s != NULL); @@ -1442,7 +1418,7 @@ isc___mem_strdup(isc_mem_t *mctx0, const char *s FLARG) { } char * -isc___mem_strndup(isc_mem_t *mctx0, const char *s, size_t size FLARG) { +isc__mem_strndup(isc_mem_t *mctx0, const char *s, size_t size FLARG) { REQUIRE(VALID_CONTEXT(mctx0)); REQUIRE(s != NULL); @@ -2450,6 +2426,7 @@ isc_mem_create(isc_mem_t **mctxp) { mem_create(mctxp, isc_mem_defaultflags); } +<<<<<<< HEAD void * isc__mem_get(isc_mem_t *mctx, size_t size FLARG) { REQUIRE(ISCAPI_MCTX_VALID(mctx)); @@ -2506,6 +2483,8 @@ isc__mem_free(isc_mem_t *mctx, void *ptr FLARG) { mctx->methods->memfree(mctx, ptr FLARG_PASS); } +======= +>>>>>>> 532e5a3b4f (Remove an extra level of indirection in memory context routines) void isc__mem_printactive(isc_mem_t *ctx0, FILE *file) { #if ISC_MEM_TRACKLINES @@ -2577,3 +2556,8 @@ char * isc__strdup(const char *s1 FLARG) { return (isc__mem_strdup(isc__mem_mctx, s1 FLARG_PASS)); } + +char * +isc__strndup(const char *s1 FLARG) { + return (isc__mem_strndup(isc__mem_mctx, s1 FLARG_PASS)); +}