mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-29 05:28:00 +00:00
Merge branch 'ondrej-cleanup-mem-macros' into 'main'
Remove some unnecessary token pasting macrology See merge request isc-projects/bind9!8236
This commit is contained in:
commit
01c758ea3a
@ -739,7 +739,7 @@ signed_strict(dns_rdataset_t *dsset, dns_secalg_t *algo) {
|
||||
}
|
||||
}
|
||||
|
||||
isc_mem_put(mctx, algo, nkey);
|
||||
isc_mem_put(mctx, algo, nkey * sizeof(algo[0]));
|
||||
return (all_ok);
|
||||
}
|
||||
|
||||
|
@ -606,8 +606,7 @@ create_db(isc_mem_t *mctx, const dns_name_t *origin, dns_dbtype_t type,
|
||||
|
||||
a_addr.s_addr = 0x0100007fU;
|
||||
|
||||
CHECKED_MEM_GET_PTR(mctx, sampledb);
|
||||
ZERO_PTR(sampledb);
|
||||
sampledb = isc_mem_getx(mctx, sizeof(*sampledb), ISC_MEM_ZERO);
|
||||
|
||||
isc_mem_attach(mctx, &sampledb->common.mctx);
|
||||
dns_name_init(&sampledb->common.origin, NULL);
|
||||
|
@ -111,12 +111,11 @@ new_sample_instance(isc_mem_t *mctx, const char *db_name, int argc, char **argv,
|
||||
const dns_dyndbctx_t *dctx,
|
||||
sample_instance_t **sample_instp) {
|
||||
isc_result_t result;
|
||||
sample_instance_t *inst = NULL;
|
||||
|
||||
REQUIRE(sample_instp != NULL && *sample_instp == NULL);
|
||||
|
||||
CHECKED_MEM_GET_PTR(mctx, inst);
|
||||
ZERO_PTR(inst);
|
||||
sample_instance_t *inst = isc_mem_getx(mctx, sizeof(*inst),
|
||||
ISC_MEM_ZERO);
|
||||
isc_mem_attach(mctx, &inst->mctx);
|
||||
|
||||
inst->db_name = isc_mem_strdup(mctx, db_name);
|
||||
@ -225,5 +224,5 @@ destroy_sample_instance(sample_instance_t **instp) {
|
||||
dns_view_detach(&inst->view);
|
||||
dns_zonemgr_detach(&inst->zmgr);
|
||||
|
||||
MEM_PUT_AND_DETACH(inst);
|
||||
isc_mem_putanddetach(&inst->mctx, inst, sizeof(*inst));
|
||||
}
|
||||
|
@ -51,32 +51,3 @@
|
||||
if (result != ISC_R_SUCCESS) \
|
||||
goto cleanup; \
|
||||
} while (0)
|
||||
|
||||
#define CHECKED_MEM_GET(m, target_ptr, s) \
|
||||
do { \
|
||||
(target_ptr) = isc_mem_get((m), (s)); \
|
||||
if ((target_ptr) == NULL) { \
|
||||
result = ISC_R_NOMEMORY; \
|
||||
log_error("Memory allocation failed"); \
|
||||
goto cleanup; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECKED_MEM_GET_PTR(m, target_ptr) \
|
||||
CHECKED_MEM_GET(m, target_ptr, sizeof(*(target_ptr)))
|
||||
|
||||
#define CHECKED_MEM_STRDUP(m, source, target) \
|
||||
do { \
|
||||
(target) = isc_mem_strdup((m), (source)); \
|
||||
if ((target) == NULL) { \
|
||||
result = ISC_R_NOMEMORY; \
|
||||
log_error("Memory allocation failed"); \
|
||||
goto cleanup; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define ZERO_PTR(ptr) memset((ptr), 0, sizeof(*(ptr)))
|
||||
|
||||
#define MEM_PUT_AND_DETACH(target_ptr) \
|
||||
isc_mem_putanddetach(&(target_ptr)->mctx, target_ptr, \
|
||||
sizeof(*(target_ptr)))
|
||||
|
@ -154,71 +154,66 @@ extern unsigned int isc_mem_defaultflags;
|
||||
#endif
|
||||
#define ISC_MEM_ZERO ((int)0x40)
|
||||
|
||||
#define ISCMEMFUNC(sfx) isc__mem_##sfx
|
||||
#define ISCMEMPOOLFUNC(sfx) isc__mempool_##sfx
|
||||
|
||||
#define isc_mem_get(c, s) ISCMEMFUNC(get)((c), (s), 0 _ISC_MEM_FILELINE)
|
||||
#define isc_mem_getx(c, s, f) ISCMEMFUNC(get)((c), (s), (f)_ISC_MEM_FILELINE)
|
||||
#define isc_mem_get(c, s) isc__mem_get((c), (s), 0 _ISC_MEM_FILELINE)
|
||||
#define isc_mem_getx(c, s, f) isc__mem_get((c), (s), (f)_ISC_MEM_FILELINE)
|
||||
#define isc_mem_reget(c, p, o, n) \
|
||||
ISCMEMFUNC(reget)((c), (p), (o), (n), 0 _ISC_MEM_FILELINE)
|
||||
isc__mem_reget((c), (p), (o), (n), 0 _ISC_MEM_FILELINE)
|
||||
#define isc_mem_regetx(c, p, o, n, f) \
|
||||
ISCMEMFUNC(reget)((c), (p), (o), (n), (f)_ISC_MEM_FILELINE)
|
||||
#define isc_mem_allocate(c, s) \
|
||||
ISCMEMFUNC(allocate)((c), (s), 0 _ISC_MEM_FILELINE)
|
||||
isc__mem_reget((c), (p), (o), (n), (f)_ISC_MEM_FILELINE)
|
||||
#define isc_mem_allocate(c, s) isc__mem_allocate((c), (s), 0 _ISC_MEM_FILELINE)
|
||||
#define isc_mem_allocatex(c, s, f) \
|
||||
ISCMEMFUNC(allocate)((c), (s), (f)_ISC_MEM_FILELINE)
|
||||
isc__mem_allocate((c), (s), (f)_ISC_MEM_FILELINE)
|
||||
#define isc_mem_callocate(c, n, s) \
|
||||
ISCMEMFUNC(callocate)((c), (n), (s), 0 _ISC_MEM_FILELINE)
|
||||
isc__mem_callocate((c), (n), (s), 0 _ISC_MEM_FILELINE)
|
||||
#define isc_mem_reallocate(c, p, s) \
|
||||
ISCMEMFUNC(reallocate)((c), (p), (s), 0 _ISC_MEM_FILELINE)
|
||||
isc__mem_reallocate((c), (p), (s), 0 _ISC_MEM_FILELINE)
|
||||
#define isc_mem_reallocatex(c, p, s, f) \
|
||||
ISCMEMFUNC(reallocate)((c), (p), (s), (f)_ISC_MEM_FILELINE)
|
||||
#define isc_mem_strdup(c, p) ISCMEMFUNC(strdup)((c), (p)_ISC_MEM_FILELINE)
|
||||
isc__mem_reallocate((c), (p), (s), (f)_ISC_MEM_FILELINE)
|
||||
#define isc_mem_strdup(c, p) isc__mem_strdup((c), (p)_ISC_MEM_FILELINE)
|
||||
#define isc_mem_strndup(c, p, l) \
|
||||
ISCMEMFUNC(strndup)((c), (p), (l)_ISC_MEM_FILELINE)
|
||||
#define isc_mempool_get(c) ISCMEMPOOLFUNC(get)((c)_ISC_MEM_FILELINE)
|
||||
isc__mem_strndup((c), (p), (l)_ISC_MEM_FILELINE)
|
||||
#define isc_mempool_get(c) isc__mempool_get((c)_ISC_MEM_FILELINE)
|
||||
|
||||
#define isc_mem_put(c, p, s) \
|
||||
do { \
|
||||
ISCMEMFUNC(put)((c), (p), (s), 0 _ISC_MEM_FILELINE); \
|
||||
(p) = NULL; \
|
||||
} while (0)
|
||||
#define isc_mem_putx(c, p, s, f) \
|
||||
do { \
|
||||
ISCMEMFUNC(put) \
|
||||
((c), (p), (s), (f)_ISC_MEM_FILELINE); \
|
||||
(p) = NULL; \
|
||||
} while (0)
|
||||
#define isc_mem_putanddetach(c, p, s) \
|
||||
do { \
|
||||
ISCMEMFUNC(putanddetach)((c), (p), (s), 0 _ISC_MEM_FILELINE); \
|
||||
(p) = NULL; \
|
||||
} while (0)
|
||||
#define isc_mem_putanddetachx(c, p, s, f) \
|
||||
do { \
|
||||
ISCMEMFUNC(putanddetach) \
|
||||
((c), (p), (s), (f)_ISC_MEM_FILELINE); \
|
||||
(p) = NULL; \
|
||||
} while (0)
|
||||
#define isc_mem_free(c, p) \
|
||||
do { \
|
||||
ISCMEMFUNC(free)((c), (p), 0 _ISC_MEM_FILELINE); \
|
||||
(p) = NULL; \
|
||||
} while (0)
|
||||
#define isc_mem_freex(c, p, f) \
|
||||
#define isc_mem_put(c, p, s) \
|
||||
do { \
|
||||
ISCMEMFUNC(free)((c), (p), (f)_ISC_MEM_FILELINE); \
|
||||
isc__mem_put((c), (p), (s), 0 _ISC_MEM_FILELINE); \
|
||||
(p) = NULL; \
|
||||
} while (0)
|
||||
#define isc_mempool_put(c, p) \
|
||||
do { \
|
||||
ISCMEMPOOLFUNC(put)((c), (p)_ISC_MEM_FILELINE); \
|
||||
(p) = NULL; \
|
||||
#define isc_mem_putx(c, p, s, f) \
|
||||
do { \
|
||||
isc__mem_put((c), (p), (s), (f)_ISC_MEM_FILELINE); \
|
||||
(p) = NULL; \
|
||||
} while (0)
|
||||
#define isc_mem_putanddetach(c, p, s) \
|
||||
do { \
|
||||
isc__mem_putanddetach((c), (p), (s), 0 _ISC_MEM_FILELINE); \
|
||||
(p) = NULL; \
|
||||
} while (0)
|
||||
#define isc_mem_putanddetachx(c, p, s, f) \
|
||||
do { \
|
||||
isc__mem_putanddetach((c), (p), (s), (f)_ISC_MEM_FILELINE); \
|
||||
(p) = NULL; \
|
||||
} while (0)
|
||||
#define isc_mem_free(c, p) \
|
||||
do { \
|
||||
isc__mem_free((c), (p), 0 _ISC_MEM_FILELINE); \
|
||||
(p) = NULL; \
|
||||
} while (0)
|
||||
#define isc_mem_freex(c, p, f) \
|
||||
do { \
|
||||
isc__mem_free((c), (p), (f)_ISC_MEM_FILELINE); \
|
||||
(p) = NULL; \
|
||||
} while (0)
|
||||
#define isc_mempool_put(c, p) \
|
||||
do { \
|
||||
isc__mempool_put((c), (p)_ISC_MEM_FILELINE); \
|
||||
(p) = NULL; \
|
||||
} while (0)
|
||||
|
||||
/*@{*/
|
||||
#define isc_mem_create(cp) ISCMEMFUNC(create)((cp)_ISC_MEM_FILELINE)
|
||||
void ISCMEMFUNC(create)(isc_mem_t **_ISC_MEM_FLARG);
|
||||
#define isc_mem_create(cp) isc__mem_create((cp)_ISC_MEM_FILELINE)
|
||||
void
|
||||
isc__mem_create(isc_mem_t **_ISC_MEM_FLARG);
|
||||
|
||||
/*!<
|
||||
* \brief Create a memory context.
|
||||
@ -230,8 +225,9 @@ void ISCMEMFUNC(create)(isc_mem_t **_ISC_MEM_FLARG);
|
||||
/*@{*/
|
||||
void
|
||||
isc_mem_attach(isc_mem_t *, isc_mem_t **);
|
||||
#define isc_mem_detach(cp) ISCMEMFUNC(detach)((cp)_ISC_MEM_FILELINE)
|
||||
void ISCMEMFUNC(detach)(isc_mem_t **_ISC_MEM_FLARG);
|
||||
#define isc_mem_detach(cp) isc__mem_detach((cp)_ISC_MEM_FILELINE)
|
||||
void
|
||||
isc__mem_detach(isc_mem_t **_ISC_MEM_FLARG);
|
||||
/*!<
|
||||
* \brief Attach to / detach from a memory context.
|
||||
*
|
||||
@ -246,8 +242,9 @@ void ISCMEMFUNC(detach)(isc_mem_t **_ISC_MEM_FLARG);
|
||||
*/
|
||||
/*@}*/
|
||||
|
||||
#define isc_mem_destroy(cp) ISCMEMFUNC(destroy)((cp)_ISC_MEM_FILELINE)
|
||||
void ISCMEMFUNC(destroy)(isc_mem_t **_ISC_MEM_FLARG);
|
||||
#define isc_mem_destroy(cp) isc__mem_destroy((cp)_ISC_MEM_FILELINE)
|
||||
void
|
||||
isc__mem_destroy(isc_mem_t **_ISC_MEM_FLARG);
|
||||
/*%<
|
||||
* Destroy a memory context.
|
||||
*/
|
||||
@ -501,38 +498,49 @@ isc_mempool_setfillcount(isc_mempool_t *restrict mpctx,
|
||||
/*
|
||||
* Pseudo-private functions for use via macros. Do not call directly.
|
||||
*/
|
||||
void ISCMEMFUNC(putanddetach)(isc_mem_t **, void *, size_t, int _ISC_MEM_FLARG);
|
||||
void ISCMEMFUNC(put)(isc_mem_t *, void *, size_t, int _ISC_MEM_FLARG);
|
||||
void ISCMEMFUNC(free)(isc_mem_t *, void *, int _ISC_MEM_FLARG);
|
||||
void
|
||||
isc__mem_putanddetach(isc_mem_t **, void *, size_t, int _ISC_MEM_FLARG);
|
||||
void
|
||||
isc__mem_put(isc_mem_t *, void *, size_t, int _ISC_MEM_FLARG);
|
||||
void
|
||||
isc__mem_free(isc_mem_t *, void *, int _ISC_MEM_FLARG);
|
||||
|
||||
ISC_ATTR_MALLOC_DEALLOCATOR_IDX(ISCMEMFUNC(put), 2)
|
||||
void *ISCMEMFUNC(get)(isc_mem_t *, size_t, int _ISC_MEM_FLARG);
|
||||
ISC_ATTR_MALLOC_DEALLOCATOR_IDX(isc__mem_put, 2)
|
||||
void *
|
||||
isc__mem_get(isc_mem_t *, size_t, int _ISC_MEM_FLARG);
|
||||
|
||||
ISC_ATTR_DEALLOCATOR_IDX(ISCMEMFUNC(put), 2)
|
||||
void *ISCMEMFUNC(reget)(isc_mem_t *, void *, size_t, size_t,
|
||||
int _ISC_MEM_FLARG);
|
||||
ISC_ATTR_DEALLOCATOR_IDX(isc__mem_put, 2)
|
||||
void *
|
||||
isc__mem_reget(isc_mem_t *, void *, size_t, size_t, int _ISC_MEM_FLARG);
|
||||
|
||||
ISC_ATTR_MALLOC_DEALLOCATOR_IDX(ISCMEMFUNC(free), 2)
|
||||
void *ISCMEMFUNC(allocate)(isc_mem_t *, size_t, int _ISC_MEM_FLARG);
|
||||
ISC_ATTR_MALLOC_DEALLOCATOR_IDX(isc__mem_free, 2)
|
||||
void *
|
||||
isc__mem_allocate(isc_mem_t *, size_t, int _ISC_MEM_FLARG);
|
||||
|
||||
ISC_ATTR_MALLOC_DEALLOCATOR_IDX(ISCMEMFUNC(free), 2)
|
||||
void *ISCMEMFUNC(callocate)(isc_mem_t *, size_t, size_t, int _ISC_MEM_FLARG);
|
||||
ISC_ATTR_MALLOC_DEALLOCATOR_IDX(isc__mem_free, 2)
|
||||
void *
|
||||
isc__mem_callocate(isc_mem_t *, size_t, size_t, int _ISC_MEM_FLARG);
|
||||
|
||||
ISC_ATTR_DEALLOCATOR_IDX(ISCMEMFUNC(free), 2)
|
||||
void *ISCMEMFUNC(reallocate)(isc_mem_t *, void *, size_t, int _ISC_MEM_FLARG);
|
||||
ISC_ATTR_DEALLOCATOR_IDX(isc__mem_free, 2)
|
||||
void *
|
||||
isc__mem_reallocate(isc_mem_t *, void *, size_t, int _ISC_MEM_FLARG);
|
||||
|
||||
ISC_ATTR_RETURNS_NONNULL
|
||||
ISC_ATTR_MALLOC_DEALLOCATOR_IDX(ISCMEMFUNC(free), 2)
|
||||
char *ISCMEMFUNC(strdup)(isc_mem_t *, const char *_ISC_MEM_FLARG);
|
||||
ISC_ATTR_MALLOC_DEALLOCATOR_IDX(isc__mem_free, 2)
|
||||
char *
|
||||
isc__mem_strdup(isc_mem_t *, const char *_ISC_MEM_FLARG);
|
||||
|
||||
ISC_ATTR_RETURNS_NONNULL
|
||||
ISC_ATTR_MALLOC_DEALLOCATOR_IDX(ISCMEMFUNC(free), 2)
|
||||
char *ISCMEMFUNC(strndup)(isc_mem_t *, const char *, size_t _ISC_MEM_FLARG);
|
||||
ISC_ATTR_MALLOC_DEALLOCATOR_IDX(isc__mem_free, 2)
|
||||
char *
|
||||
isc__mem_strndup(isc_mem_t *, const char *, size_t _ISC_MEM_FLARG);
|
||||
|
||||
ISC_ATTR_MALLOC_DEALLOCATOR_IDX(ISCMEMPOOLFUNC(put), 2)
|
||||
void *ISCMEMPOOLFUNC(get)(isc_mempool_t *_ISC_MEM_FLARG);
|
||||
ISC_ATTR_MALLOC_DEALLOCATOR_IDX(isc__mempool_put, 2)
|
||||
void *
|
||||
isc__mempool_get(isc_mempool_t *_ISC_MEM_FLARG);
|
||||
|
||||
void ISCMEMPOOLFUNC(put)(isc_mempool_t *, void *_ISC_MEM_FLARG);
|
||||
void
|
||||
isc__mempool_put(isc_mempool_t *, void *_ISC_MEM_FLARG);
|
||||
|
||||
#ifdef POP_MALLOC_MACRO
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user