Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use explicit designators to init struct to improve readability #247

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions h_malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ static inline struct size_info get_size_info(size_t size) {
}
// size <= 64 is needed for correctness and raising it to size <= 128 is an optimization
if (size <= 128) {
return (struct size_info){align(size, 16), ((size - 1) >> 4) + 1};
return (struct size_info){.size = align(size, 16), .class = ((size - 1) >> 4) + 1};
}

static const size_t initial_spacing_multiplier = 5;
Expand All @@ -244,15 +244,15 @@ static inline struct size_info get_size_info(size_t size) {
size_t real_size = align(size, spacing_class);
size_t spacing_class_index = (real_size >> spacing_class_shift) - initial_spacing_multiplier;
size_t index = (spacing_class_shift - 4) * 4 + special_small_sizes + spacing_class_index;
return (struct size_info){real_size, index};
return (struct size_info){.size = real_size, .class = index};
}

// alignment must be a power of 2 <= PAGE_SIZE since slabs are only page aligned
static inline struct size_info get_size_info_align(size_t size, size_t alignment) {
for (unsigned class = 1; class < N_SIZE_CLASSES; class++) {
size_t real_size = size_classes[class];
if (size <= real_size && !(real_size & (alignment - 1))) {
return (struct size_info){real_size, class};
return (struct size_info){.size = real_size, class};
}
}
fatal_error("invalid size for slabs");
Expand Down Expand Up @@ -758,7 +758,7 @@ static struct slab_size_class_info slab_size_class(const void *p) {
arena = offset / ARENA_SIZE;
offset -= arena * ARENA_SIZE;
}
return (struct slab_size_class_info){arena, offset / REAL_CLASS_REGION_SIZE};
return (struct slab_size_class_info){arena, .class = offset / REAL_CLASS_REGION_SIZE};
}

static size_t slab_usable_size(const void *p) {
Expand Down Expand Up @@ -1000,8 +1000,7 @@ static void regions_quarantine_deallocate_pages(void *p, size_t size, size_t gua
memory_set_name(p, size, "malloc large quarantine");
}

struct quarantine_info target =
(struct quarantine_info){(char *)p - guard_size, size + guard_size * 2};
struct quarantine_info target = {.p = (char *)p - guard_size, .size = size + guard_size * 2};

struct region_allocator *ra = ro.region_allocator;

Expand Down