blob: 5c371d6ff64da11bdba8b4a3ea3fbd9a48cb9050 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
#include <stddef.h>
/*
todo get this working proper. i don't think it's
possible in X however.
*/
/*
#include "memory.h"
#include "config.h"
Heap ui_heap = { 0 };
static void try_init_heap(void) {
if (!ui_heap.buffer) {
init_heap(
&ui_heap,
galloc(ui_memory_size),
ui_memory_size
);
}
}
void* ui_malloc(size_t size) {
try_init_heap();
return heap_alloc(&ui_heap, size);
}
void ui_free(void* ptr) {
try_init_heap();
heap_free(&ui_heap, ptr);
}
void* ui_realloc(void* ptr, size_t size) {
void* old;
size_t os, diff;
if (!ptr)
return ui_malloc(size);
if (!size && ptr)
ui_free(ptr);
os = heap_block_size(ptr);
if (size == os) return ptr;
diff = size;
if (size > os)
diff = os;
old = ptr;
ptr = ui_malloc(size);
memcpy(ptr, old, diff);
ui_free(old);
return ptr;
}
void* ui_calloc(size_t c, size_t s) {
void* p;
s *= c;
p = ui_malloc(s);
memset(p, 0, s);
return p;
}
#ifdef malloc
#undef malloc
#endif
#ifdef free
#undef free
#endif
#ifdef realloc
#undef realloc
#endif
#ifdef calloc
#undef calloc
#endif
#define malloc ui_malloc
#define free ui_free
#define realloc ui_realloc
#define calloc ui_calloc
*/
#define UI_IMPLEMENTATION
#include "luigi.h"
/*
#undef malloc
#undef free
#undef realloc
#undef calloc
*/
|