Remove ISC_MEM_ZERO and isc_mem_*x() API
Use the new isc_mem_c*() calloc-like API for allocations that are zeroed. In turn, this also fixes couple of incorrect usage of the ISC_MEM_ZERO for structures that need to be zeroed explicitly. There are few places where isc_mem_cput() is used on structures with a flexible member (or similar).
This commit is contained in:
@@ -820,7 +820,7 @@ startup(void *arg) {
|
||||
uint32_t nloops = isc_loopmgr_nloops(loopmgr);
|
||||
size_t bytes = sizeof(struct bench_state) +
|
||||
sizeof(struct thread_args) * nloops;
|
||||
struct bench_state *bctx = isc_mem_getx(mctx, bytes, ISC_MEM_ZERO);
|
||||
struct bench_state *bctx = isc_mem_cget(mctx, 1, bytes);
|
||||
|
||||
*bctx = (struct bench_state){
|
||||
.loopmgr = loopmgr,
|
||||
@@ -871,10 +871,11 @@ setup_tickers(isc_mem_t *mctx, isc_loopmgr_t *loopmgr) {
|
||||
uint32_t nloops = isc_loopmgr_nloops(loopmgr);
|
||||
for (uint32_t i = 0; i < nloops; i++) {
|
||||
isc_loop_t *loop = isc_loop_get(loopmgr, i);
|
||||
struct ticker *ticker = isc_mem_getx(mctx, sizeof(*ticker),
|
||||
ISC_MEM_ZERO);
|
||||
struct ticker *ticker = isc_mem_get(mctx, sizeof(*ticker));
|
||||
*ticker = (struct ticker){
|
||||
.loopmgr = loopmgr,
|
||||
};
|
||||
isc_mem_attach(mctx, &ticker->mctx);
|
||||
ticker->loopmgr = loopmgr;
|
||||
isc_loop_setup(loop, start_ticker, ticker);
|
||||
isc_loop_teardown(loop, stop_ticker, ticker);
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ ISC_RUN_TEST_IMPL(isc_mem_get) {
|
||||
}
|
||||
|
||||
/* zeroed memory system tests */
|
||||
ISC_RUN_TEST_IMPL(isc_mem_get_zero) {
|
||||
ISC_RUN_TEST_IMPL(isc_mem_cget_zero) {
|
||||
uint8_t *ptr;
|
||||
bool zeroed;
|
||||
uint8_t expected[4096] = { 0 };
|
||||
@@ -147,12 +147,12 @@ ISC_RUN_TEST_IMPL(isc_mem_get_zero) {
|
||||
return;
|
||||
}
|
||||
|
||||
ptr = isc_mem_getx(mctx, sizeof(expected), ISC_MEM_ZERO);
|
||||
ptr = isc_mem_cget(mctx, 1, sizeof(expected));
|
||||
assert_memory_equal(ptr, expected, sizeof(expected));
|
||||
isc_mem_put(mctx, ptr, sizeof(expected));
|
||||
}
|
||||
|
||||
ISC_RUN_TEST_IMPL(isc_mem_allocate_zero) {
|
||||
ISC_RUN_TEST_IMPL(isc_mem_callocate_zero) {
|
||||
uint8_t *ptr;
|
||||
bool zeroed;
|
||||
uint8_t expected[4096] = { 0 };
|
||||
@@ -172,7 +172,7 @@ ISC_RUN_TEST_IMPL(isc_mem_allocate_zero) {
|
||||
return;
|
||||
}
|
||||
|
||||
ptr = isc_mem_allocatex(mctx, sizeof(expected), ISC_MEM_ZERO);
|
||||
ptr = isc_mem_callocate(mctx, 1, sizeof(expected));
|
||||
assert_memory_equal(ptr, expected, sizeof(expected));
|
||||
isc_mem_free(mctx, ptr);
|
||||
}
|
||||
@@ -251,26 +251,26 @@ ISC_RUN_TEST_IMPL(isc_mem_reget) {
|
||||
isc_mem_put(mctx, data, REGET_SHRINK_SIZE);
|
||||
}
|
||||
|
||||
ISC_RUN_TEST_IMPL(isc_mem_reallocatex) {
|
||||
ISC_RUN_TEST_IMPL(isc_mem_reallocate) {
|
||||
uint8_t *data = NULL;
|
||||
|
||||
/* test that we can reallocate NULL */
|
||||
data = isc_mem_reallocatex(mctx, NULL, REGET_INIT_SIZE, 0);
|
||||
data = isc_mem_reallocate(mctx, NULL, REGET_INIT_SIZE);
|
||||
assert_non_null(data);
|
||||
isc_mem_free(mctx, data);
|
||||
|
||||
/* test that we can re-get a zero-length allocation */
|
||||
data = isc_mem_allocatex(mctx, 0, 0);
|
||||
data = isc_mem_allocate(mctx, 0);
|
||||
assert_non_null(data);
|
||||
|
||||
data = isc_mem_reallocatex(mctx, data, REGET_INIT_SIZE, 0);
|
||||
data = isc_mem_reallocate(mctx, data, REGET_INIT_SIZE);
|
||||
assert_non_null(data);
|
||||
|
||||
for (size_t i = 0; i < REGET_INIT_SIZE; i++) {
|
||||
data[i] = i % UINT8_MAX;
|
||||
}
|
||||
|
||||
data = isc_mem_reallocatex(mctx, data, REGET_GROW_SIZE, 0);
|
||||
data = isc_mem_reallocate(mctx, data, REGET_GROW_SIZE);
|
||||
assert_non_null(data);
|
||||
|
||||
for (size_t i = 0; i < REGET_INIT_SIZE; i++) {
|
||||
@@ -281,7 +281,7 @@ ISC_RUN_TEST_IMPL(isc_mem_reallocatex) {
|
||||
data[i - 1] = i % UINT8_MAX;
|
||||
}
|
||||
|
||||
data = isc_mem_reallocatex(mctx, data, REGET_SHRINK_SIZE, 0);
|
||||
data = isc_mem_reallocate(mctx, data, REGET_SHRINK_SIZE);
|
||||
assert_non_null(data);
|
||||
|
||||
for (size_t i = REGET_SHRINK_SIZE; i > 0; i--) {
|
||||
@@ -480,12 +480,12 @@ ISC_RUN_TEST_IMPL(isc_mem_benchmark) {
|
||||
ISC_TEST_LIST_START
|
||||
|
||||
ISC_TEST_ENTRY(isc_mem_get)
|
||||
ISC_TEST_ENTRY(isc_mem_get_zero)
|
||||
ISC_TEST_ENTRY(isc_mem_allocate_zero)
|
||||
ISC_TEST_ENTRY(isc_mem_cget_zero)
|
||||
ISC_TEST_ENTRY(isc_mem_callocate_zero)
|
||||
ISC_TEST_ENTRY(isc_mem_inuse)
|
||||
ISC_TEST_ENTRY(isc_mem_zeroget)
|
||||
ISC_TEST_ENTRY(isc_mem_reget)
|
||||
ISC_TEST_ENTRY(isc_mem_reallocatex)
|
||||
ISC_TEST_ENTRY(isc_mem_reallocate)
|
||||
|
||||
#if ISC_MEM_TRACKLINES
|
||||
ISC_TEST_ENTRY(isc_mem_noflags)
|
||||
|
||||
@@ -105,7 +105,8 @@ ISC_LOOP_TEARDOWN_IMPL(ratelimiter_enqueue) { assert_int_equal(ticks, 1); }
|
||||
|
||||
ISC_LOOP_TEST_SETUP_TEARDOWN_IMPL(ratelimiter_enqueue) {
|
||||
isc_result_t result;
|
||||
rlstat_t *rlstat = isc_mem_getx(mctx, sizeof(*rlstat), ISC_MEM_ZERO);
|
||||
rlstat_t *rlstat = isc_mem_get(mctx, sizeof(*rlstat));
|
||||
*rlstat = (rlstat_t){ 0 };
|
||||
|
||||
result = isc_ratelimiter_enqueue(rl, mainloop, tick, rlstat,
|
||||
&rlstat->event);
|
||||
@@ -123,8 +124,9 @@ ISC_LOOP_TEARDOWN_IMPL(ratelimiter_enqueue_shutdown) {
|
||||
}
|
||||
|
||||
ISC_LOOP_TEST_SETUP_TEARDOWN_IMPL(ratelimiter_enqueue_shutdown) {
|
||||
rlstat_t *rlstat = isc_mem_getx(mctx, sizeof(*rlstat), ISC_MEM_ZERO);
|
||||
isc_rlevent_t *event = NULL;
|
||||
rlstat_t *rlstat = isc_mem_get(mctx, sizeof(*rlstat));
|
||||
*rlstat = (rlstat_t){ 0 };
|
||||
|
||||
expect_assert_failure(
|
||||
isc_ratelimiter_enqueue(NULL, mainloop, tick, NULL, &event));
|
||||
@@ -156,8 +158,9 @@ ISC_LOOP_TEARDOWN_IMPL(ratelimiter_dequeue) { /* */
|
||||
}
|
||||
|
||||
ISC_LOOP_TEST_SETUP_TEARDOWN_IMPL(ratelimiter_dequeue) {
|
||||
rlstat_t *rlstat = isc_mem_getx(mctx, sizeof(*rlstat), ISC_MEM_ZERO);
|
||||
isc_rlevent_t *fake = isc_mem_get(mctx, sizeof(*fake));
|
||||
rlstat_t *rlstat = isc_mem_get(mctx, sizeof(*rlstat));
|
||||
*rlstat = (rlstat_t){ 0 };
|
||||
|
||||
assert_int_equal(isc_ratelimiter_enqueue(rl, mainloop, tick, rlstat,
|
||||
&rlstat->event),
|
||||
@@ -225,12 +228,14 @@ ISC_LOOP_TEST_SETUP_TEARDOWN_IMPL(ratelimiter_pertick_interval) {
|
||||
isc_ratelimiter_setpertic(rl, 1);
|
||||
isc_ratelimiter_setpushpop(rl, false);
|
||||
|
||||
rlstat = isc_mem_getx(mctx, sizeof(*rlstat), ISC_MEM_ZERO);
|
||||
rlstat = isc_mem_get(mctx, sizeof(*rlstat));
|
||||
*rlstat = (rlstat_t){ 0 };
|
||||
assert_int_equal(isc_ratelimiter_enqueue(rl, mainloop, tock, rlstat,
|
||||
&rlstat->event),
|
||||
ISC_R_SUCCESS);
|
||||
|
||||
rlstat = isc_mem_getx(mctx, sizeof(*rlstat), ISC_MEM_ZERO);
|
||||
rlstat = isc_mem_get(mctx, sizeof(*rlstat));
|
||||
*rlstat = (rlstat_t){ 0 };
|
||||
assert_int_equal(isc_ratelimiter_enqueue(rl, mainloop, tick, rlstat,
|
||||
&rlstat->event),
|
||||
ISC_R_SUCCESS);
|
||||
@@ -258,12 +263,14 @@ ISC_LOOP_TEST_SETUP_TEARDOWN_IMPL(ratelimiter_pushpop) {
|
||||
isc_ratelimiter_setpertic(rl, 2);
|
||||
isc_ratelimiter_setpushpop(rl, true);
|
||||
|
||||
rlstat = isc_mem_getx(mctx, sizeof(*rlstat), ISC_MEM_ZERO);
|
||||
rlstat = isc_mem_get(mctx, sizeof(*rlstat));
|
||||
*rlstat = (rlstat_t){ 0 };
|
||||
assert_int_equal(isc_ratelimiter_enqueue(rl, mainloop, tock, rlstat,
|
||||
&rlstat->event),
|
||||
ISC_R_SUCCESS);
|
||||
|
||||
rlstat = isc_mem_getx(mctx, sizeof(*rlstat), ISC_MEM_ZERO);
|
||||
rlstat = isc_mem_get(mctx, sizeof(*rlstat));
|
||||
*rlstat = (rlstat_t){ 0 };
|
||||
assert_int_equal(isc_ratelimiter_enqueue(rl, mainloop, tick, rlstat,
|
||||
&rlstat->event),
|
||||
ISC_R_SUCCESS);
|
||||
|
||||
Reference in New Issue
Block a user