From cb605a619b96b9261994f28f4af0f3c7e77f0892 Mon Sep 17 00:00:00 2001 From: Matthew Sotoudeh Date: Thu, 16 May 2024 15:46:02 -0700 Subject: test harness includes move_buddy --- magic_buddy/magic_buddy.c | 3 ++- magic_buddy/magic_buddy.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'magic_buddy') diff --git a/magic_buddy/magic_buddy.c b/magic_buddy/magic_buddy.c index c6283d8..9deaa8f 100644 --- a/magic_buddy/magic_buddy.c +++ b/magic_buddy/magic_buddy.c @@ -197,7 +197,7 @@ static void *_naive_reallocate(void *old, size_t old_size, size_t new_size, return new; } -void *reallocate(void *old, size_t old_size, size_t new_size, +void *reallocate(void *old, size_t new_size, size_t old_size, struct buddy *state) { if (new_size == 0) return liberate(old, old_size, state), (void*)0; @@ -316,6 +316,7 @@ int shrink_buddy(size_t new_size, struct buddy *state) { } void move_buddy(struct buddy *new_state, struct buddy *old_state) { + if (new_state == old_state) return; memcpy(new_state, old_state, sizeof(struct buddy)); for (size_t i = 0; i < ADDRESS_BITS; i++) { if (!new_state->avail[i]) continue; diff --git a/magic_buddy/magic_buddy.h b/magic_buddy/magic_buddy.h index c8778d6..a25ceb7 100644 --- a/magic_buddy/magic_buddy.h +++ b/magic_buddy/magic_buddy.h @@ -30,7 +30,7 @@ void debug_buddy(struct buddy *state); // Simulates @new = allocate, memcpy(@new, @old), free(@old), with some // optimizations for cases where the reallocation can be done in place. -void *reallocate(void *old, size_t old_size, size_t new_size, +void *reallocate(void *old, size_t new_size, size_t old_size, struct buddy *state); // Attempts to reserve a range [@start,@start+@size). -- cgit v1.2.3