diff --git a/libs/libks/src/include/ks_pool.h b/libs/libks/src/include/ks_pool.h index efa2677e51..083d152ac8 100644 --- a/libs/libks/src/include/ks_pool.h +++ b/libs/libks/src/include/ks_pool.h @@ -34,8 +34,9 @@ KS_BEGIN_EXTERN_C typedef enum { KS_POOL_FLAG_DEFAULT = 0, - KS_POOL_FLAG_BEST_FIT = (1 << 0), + KS_POOL_FLAG_NO_ASSERT = (1 << 1), + KS_POOL_FLAG_NO_ZERO = (1 << 2), /* * Choose a best fit algorithm not first fit. This takes more CPU * time but will result in a tighter heap. diff --git a/libs/libks/src/ks_pool.c b/libs/libks/src/ks_pool.c index 2a6750e91d..92e2d827fe 100644 --- a/libs/libks/src/ks_pool.c +++ b/libs/libks/src/ks_pool.c @@ -3,7 +3,7 @@ * * Copyright 1996 by Gray Watson. * - * This file is part of the ks_mpool package. + * This file is part of the ks_pool package. * * Permission to use, copy, modify, and distribute this software for * any purpose and without fee is hereby granted, provided that the @@ -1465,6 +1465,12 @@ KS_DECLARE(void *) ks_pool_alloc_ex(ks_pool_t *mp_p, const unsigned long byte_si mp_p->mp_log_func(mp_p, KS_POOL_FUNC_ALLOC, byte_size, 0, addr, NULL, 0); } + ks_assert(addr || (mp_p->mp_flags & KS_POOL_FLAG_NO_ASSERT)); + + if (!(mp_p->mp_flags & KS_POOL_FLAG_NO_ZERO)) { + memset(addr, 0, byte_size); + } + return addr; } @@ -1554,6 +1560,12 @@ KS_DECLARE(void *) ks_pool_calloc_ex(ks_pool_t *mp_p, const unsigned long ele_n, mp_p->mp_log_func(mp_p, KS_POOL_FUNC_CALLOC, ele_size, ele_n, addr, NULL, 0); } + ks_assert(addr || (mp_p->mp_flags & KS_POOL_FLAG_NO_ASSERT)); + + if (!(mp_p->mp_flags & KS_POOL_FLAG_NO_ZERO)) { + memset(addr, 0, ele_n * ele_size); + } + return addr; } @@ -1785,6 +1797,8 @@ KS_DECLARE(void *) ks_pool_resize_ex(ks_pool_t *mp_p, void *old_addr, const unsi ks_mutex_unlock(mp_p->mutex); + ks_assert(new_addr || (mp_p->mp_flags & KS_POOL_FLAG_NO_ASSERT)); + return new_addr; }