blob: befec1d2db093f1443c0be4f69e1d82fed52390b (
plain)
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
88
89
90
91
|
module builtin
#flag -DGC_THREADS=1
$if static_boehm ? {
$if macos {
#flag -I$first_existing("/opt/homebrew/include", "/usr/local/include")
#flag $first_existing("/opt/homebrew/lib/libgc.a", "/usr/local/lib/libgc.a")
} $else $if linux {
#flag -l:libgc.a
} $else $if openbsd {
#flag -I/usr/local/include
#flag /usr/local/lib/libgc.a
#flag -lpthread
} $else $if windows {
#flag -DGC_NOT_DLL=1
$if tinyc {
#flag -I@VEXEROOT/thirdparty/libgc/include
#flag -L@VEXEROOT/thirdparty/libgc
#flag -lgc
} $else {
#flag -DGC_BUILTIN_ATOMIC=1
#flag -I@VEXEROOT/thirdparty/libgc
#flag @VEXEROOT/thirdparty/libgc/gc.o
}
} $else {
#flag -lgc
}
} $else {
$if macos {
#pkgconfig bdw-gc
} $else $if openbsd || freebsd {
#flag -I/usr/local/include
#flag -L/usr/local/lib
}
$if windows {
$if tinyc {
#flag -I@VEXEROOT/thirdparty/libgc/include
#flag -L@VEXEROOT/thirdparty/libgc
#flag -lgc
} $else {
#flag -DGC_BUILTIN_ATOMIC=1
#flag -I@VEXEROOT/thirdparty/libgc
#flag @VEXEROOT/thirdparty/libgc/gc.o
}
} $else {
#flag -lgc
}
}
$if gcboehm_leak ? {
#flag -DGC_DEBUG=1
}
#include <gc.h>
// replacements for `malloc()/calloc()`, `realloc()` and `free()`
// for use with Boehm-GC
// Do not use them manually. They are automatically chosen when
// compiled with `-gc boehm` or `-gc boehm_leak`.
fn C.GC_MALLOC(n size_t) voidptr
fn C.GC_MALLOC_ATOMIC(n size_t) voidptr
fn C.GC_MALLOC_UNCOLLECTABLE(n size_t) voidptr
fn C.GC_REALLOC(ptr voidptr, n size_t) voidptr
fn C.GC_FREE(ptr voidptr)
// explicitely perform garbage collection now! Garbage collections
// are done automatically when needed, so this function is hardly needed
fn C.GC_gcollect()
// functions to temporarily suspend/resume garbage collection
fn C.GC_disable()
fn C.GC_enable()
// returns non-zero if GC is disabled
fn C.GC_is_disabled() int
// protect memory block from being freed before this call
fn C.GC_reachable_here(voidptr)
// for leak detection it is advisable to do explicit garbage collections
pub fn gc_check_leaks() {
$if gcboehm_leak ? {
C.GC_gcollect()
}
}
|