2021-03-20 16:16:36 +03:00
|
|
|
module builtin
|
|
|
|
|
2021-10-25 10:24:08 +03:00
|
|
|
$if freebsd {
|
|
|
|
// Tested on FreeBSD 13.0-RELEASE-p3, with clang, gcc and tcc:
|
|
|
|
#flag -DBUS_PAGE_FAULT=T_PAGEFLT
|
|
|
|
$if !tinyc {
|
|
|
|
#flag -DGC_THREADS=1
|
|
|
|
#flag -DGC_BUILTIN_ATOMIC=1
|
|
|
|
#flag @VEXEROOT/thirdparty/libgc/gc.o
|
|
|
|
#flag -lpthread
|
|
|
|
}
|
|
|
|
} $else {
|
|
|
|
#flag -DGC_THREADS=1
|
|
|
|
}
|
2021-03-20 16:16:36 +03:00
|
|
|
|
2021-04-08 19:17:04 +03:00
|
|
|
$if static_boehm ? {
|
|
|
|
$if macos {
|
2021-04-10 10:46:43 +03:00
|
|
|
#flag -I$first_existing("/opt/homebrew/include", "/usr/local/include")
|
|
|
|
#flag $first_existing("/opt/homebrew/lib/libgc.a", "/usr/local/lib/libgc.a")
|
2021-04-08 19:17:04 +03:00
|
|
|
} $else $if linux {
|
|
|
|
#flag -l:libgc.a
|
2021-06-01 22:28:30 +03:00
|
|
|
} $else $if openbsd {
|
|
|
|
#flag -I/usr/local/include
|
|
|
|
#flag /usr/local/lib/libgc.a
|
|
|
|
#flag -lpthread
|
2021-06-19 17:06:25 +03:00
|
|
|
} $else $if windows {
|
2021-07-24 16:04:26 +03:00
|
|
|
#flag -DGC_NOT_DLL=1
|
|
|
|
$if tinyc {
|
|
|
|
#flag -I@VEXEROOT/thirdparty/libgc/include
|
|
|
|
#flag -L@VEXEROOT/thirdparty/libgc
|
|
|
|
#flag -lgc
|
2022-01-11 16:23:21 +03:00
|
|
|
} $else $if msvc {
|
|
|
|
#flag -DGC_BUILTIN_ATOMIC=1
|
|
|
|
#flag -I@VEXEROOT/thirdparty/libgc/include
|
2021-07-24 16:04:26 +03:00
|
|
|
} $else {
|
|
|
|
#flag -DGC_BUILTIN_ATOMIC=1
|
|
|
|
#flag -I@VEXEROOT/thirdparty/libgc
|
|
|
|
#flag @VEXEROOT/thirdparty/libgc/gc.o
|
|
|
|
}
|
2021-04-08 19:17:04 +03:00
|
|
|
} $else {
|
|
|
|
#flag -lgc
|
|
|
|
}
|
|
|
|
} $else {
|
|
|
|
$if macos {
|
|
|
|
#pkgconfig bdw-gc
|
2021-06-01 22:28:30 +03:00
|
|
|
} $else $if openbsd || freebsd {
|
|
|
|
#flag -I/usr/local/include
|
|
|
|
#flag -L/usr/local/lib
|
2021-04-08 19:17:04 +03:00
|
|
|
}
|
|
|
|
$if windows {
|
2021-07-24 16:04:26 +03:00
|
|
|
$if tinyc {
|
|
|
|
#flag -I@VEXEROOT/thirdparty/libgc/include
|
|
|
|
#flag -L@VEXEROOT/thirdparty/libgc
|
|
|
|
#flag -lgc
|
2022-01-11 16:23:21 +03:00
|
|
|
} $else $if msvc {
|
|
|
|
#flag -DGC_BUILTIN_ATOMIC=1
|
|
|
|
#flag -I@VEXEROOT/thirdparty/libgc/include
|
2021-07-24 16:04:26 +03:00
|
|
|
} $else {
|
|
|
|
#flag -DGC_BUILTIN_ATOMIC=1
|
|
|
|
#flag -I@VEXEROOT/thirdparty/libgc
|
|
|
|
#flag @VEXEROOT/thirdparty/libgc/gc.o
|
|
|
|
}
|
|
|
|
} $else {
|
|
|
|
#flag -lgc
|
2021-04-08 19:17:04 +03:00
|
|
|
}
|
2021-03-25 08:28:30 +03:00
|
|
|
}
|
2021-04-08 19:17:04 +03:00
|
|
|
|
2021-03-25 18:52:33 +03:00
|
|
|
$if gcboehm_leak ? {
|
2021-07-24 16:04:26 +03:00
|
|
|
#flag -DGC_DEBUG=1
|
2021-03-25 18:52:33 +03:00
|
|
|
}
|
2021-03-20 16:16:36 +03:00
|
|
|
|
2021-04-08 19:17:04 +03:00
|
|
|
#include <gc.h>
|
2021-03-20 16:16:36 +03:00
|
|
|
|
2021-03-25 18:52:33 +03:00
|
|
|
// 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`.
|
2021-09-08 13:09:32 +03:00
|
|
|
fn C.GC_MALLOC(n usize) voidptr
|
2021-03-20 16:16:36 +03:00
|
|
|
|
2021-09-08 13:09:32 +03:00
|
|
|
fn C.GC_MALLOC_ATOMIC(n usize) voidptr
|
2021-04-14 01:40:26 +03:00
|
|
|
|
2021-09-08 13:09:32 +03:00
|
|
|
fn C.GC_MALLOC_UNCOLLECTABLE(n usize) voidptr
|
2021-03-26 17:44:45 +03:00
|
|
|
|
2021-09-08 13:09:32 +03:00
|
|
|
fn C.GC_REALLOC(ptr voidptr, n usize) voidptr
|
2021-03-20 16:16:36 +03:00
|
|
|
|
|
|
|
fn C.GC_FREE(ptr voidptr)
|
2021-03-21 05:31:06 +03:00
|
|
|
|
2021-03-25 18:52:33 +03:00
|
|
|
// explicitely perform garbage collection now! Garbage collections
|
2021-04-07 16:25:11 +03:00
|
|
|
// are done automatically when needed, so this function is hardly needed
|
2021-03-21 05:31:06 +03:00
|
|
|
fn C.GC_gcollect()
|
2021-03-25 18:52:33 +03:00
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2021-04-09 13:13:49 +03:00
|
|
|
// protect memory block from being freed before this call
|
|
|
|
fn C.GC_reachable_here(voidptr)
|
|
|
|
|
2021-03-25 18:52:33 +03:00
|
|
|
// for leak detection it is advisable to do explicit garbage collections
|
|
|
|
pub fn gc_check_leaks() {
|
|
|
|
$if gcboehm_leak ? {
|
|
|
|
C.GC_gcollect()
|
|
|
|
}
|
|
|
|
}
|