Skip to content

Commit 09e1c03

Browse files
authored
Rename functions to avoid shadowing default c++ constructor for structs
1 parent b19cb73 commit 09e1c03

File tree

2 files changed

+42
-42
lines changed

2 files changed

+42
-42
lines changed

buddy_alloc.h

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ static struct buddy_tree_pos buddy_tree_right_adjacent(struct buddy_tree_pos pos
354354
static size_t buddy_tree_index(struct buddy_tree_pos pos);
355355

356356
/* Return the interval of the deepest positions spanning the indicated position */
357-
static struct buddy_tree_interval buddy_tree_interval(struct buddy_tree *t, struct buddy_tree_pos pos);
357+
static struct buddy_tree_interval to_buddy_tree_interval(struct buddy_tree *t, struct buddy_tree_pos pos);
358358

359359
/* Checks if one interval contains another */
360360
static bool buddy_tree_interval_contains(struct buddy_tree_interval outer,
@@ -430,7 +430,7 @@ struct bitset_range {
430430
uint8_t to_index;
431431
};
432432

433-
static inline struct bitset_range bitset_range(size_t from_pos, size_t to_pos);
433+
static inline struct bitset_range to_bitset_range(size_t from_pos, size_t to_pos);
434434

435435
static void bitset_set_range(unsigned char *bitset, struct bitset_range range);
436436

@@ -515,7 +515,7 @@ static unsigned char *address_for_position(struct buddy *buddy, struct buddy_tre
515515
static struct buddy_tree_pos position_for_address(struct buddy *buddy, const unsigned char *addr);
516516
static unsigned char *buddy_main(struct buddy *buddy);
517517
static unsigned int buddy_relative_mode(struct buddy *buddy);
518-
static struct buddy_tree *buddy_tree(struct buddy *buddy);
518+
static struct buddy_tree *buddy_tree_for(struct buddy *buddy);
519519
static size_t buddy_effective_memory_size(struct buddy *buddy);
520520
static size_t buddy_virtual_slots(struct buddy *buddy);
521521
static void buddy_toggle_virtual_slots(struct buddy *buddy, unsigned int state);
@@ -664,7 +664,7 @@ static struct buddy *buddy_resize_standard(struct buddy *buddy, size_t new_memor
664664

665665
/* Calculate new tree order and resize it */
666666
new_buddy_tree_order = buddy_tree_order_for_memory(new_memory_size, buddy->alignment);
667-
buddy_tree_resize(buddy_tree(buddy), (uint8_t) new_buddy_tree_order);
667+
buddy_tree_resize(buddy_tree_for(buddy), (uint8_t) new_buddy_tree_order);
668668

669669
/* Store the new memory size and reconstruct any virtual slots */
670670
buddy->memory_size = new_memory_size;
@@ -726,7 +726,7 @@ bool buddy_is_full(struct buddy *buddy) {
726726
if (buddy == NULL) {
727727
return false;
728728
}
729-
tree = buddy_tree(buddy);
729+
tree = buddy_tree_for(buddy);
730730
pos = buddy_tree_root();
731731
return buddy_tree_status(tree, pos) == buddy_tree_order(tree);
732732
}
@@ -740,7 +740,7 @@ size_t buddy_arena_size(struct buddy *buddy) {
740740

741741
size_t buddy_arena_free_size(struct buddy *buddy) {
742742
size_t result = 0;
743-
struct buddy_tree *tree = buddy_tree(buddy);
743+
struct buddy_tree *tree = buddy_tree_for(buddy);
744744
size_t tree_order = buddy_tree_order(tree);
745745

746746
struct buddy_tree_walk_state state = buddy_tree_walk_state_root();
@@ -792,7 +792,7 @@ void *buddy_malloc(struct buddy *buddy, size_t requested_size) {
792792
}
793793

794794
target_depth = depth_for_size(buddy, requested_size);
795-
tree = buddy_tree(buddy);
795+
tree = buddy_tree_for(buddy);
796796
pos = buddy_tree_find_free(tree, (uint8_t) target_depth);
797797

798798
if (! buddy_tree_valid(tree, pos)) {
@@ -854,7 +854,7 @@ void *buddy_realloc(struct buddy *buddy, void *ptr, size_t requested_size, bool
854854
}
855855

856856
/* Find the position tracking this address */
857-
tree = buddy_tree(buddy);
857+
tree = buddy_tree_for(buddy);
858858
origin = position_for_address(buddy, (unsigned char *) ptr);
859859
if (! buddy_tree_valid(tree, origin)) {
860860
return NULL;
@@ -922,7 +922,7 @@ void buddy_free(struct buddy *buddy, void *ptr) {
922922
}
923923

924924
/* Find the position tracking this address */
925-
tree = buddy_tree(buddy);
925+
tree = buddy_tree_for(buddy);
926926
pos = position_for_address(buddy, dst);
927927

928928
if (! buddy_tree_valid(tree, pos)) {
@@ -953,7 +953,7 @@ enum buddy_safe_free_status buddy_safe_free(struct buddy* buddy, void* ptr, size
953953
}
954954

955955
/* Find an allocated position tracking this address */
956-
tree = buddy_tree(buddy);
956+
tree = buddy_tree_for(buddy);
957957
pos = position_for_address(buddy, dst);
958958

959959
if (!buddy_tree_valid(tree, pos)) {
@@ -1002,7 +1002,7 @@ size_t buddy_alloc_size(struct buddy *buddy, void *ptr) {
10021002
}
10031003

10041004
/* Find an allocated position tracking this address */
1005-
tree = buddy_tree(buddy);
1005+
tree = buddy_tree_for(buddy);
10061006
pos = position_for_address(buddy, dst);
10071007

10081008
if (!buddy_tree_valid(tree, pos)) {
@@ -1039,7 +1039,7 @@ void *buddy_walk(struct buddy *buddy,
10391039
}
10401040
main = buddy_main(buddy);
10411041
effective_memory_size = buddy_effective_memory_size(buddy);
1042-
tree = buddy_tree(buddy);
1042+
tree = buddy_tree_for(buddy);
10431043
tree_order = buddy_tree_order(tree);
10441044

10451045
state = buddy_tree_walk_state_root();
@@ -1088,12 +1088,12 @@ unsigned char buddy_fragmentation(struct buddy *buddy) {
10881088
if (buddy == NULL) {
10891089
return 0;
10901090
}
1091-
return buddy_tree_fragmentation(buddy_tree(buddy));
1091+
return buddy_tree_fragmentation(buddy_tree_for(buddy));
10921092
}
10931093

10941094
#ifdef BUDDY_EXPERIMENTAL_CHANGE_TRACKING
10951095
void buddy_enable_change_tracking(struct buddy* buddy, void* context, void (*tracker) (void*, unsigned char*, size_t)) {
1096-
struct buddy_tree *t = buddy_tree(buddy);
1096+
struct buddy_tree *t = buddy_tree_for(buddy);
10971097
struct buddy_change_tracker *header = (struct buddy_change_tracker *) buddy_main(buddy);
10981098

10991099
/* Allocate memory for the change tracking header */
@@ -1127,7 +1127,7 @@ static inline size_t size_for_depth(struct buddy *buddy, size_t depth) {
11271127
return ceiling_power_of_two(buddy->memory_size) >> (depth-1);
11281128
}
11291129

1130-
static struct buddy_tree *buddy_tree(struct buddy *buddy) {
1130+
static struct buddy_tree *buddy_tree_for(struct buddy *buddy) {
11311131
return (struct buddy_tree*) ((unsigned char *)buddy + sizeof(*buddy));
11321132
}
11331133

@@ -1152,7 +1152,7 @@ static unsigned char *address_for_position(struct buddy *buddy, struct buddy_tre
11521152

11531153
static struct buddy_tree_pos deepest_position_for_offset(struct buddy *buddy, size_t offset) {
11541154
size_t index = offset / buddy->alignment;
1155-
struct buddy_tree_pos pos = buddy_tree_leftmost_child(buddy_tree(buddy));
1155+
struct buddy_tree_pos pos = buddy_tree_leftmost_child(buddy_tree_for(buddy));
11561156
pos.index += index;
11571157
return pos;
11581158
}
@@ -1170,7 +1170,7 @@ static struct buddy_tree_pos position_for_address(struct buddy *buddy, const uns
11701170
return INVALID_POS; /* invalid alignment */
11711171
}
11721172

1173-
tree = buddy_tree(buddy);
1173+
tree = buddy_tree_for(buddy);
11741174
pos = deepest_position_for_offset(buddy, offset);
11751175

11761176
/* Find the actual allocated position tracking this address */
@@ -1216,7 +1216,7 @@ static void buddy_toggle_virtual_slots(struct buddy *buddy, unsigned int state)
12161216
/* Node memory size is already aligned to buddy->alignment */
12171217
delta = effective_memory_size - memory_size;
12181218

1219-
tree = buddy_tree(buddy);
1219+
tree = buddy_tree_for(buddy);
12201220
pos = buddy_tree_right_child(buddy_tree_root());
12211221
while (delta) {
12221222
size_t current_pos_size = size_for_depth(buddy, buddy_tree_depth(pos));
@@ -1273,7 +1273,7 @@ static void buddy_toggle_range_reservation(struct buddy *buddy, void *ptr, size_
12731273
}
12741274

12751275
/* Find the deepest position tracking this address */
1276-
tree = buddy_tree(buddy);
1276+
tree = buddy_tree_for(buddy);
12771277
offset = (size_t) (dst - main);
12781278
pos = deepest_position_for_offset(buddy, offset);
12791279

@@ -1307,20 +1307,20 @@ static bool buddy_is_free(struct buddy *buddy, size_t from) {
13071307
to = effective_memory_size -
13081308
((virtual_slots ? (virtual_slots + 1) : 1) * buddy->alignment);
13091309

1310-
tree = buddy_tree(buddy);
1310+
tree = buddy_tree_for(buddy);
13111311

13121312
query_range.from = deepest_position_for_offset(buddy, from);
13131313
query_range.to = deepest_position_for_offset(buddy, to);
13141314

13151315
pos = deepest_position_for_offset(buddy, from);
13161316
while(buddy_tree_valid(tree, pos) && (pos.index < query_range.to.index)) {
1317-
struct buddy_tree_interval current_test_range = buddy_tree_interval(tree, pos);
1317+
struct buddy_tree_interval current_test_range = to_buddy_tree_interval(tree, pos);
13181318
struct buddy_tree_interval parent_test_range =
1319-
buddy_tree_interval(tree, buddy_tree_parent(pos));
1319+
to_buddy_tree_interval(tree, buddy_tree_parent(pos));
13201320
while(buddy_tree_interval_contains(query_range, parent_test_range)) {
13211321
pos = buddy_tree_parent(pos);
13221322
current_test_range = parent_test_range;
1323-
parent_test_range = buddy_tree_interval(tree, buddy_tree_parent(pos));
1323+
parent_test_range = to_buddy_tree_interval(tree, buddy_tree_parent(pos));
13241324
}
13251325
/* pos is now tracking an overlapping segment */
13261326
if (! buddy_tree_is_free(tree, pos)) {
@@ -1371,7 +1371,7 @@ void buddy_debug(struct buddy *buddy) {
13711371
BUDDY_PRINTF("\n");
13721372
BUDDY_PRINTF("virtual slots: %zu\n", buddy_virtual_slots(buddy));
13731373
BUDDY_PRINTF("allocator tree follows:\n");
1374-
buddy_tree_debug(buddy_tree(buddy), buddy_tree_root(), buddy_effective_memory_size(buddy));
1374+
buddy_tree_debug(buddy_tree_for(buddy), buddy_tree_root(), buddy_effective_memory_size(buddy));
13751375
}
13761376

13771377
/*
@@ -1522,8 +1522,8 @@ static void buddy_tree_grow(struct buddy_tree *t, uint8_t desired_order) {
15221522

15231523
/* Clear right section */
15241524
bitset_clear_range(buddy_tree_bits(t),
1525-
bitset_range(next_internal.bitset_location + (next_internal.local_offset * node_count),
1526-
next_internal.bitset_location + (next_internal.local_offset * node_count * 2) - 1));
1525+
to_bitset_range(next_internal.bitset_location + (next_internal.local_offset * node_count),
1526+
next_internal.bitset_location + (next_internal.local_offset * node_count * 2) - 1));
15271527

15281528
/* Handle the upper level */
15291529
current_order -= 1u;
@@ -1676,11 +1676,11 @@ static inline size_t buddy_tree_size_for_order(struct buddy_tree *t,
16761676

16771677
static void write_to_internal_position(struct buddy_tree* t, struct internal_position pos, size_t value) {
16781678
unsigned char *bitset = buddy_tree_bits(t);
1679-
struct bitset_range clear_range = bitset_range(pos.bitset_location, pos.bitset_location + pos.local_offset - 1);
1679+
struct bitset_range clear_range = to_bitset_range(pos.bitset_location, pos.bitset_location + pos.local_offset - 1);
16801680

16811681
bitset_clear_range(bitset, clear_range);
16821682
if (value) {
1683-
bitset_set_range(bitset, bitset_range(pos.bitset_location, pos.bitset_location+value-1));
1683+
bitset_set_range(bitset, to_bitset_range(pos.bitset_location, pos.bitset_location+value-1));
16841684
}
16851685

16861686
#ifdef BUDDY_EXPERIMENTAL_CHANGE_TRACKING
@@ -1693,14 +1693,14 @@ static size_t read_from_internal_position(unsigned char *bitset, struct internal
16931693
if (! bitset_test(bitset, pos.bitset_location)) {
16941694
return 0; /* Fast test without complete extraction */
16951695
}
1696-
return bitset_count_range(bitset, bitset_range(pos.bitset_location, pos.bitset_location+pos.local_offset-1));
1696+
return bitset_count_range(bitset, to_bitset_range(pos.bitset_location, pos.bitset_location+pos.local_offset-1));
16971697
}
16981698

16991699
static inline unsigned char compare_with_internal_position(unsigned char *bitset, struct internal_position pos, size_t value) {
17001700
return bitset_test(bitset, pos.bitset_location+value-1);
17011701
}
17021702

1703-
static struct buddy_tree_interval buddy_tree_interval(struct buddy_tree *t, struct buddy_tree_pos pos) {
1703+
static struct buddy_tree_interval to_buddy_tree_interval(struct buddy_tree *t, struct buddy_tree_pos pos) {
17041704
struct buddy_tree_interval result;
17051705
size_t depth;
17061706

@@ -2050,7 +2050,7 @@ static const uint8_t bitset_char_mask[8][8] = {
20502050
{0, 0, 0, 0, 0, 0, 0, 128},
20512051
};
20522052

2053-
static inline struct bitset_range bitset_range(size_t from_pos, size_t to_pos) {
2053+
static inline struct bitset_range to_bitset_range(size_t from_pos, size_t to_pos) {
20542054
struct bitset_range range = {0};
20552055
range.from_bucket = from_pos / CHAR_BIT;
20562056
range.to_bucket = to_pos / CHAR_BIT;

tests.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,15 @@ void test_bitset_range(void) {
108108
for (size_t i = 0; i < bitset_length; i++) {
109109
for (size_t j = 0; j <= i; j++) {
110110
memset(buf, 0, 4);
111-
bitset_set_range(buf, bitset_range(j, i));
111+
bitset_set_range(buf, to_bitset_range(j, i));
112112
for (size_t k = 0; k < bitset_length; k++) {
113113
if ((k >= j) && (k <= i)) {
114114
assert(bitset_test(buf, k));
115115
} else {
116116
assert(!bitset_test(buf, k));
117117
}
118118
}
119-
bitset_clear_range(buf, bitset_range(j, i));
119+
bitset_clear_range(buf, to_bitset_range(j, i));
120120
for (size_t k = j; k < i; k++) {
121121
assert(!bitset_test(buf, k));
122122
}
@@ -186,16 +186,16 @@ void test_bitset_shift(void) {
186186
void test_bitset_shift_invalid(void) {
187187
unsigned char buf[4096] = {0};
188188
START_TEST;
189-
bitset_set_range(buf, bitset_range(1, 0)); /* no-op */
189+
bitset_set_range(buf, to_bitset_range(1, 0)); /* no-op */
190190
assert(!bitset_test(buf, 0));
191191
assert(!bitset_test(buf, 1));
192-
bitset_set_range(buf, bitset_range(0, 1));
192+
bitset_set_range(buf, to_bitset_range(0, 1));
193193
assert(bitset_test(buf, 0));
194194
assert(bitset_test(buf, 1));
195-
bitset_clear_range(buf, bitset_range(1, 0)) /* no-op */;
195+
bitset_clear_range(buf, to_bitset_range(1, 0)) /* no-op */;
196196
assert(bitset_test(buf, 0));
197197
assert(bitset_test(buf, 1));
198-
bitset_clear_range(buf, bitset_range(0, 1));
198+
bitset_clear_range(buf, to_bitset_range(0, 1));
199199
assert(!bitset_test(buf, 0));
200200
assert(!bitset_test(buf, 1));
201201
}
@@ -2499,10 +2499,10 @@ void test_buddy_tree_interval(void) {
24992499
START_TEST;
25002500
t = buddy_tree_init(buddy_tree_buf, 3);
25012501
pos = buddy_tree_leftmost_child(t);
2502-
interval = buddy_tree_interval(t, pos);
2502+
interval = to_buddy_tree_interval(t, pos);
25032503
assert(interval.from.index == pos.index);
25042504
assert(interval.to.index == pos.index);
2505-
interval = buddy_tree_interval(t, buddy_tree_parent(pos));
2505+
interval = to_buddy_tree_interval(t, buddy_tree_parent(pos));
25062506
assert(interval.from.index == pos.index);
25072507
assert(interval.to.index == buddy_tree_right_adjacent(pos).index);
25082508
}
@@ -2515,8 +2515,8 @@ void test_buddy_tree_interval_contains(void) {
25152515
START_TEST;
25162516
t = buddy_tree_init(buddy_tree_buf, 3);
25172517
pos = buddy_tree_leftmost_child(t);
2518-
interval_low = buddy_tree_interval(t, pos);
2519-
interval_high = buddy_tree_interval(t, buddy_tree_parent(pos));
2518+
interval_low = to_buddy_tree_interval(t, pos);
2519+
interval_high = to_buddy_tree_interval(t, buddy_tree_parent(pos));
25202520
assert(buddy_tree_interval_contains(interval_low, interval_low) == 1);
25212521
assert(buddy_tree_interval_contains(interval_high, interval_low) == 1);
25222522
assert(buddy_tree_interval_contains(interval_high, interval_high) == 1);
@@ -2529,7 +2529,7 @@ void test_buddy_tree_buddy() {
25292529
struct buddy_tree *tree;
25302530
START_TEST;
25312531
buddy = buddy_embed(buf, 4096);
2532-
tree = buddy_tree(buddy);
2532+
tree = buddy_tree_for(buddy);
25332533
assert(buddy_tree_buddy(tree) == buddy);
25342534
}
25352535

0 commit comments

Comments
 (0)