|
@@ -4,6 +4,22 @@
|
4
|
4
|
|
5
|
5
|
#include "allocator_internal.h"
|
6
|
6
|
|
|
7
|
+#ifdef DEBUG
|
|
8
|
+#include <stdio.h>
|
|
9
|
+
|
|
10
|
+void debug_print_tree(int indent, TreeAlloc *node) {
|
|
11
|
+ if (node != NULL) {
|
|
12
|
+ debug_print_tree(indent + 1, node->left);
|
|
13
|
+ for (int ii = 0; ii < indent; ii++) { printf(" "); }
|
|
14
|
+ if (node->color == COLOR_RED) { printf("\e[31"); }
|
|
15
|
+ printf("%p %u\n", node, node->size);
|
|
16
|
+ if (node->color == COLOR_RED) { printf("\e[37"); }
|
|
17
|
+ debug_print_tree(indent + 1, node->right);
|
|
18
|
+ }
|
|
19
|
+}
|
|
20
|
+
|
|
21
|
+#endif
|
|
22
|
+
|
7
|
23
|
TreeAlloc *insert_node_at(void *address, uintptr_t padding, uintptr_t align, uintptr_t size) {
|
8
|
24
|
return NULL;
|
9
|
25
|
}
|
|
@@ -354,6 +370,12 @@ void unalloc(Arena *arena, void *addr) {
|
354
|
370
|
|
355
|
371
|
void *alloc(Arena *arena, uintptr_t size, uintptr_t align) {
|
356
|
372
|
uintptr_t actual_align = lcm(alignof(struct WatermarkAlloc), align);
|
|
373
|
+#ifdef DEBUG
|
|
374
|
+ printf("=== FREESPACE TREE ===\n");
|
|
375
|
+ debug_print_tree(0, arena->root_freespace);
|
|
376
|
+ printf("=== TREEALLOC TREE ===\n");
|
|
377
|
+ debug_print_tree(0, arena->root_treealloc);
|
|
378
|
+#endif
|
357
|
379
|
if (arena->root_freespace == NULL) {
|
358
|
380
|
// Handle being out of freespace.
|
359
|
381
|
if (!add_new_region(arena, size, sizeof(TreeAlloc), actual_align)) {
|