Add isc_mem_callocate() and isc_mem_cget() functions
These two functions mimick the standard library calloc(num, size) function by allocating num*size continuous memory and clearing the memory after the allocation.
This commit is contained in:
@@ -207,8 +207,11 @@ struct isc_mempool {
|
||||
#define ISCMEMFUNC(sfx) isc__mem_##sfx
|
||||
#define ISCMEMPOOLFUNC(sfx) isc__mempool_##sfx
|
||||
|
||||
#define isc_mem_get(c, s) ISCMEMFUNC(get)((c), (s)_ISC_MEM_FILELINE)
|
||||
#define isc_mem_get(c, s) ISCMEMFUNC(get)((c), (s)_ISC_MEM_FILELINE)
|
||||
#define isc_mem_cget(c, n, s) ISCMEMFUNC(cget((c), (n), (s)_ISC_MEM_FILELINE)
|
||||
#define isc_mem_allocate(c, s) ISCMEMFUNC(allocate)((c), (s)_ISC_MEM_FILELINE)
|
||||
#define isc_mem_callocate(c, n, s) \
|
||||
ISCMEMFUNC(callocate)((c), (n), (s)_ISC_MEM_FILELINE)
|
||||
#define isc_mem_reallocate(c, p, s) \
|
||||
ISCMEMFUNC(reallocate)((c), (p), (s)_ISC_MEM_FILELINE)
|
||||
#define isc_mem_strdup(c, p) ISCMEMFUNC(strdup)((c), (p)_ISC_MEM_FILELINE)
|
||||
@@ -578,9 +581,11 @@ isc_mempool_setfillcount(isc_mempool_t *mpctx, unsigned int limit);
|
||||
* Pseudo-private functions for use via macros. Do not call directly.
|
||||
*/
|
||||
void *ISCMEMFUNC(get)(isc_mem_t *, size_t _ISC_MEM_FLARG);
|
||||
void *ISCMEMFUNC(cget)(isc_mem_t *, size_t, size_t _ISC_MEM_FLARG);
|
||||
void ISCMEMFUNC(putanddetach)(isc_mem_t **, void *, size_t _ISC_MEM_FLARG);
|
||||
void ISCMEMFUNC(put)(isc_mem_t *, void *, size_t _ISC_MEM_FLARG);
|
||||
void *ISCMEMFUNC(allocate)(isc_mem_t *, size_t _ISC_MEM_FLARG);
|
||||
void *ISCMEMFUNC(callocate)(isc_mem_t *, size_t, size_t _ISC_MEM_FLARG);
|
||||
void *ISCMEMFUNC(reallocate)(isc_mem_t *, void *, size_t _ISC_MEM_FLARG);
|
||||
void ISCMEMFUNC(free)(isc_mem_t *, void *_ISC_MEM_FLARG);
|
||||
char *ISCMEMFUNC(strdup)(isc_mem_t *, const char *_ISC_MEM_FLARG);
|
||||
|
||||
+21
-6
@@ -1298,6 +1298,26 @@ isc__mem_allocate(isc_mem_t *ctx0, size_t size FLARG) {
|
||||
return (si);
|
||||
}
|
||||
|
||||
void *
|
||||
isc__mem_callocate(isc_mem_t *ctx0, size_t num, size_t size FLARG) {
|
||||
size_t numsize;
|
||||
|
||||
ISC_MUL_OVERFLOW(num, size, &numsize);
|
||||
void *ptr = isc__mem_allocate(ctx0, numsize FLARG_PASS);
|
||||
memset(ptr, 0, numsize);
|
||||
return (ptr);
|
||||
}
|
||||
|
||||
void *
|
||||
isc__mem_cget(isc_mem_t *ctx0, size_t num, size_t size FLARG) {
|
||||
size_t numsize;
|
||||
|
||||
ISC_MUL_OVERFLOW(num, size, &numsize);
|
||||
void *ptr = isc__mem_get(ctx0, numsize FLARG_PASS);
|
||||
memset(ptr, 0, numsize);
|
||||
return (ptr);
|
||||
}
|
||||
|
||||
void *
|
||||
isc__mem_reallocate(isc_mem_t *ctx0, void *ptr, size_t size FLARG) {
|
||||
REQUIRE(VALID_CONTEXT(ctx0));
|
||||
@@ -2534,12 +2554,7 @@ isc__malloc(size_t size FLARG) {
|
||||
|
||||
void *
|
||||
isc__calloc(size_t num, size_t size FLARG) {
|
||||
size_t numsize;
|
||||
|
||||
ISC_MUL_OVERFLOW(num, size, &numsize);
|
||||
void *ptr = isc__mem_allocate(isc__mem_mctx, numsize FLARG_PASS);
|
||||
memset(ptr, 0, numsize);
|
||||
return (ptr);
|
||||
return (isc__mem_callocate(isc__mem_mctx, num, size FLARG_PASS));
|
||||
}
|
||||
|
||||
void *
|
||||
|
||||
Reference in New Issue
Block a user