2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 14:35:26 +00:00

185. [bug] Fixed up handling of ISC_MEMCLUSTER_LEGACY. Several

public functions did not have an isc__ prefix, and
                        referred to functions that had previously been
                        renamed.

 184.   [cleanup]       Variables/functions which began with two leading
                        underscores were made to conform to the ANSI/ISO

function declaration and comment reformatting in accordance with coding
style document.

check_overrun conditionally compiled based on ISC_MEM_FILL and
ISC_MEM_CHECKOVERRUN to avoid compiler warnings about being defined
but not used if one of those two CPP symbols is not defined.
This commit is contained in:
David Lawrence
2000-05-16 05:17:31 +00:00
parent a120694df8
commit 6d8cdbaff4
2 changed files with 77 additions and 77 deletions

View File

@@ -95,25 +95,27 @@ isc_result_t isc_mem_restore(isc_mem_t *);
* Legacy. * Legacy.
*/ */
#define meminit __meminit #define meminit isc__legacy_meminit
#define mem_default_context __mem_default_context #define mem_default_context isc__legacy_mem_default_context
#ifdef MEMCLUSTER_DEBUG #ifdef MEMCLUSTER_DEBUG
#define memget(s) __memget_debug(s, __FILE__, __LINE__) #define memget(s) isc__legacy_memget_debug(s, __FILE__, __LINE__)
#define memput(p, s) __memput_debug(p, s, __FILE__, __LINE__) #define memput(p, s) isc__legacy_memput_debug(p, s, \
__FILE__, __LINE__)
#else #else
#define memget __memget #define memget isc__legacy_memget
#define memput __memput #define memput isc__legacy_memput
#endif #endif
#define memvalid __memvalid #define memvalid isc__legacy_memvalid
#define memstats __memstats #define memstats isc__legacy_memstats
int meminit(size_t, size_t); int meminit(size_t, size_t);
isc_mem_t * mem_default_context(void); isc_mem_t * mem_default_context(void);
void * __memget(size_t); void * isc__legacy_memget(size_t);
void __memput(void *, size_t); void isc__legacy_memput(void *, size_t);
void * __memget_debug(size_t, const char *, int); void * isc__legacy_memget_debug(size_t, const char *,
void __memput_debug(void *, size_t, const char *, int);
int); void isc__legacy_memput_debug(void *, size_t,
const char *, int);
int memvalid(void *); int memvalid(void *);
void memstats(FILE *); void memstats(FILE *);

View File

@@ -459,8 +459,7 @@ more_basic_blocks(isc_mem_t *ctx) {
} }
void * void *
isc__mem_get(isc_mem_t *ctx, size_t size) isc__mem_get(isc_mem_t *ctx, size_t size) {
{
void *ret; void *ret;
REQUIRE(VALID_CONTEXT(ctx)); REQUIRE(VALID_CONTEXT(ctx));
@@ -472,6 +471,7 @@ isc__mem_get(isc_mem_t *ctx, size_t size)
return (ret); return (ret);
} }
#if ISC_MEM_FILL != 0 && ISC_MEM_CHECKOVERRUN != 0
static inline void static inline void
check_overrun(void *mem, size_t size, size_t new_size) { check_overrun(void *mem, size_t size, size_t new_size) {
unsigned char *cp; unsigned char *cp;
@@ -484,6 +484,7 @@ check_overrun(void *mem, size_t size, size_t new_size) {
size++; size++;
} }
} }
#endif
static inline void static inline void
split(isc_mem_t *ctx, size_t size, size_t new_size) { split(isc_mem_t *ctx, size_t size, size_t new_size) {
@@ -606,13 +607,14 @@ more_frags(isc_mem_t *ctx, size_t new_size) {
} }
static inline void * static inline void *
mem_getunlocked(isc_mem_t *ctx, size_t size) mem_getunlocked(isc_mem_t *ctx, size_t size) {
{
size_t new_size = quantize(size); size_t new_size = quantize(size);
void *ret; void *ret;
if (size >= ctx->max_size || new_size >= ctx->max_size) { if (size >= ctx->max_size || new_size >= ctx->max_size) {
/* memget() was called on something beyond our upper limit. */ /*
* memget() was called on something beyond our upper limit.
*/
if (ctx->quota != 0 && ctx->total + size > ctx->quota) { if (ctx->quota != 0 && ctx->total + size > ctx->quota) {
ret = NULL; ret = NULL;
goto done; goto done;
@@ -669,8 +671,7 @@ mem_getunlocked(isc_mem_t *ctx, size_t size)
} }
void void
isc__mem_put(isc_mem_t *ctx, void *mem, size_t size) isc__mem_put(isc_mem_t *ctx, void *mem, size_t size) {
{
REQUIRE(VALID_CONTEXT(ctx)); REQUIRE(VALID_CONTEXT(ctx));
LOCK(&ctx->lock); LOCK(&ctx->lock);
@@ -679,12 +680,13 @@ isc__mem_put(isc_mem_t *ctx, void *mem, size_t size)
} }
static inline void static inline void
mem_putunlocked(isc_mem_t *ctx, void *mem, size_t size) mem_putunlocked(isc_mem_t *ctx, void *mem, size_t size) {
{
size_t new_size = quantize(size); size_t new_size = quantize(size);
if (size == ctx->max_size || new_size >= ctx->max_size) { if (size == ctx->max_size || new_size >= ctx->max_size) {
/* memput() called on something beyond our upper limit */ /*
* memput() called on something beyond our upper limit.
*/
#if ISC_MEM_FILL #if ISC_MEM_FILL
memset(mem, 0xde, size); /* Mnemonic for "dead". */ memset(mem, 0xde, size); /* Mnemonic for "dead". */
#endif #endif
@@ -704,7 +706,9 @@ mem_putunlocked(isc_mem_t *ctx, void *mem, size_t size)
memset(mem, 0xde, new_size); /* Mnemonic for "dead". */ memset(mem, 0xde, new_size); /* Mnemonic for "dead". */
#endif #endif
/* The free list uses the "rounded-up" size "new_size": */ /*
* The free list uses the "rounded-up" size "new_size".
*/
((element *)mem)->next = ctx->freelists[new_size]; ((element *)mem)->next = ctx->freelists[new_size];
ctx->freelists[new_size] = (element *)mem; ctx->freelists[new_size] = (element *)mem;
@@ -985,7 +989,9 @@ static isc_mem_t *default_context = NULL;
int int
meminit(size_t init_max_size, size_t target_size) { meminit(size_t init_max_size, size_t target_size) {
/* need default_context lock here */ /*
* Need default_context lock here.
*/
if (default_context != NULL) if (default_context != NULL)
return (-1); return (-1);
return (isc_mem_create(init_max_size, target_size, &default_context)); return (isc_mem_create(init_max_size, target_size, &default_context));
@@ -993,55 +999,65 @@ meminit(size_t init_max_size, size_t target_size) {
isc_mem_t * isc_mem_t *
mem_default_context(void) { mem_default_context(void) {
/* need default_context lock here */ /*
* Need default_context lock here.
*/
if (default_context == NULL && meminit(0, 0) == -1) if (default_context == NULL && meminit(0, 0) == -1)
return (NULL); return (NULL);
return (default_context); return (default_context);
} }
void * void *
__memget(size_t size) { isc__legacy_memget(size_t size) {
/* need default_context lock here */ /*
* Need default_context lock here.
*/
if (default_context == NULL && meminit(0, 0) == -1) if (default_context == NULL && meminit(0, 0) == -1)
return (NULL); return (NULL);
return (__mem_get(default_context, size)); return (isc__mem_get(default_context, size));
} }
void void
__memput(void *mem, size_t size) { isc__legacy_memput(void *mem, size_t size) {
/* need default_context lock here */ /*
* Need default_context lock here.
*/
REQUIRE(default_context != NULL); REQUIRE(default_context != NULL);
__mem_put(default_context, mem, size); isc__mem_put(default_context, mem, size);
} }
void * void *
__memget_debug(size_t size, const char *file, int line) { isc__legacy_memget_debug(size_t size, const char *file, int line) {
void *ptr; void *ptr;
ptr = __memget(size); ptr = isc__legacy_memget(size);
fprintf(stderr, "%s:%d: memget(%lu) -> %p\n", file, line, fprintf(stderr, "%s:%d: memget(%lu) -> %p\n", file, line,
(unsigned long)size, ptr); (unsigned long)size, ptr);
return (ptr); return (ptr);
} }
void void
__memput_debug(void *ptr, size_t size, const char *file, int line) { isc__legacy_memput_debug(void *ptr, size_t size, const char *file, int line) {
fprintf(stderr, "%s:%d: memput(%p, %lu)\n", file, line, fprintf(stderr, "%s:%d: memput(%p, %lu)\n", file, line,
ptr, (unsigned long)size); ptr, (unsigned long)size);
__memput(ptr, size); isc__legacy_memput(ptr, size);
} }
int int
memvalid(void *ptr) { memvalid(void *ptr) {
/* need default_context lock here */ /*
* Need default_context lock here.
*/
REQUIRE(default_context != NULL); REQUIRE(default_context != NULL);
return (mem_valid(default_context, ptr)); return (isc_mem_valid(default_context, ptr));
} }
void void
memstats(FILE *out) { memstats(FILE *out) {
/* need default_context lock here */ /*
* Need default_context lock here.
*/
REQUIRE(default_context != NULL); REQUIRE(default_context != NULL);
mem_stats(default_context, out); isc_mem_stats(default_context, out);
} }
#endif /* ISC_MEMCLUSTER_LEGACY */ #endif /* ISC_MEMCLUSTER_LEGACY */
@@ -1058,8 +1074,7 @@ memstats(FILE *out) {
* will be returned to the mctx. * will be returned to the mctx.
*/ */
static void static void
mempool_release(isc_mempool_t *mpctx, unsigned int n) mempool_release(isc_mempool_t *mpctx, unsigned int n) {
{
isc_mem_t *mctx; isc_mem_t *mctx;
element *item; element *item;
element *next; element *next;
@@ -1098,8 +1113,7 @@ mempool_release(isc_mempool_t *mpctx, unsigned int n)
* context must be locked, and the pool if needed. * context must be locked, and the pool if needed.
*/ */
static void static void
mempool_releaseall(isc_mempool_t *mpctx) mempool_releaseall(isc_mempool_t *mpctx) {
{
isc_mem_t *mctx; isc_mem_t *mctx;
element *item; element *item;
element *next; element *next;
@@ -1122,8 +1136,7 @@ mempool_releaseall(isc_mempool_t *mpctx)
} }
isc_result_t isc_result_t
isc_mempool_create(isc_mem_t *mctx, size_t size, isc_mempool_t **mpctxp) isc_mempool_create(isc_mem_t *mctx, size_t size, isc_mempool_t **mpctxp) {
{
isc_mempool_t *mpctx; isc_mempool_t *mpctx;
REQUIRE(VALID_CONTEXT(mctx)); REQUIRE(VALID_CONTEXT(mctx));
@@ -1167,8 +1180,7 @@ isc_mempool_create(isc_mem_t *mctx, size_t size, isc_mempool_t **mpctxp)
} }
void void
isc_mempool_setname(isc_mempool_t *mpctx, char *name) isc_mempool_setname(isc_mempool_t *mpctx, char *name) {
{
REQUIRE(name != NULL); REQUIRE(name != NULL);
#if ISC_MEMPOOL_NAMES #if ISC_MEMPOOL_NAMES
@@ -1187,8 +1199,7 @@ isc_mempool_setname(isc_mempool_t *mpctx, char *name)
} }
void void
isc_mempool_destroy(isc_mempool_t **mpctxp) isc_mempool_destroy(isc_mempool_t **mpctxp) {
{
isc_mempool_t *mpctx; isc_mempool_t *mpctx;
isc_mem_t *mctx; isc_mem_t *mctx;
isc_mutex_t *lock; isc_mutex_t *lock;
@@ -1230,8 +1241,7 @@ isc_mempool_destroy(isc_mempool_t **mpctxp)
} }
void void
isc_mempool_associatelock(isc_mempool_t *mpctx, isc_mutex_t *lock) isc_mempool_associatelock(isc_mempool_t *mpctx, isc_mutex_t *lock) {
{
REQUIRE(VALID_MEMPOOL(mpctx)); REQUIRE(VALID_MEMPOOL(mpctx));
REQUIRE(mpctx->lock == NULL); REQUIRE(mpctx->lock == NULL);
REQUIRE(lock != NULL); REQUIRE(lock != NULL);
@@ -1240,8 +1250,7 @@ isc_mempool_associatelock(isc_mempool_t *mpctx, isc_mutex_t *lock)
} }
void * void *
isc__mempool_get(isc_mempool_t *mpctx) isc__mempool_get(isc_mempool_t *mpctx) {
{
element *item; element *item;
isc_mem_t *mctx; isc_mem_t *mctx;
unsigned int i; unsigned int i;
@@ -1309,8 +1318,7 @@ isc__mempool_get(isc_mempool_t *mpctx)
} }
void void
isc__mempool_put(isc_mempool_t *mpctx, void *mem) isc__mempool_put(isc_mempool_t *mpctx, void *mem) {
{
isc_mem_t *mctx; isc_mem_t *mctx;
element *item; element *item;
@@ -1348,9 +1356,7 @@ isc__mempool_put(isc_mempool_t *mpctx, void *mem)
} }
void * void *
isc__mempool_getdebug(isc_mempool_t *mpctx, isc__mempool_getdebug(isc_mempool_t *mpctx, const char *file, int line) {
const char *file, int line)
{
void *ptr; void *ptr;
ptr = isc__mempool_get(mpctx); ptr = isc__mempool_get(mpctx);
@@ -1361,8 +1367,8 @@ isc__mempool_getdebug(isc_mempool_t *mpctx,
} }
void void
isc__mempool_putdebug(isc_mempool_t *mpctx, void *ptr, isc__mempool_putdebug(isc_mempool_t *mpctx, void *ptr, const char *file,
const char *file, int line) int line)
{ {
fprintf(stderr, "%s:%d: mempool_put(%p, %p)\n", file, line, fprintf(stderr, "%s:%d: mempool_put(%p, %p)\n", file, line,
mpctx, ptr); mpctx, ptr);
@@ -1374,8 +1380,7 @@ isc__mempool_putdebug(isc_mempool_t *mpctx, void *ptr,
*/ */
void void
isc_mempool_setfreemax(isc_mempool_t *mpctx, unsigned int limit) isc_mempool_setfreemax(isc_mempool_t *mpctx, unsigned int limit) {
{
REQUIRE(VALID_MEMPOOL(mpctx)); REQUIRE(VALID_MEMPOOL(mpctx));
if (mpctx->lock != NULL) if (mpctx->lock != NULL)
@@ -1388,8 +1393,7 @@ isc_mempool_setfreemax(isc_mempool_t *mpctx, unsigned int limit)
} }
unsigned int unsigned int
isc_mempool_getfreemax(isc_mempool_t *mpctx) isc_mempool_getfreemax(isc_mempool_t *mpctx) {
{
unsigned int freemax; unsigned int freemax;
REQUIRE(VALID_MEMPOOL(mpctx)); REQUIRE(VALID_MEMPOOL(mpctx));
@@ -1406,8 +1410,7 @@ isc_mempool_getfreemax(isc_mempool_t *mpctx)
} }
unsigned int unsigned int
isc_mempool_getfreecount(isc_mempool_t *mpctx) isc_mempool_getfreecount(isc_mempool_t *mpctx) {
{
unsigned int freecount; unsigned int freecount;
REQUIRE(VALID_MEMPOOL(mpctx)); REQUIRE(VALID_MEMPOOL(mpctx));
@@ -1424,8 +1427,7 @@ isc_mempool_getfreecount(isc_mempool_t *mpctx)
} }
void void
isc_mempool_setmaxalloc(isc_mempool_t *mpctx, unsigned int limit) isc_mempool_setmaxalloc(isc_mempool_t *mpctx, unsigned int limit) {
{
REQUIRE(limit > 0); REQUIRE(limit > 0);
REQUIRE(VALID_MEMPOOL(mpctx)); REQUIRE(VALID_MEMPOOL(mpctx));
@@ -1440,8 +1442,7 @@ isc_mempool_setmaxalloc(isc_mempool_t *mpctx, unsigned int limit)
} }
unsigned int unsigned int
isc_mempool_getmaxalloc(isc_mempool_t *mpctx) isc_mempool_getmaxalloc(isc_mempool_t *mpctx) {
{
unsigned int maxalloc; unsigned int maxalloc;
REQUIRE(VALID_MEMPOOL(mpctx)); REQUIRE(VALID_MEMPOOL(mpctx));
@@ -1458,8 +1459,7 @@ isc_mempool_getmaxalloc(isc_mempool_t *mpctx)
} }
unsigned int unsigned int
isc_mempool_getallocated(isc_mempool_t *mpctx) isc_mempool_getallocated(isc_mempool_t *mpctx) {
{
unsigned int allocated; unsigned int allocated;
REQUIRE(VALID_MEMPOOL(mpctx)); REQUIRE(VALID_MEMPOOL(mpctx));
@@ -1476,8 +1476,7 @@ isc_mempool_getallocated(isc_mempool_t *mpctx)
} }
void void
isc_mempool_setfillcount(isc_mempool_t *mpctx, unsigned int limit) isc_mempool_setfillcount(isc_mempool_t *mpctx, unsigned int limit) {
{
REQUIRE(limit > 0); REQUIRE(limit > 0);
REQUIRE(VALID_MEMPOOL(mpctx)); REQUIRE(VALID_MEMPOOL(mpctx));
@@ -1491,8 +1490,7 @@ isc_mempool_setfillcount(isc_mempool_t *mpctx, unsigned int limit)
} }
unsigned int unsigned int
isc_mempool_getfillcount(isc_mempool_t *mpctx) isc_mempool_getfillcount(isc_mempool_t *mpctx) {
{
unsigned int fillcount; unsigned int fillcount;
REQUIRE(VALID_MEMPOOL(mpctx)); REQUIRE(VALID_MEMPOOL(mpctx));