2021-03-20 14:16:36 +01:00
|
|
|
module builtin
|
|
|
|
|
|
|
|
#define GC_THREADS 1
|
|
|
|
|
2021-04-08 18:17:04 +02:00
|
|
|
$if static_boehm ? {
|
|
|
|
$if macos {
|
2021-04-10 09:46:43 +02: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 18:17:04 +02:00
|
|
|
} $else $if linux {
|
|
|
|
#flag -l:libgc.a
|
|
|
|
} $else {
|
|
|
|
#flag -lgc
|
|
|
|
}
|
|
|
|
} $else {
|
|
|
|
$if macos {
|
|
|
|
#pkgconfig bdw-gc
|
|
|
|
}
|
|
|
|
$if windows {
|
|
|
|
#flag -I@VROOT/thirdparty/libgc/include
|
|
|
|
#flag -L@VROOT/thirdparty/libgc
|
|
|
|
}
|
|
|
|
#flag -lgc
|
2021-03-25 06:28:30 +01:00
|
|
|
}
|
2021-04-08 18:17:04 +02:00
|
|
|
|
2021-03-25 16:52:33 +01:00
|
|
|
$if gcboehm_leak ? {
|
|
|
|
#define GC_DEBUG
|
|
|
|
}
|
2021-03-20 14:16:36 +01:00
|
|
|
|
2021-04-08 18:17:04 +02:00
|
|
|
#include <gc.h>
|
2021-03-20 14:16:36 +01:00
|
|
|
|
2021-03-25 16:52:33 +01: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-03-20 14:16:36 +01:00
|
|
|
fn C.GC_MALLOC(n size_t) voidptr
|
|
|
|
|
2021-03-26 15:44:45 +01:00
|
|
|
fn C.GC_MALLOC_UNCOLLECTABLE(n size_t) voidptr
|
|
|
|
|
2021-03-20 14:16:36 +01:00
|
|
|
fn C.GC_REALLOC(ptr voidptr, n size_t) voidptr
|
|
|
|
|
|
|
|
fn C.GC_FREE(ptr voidptr)
|
2021-03-21 03:31:06 +01:00
|
|
|
|
2021-03-25 16:52:33 +01:00
|
|
|
// explicitely perform garbage collection now! Garbage collections
|
2021-04-07 15:25:11 +02:00
|
|
|
// are done automatically when needed, so this function is hardly needed
|
2021-03-21 03:31:06 +01:00
|
|
|
fn C.GC_gcollect()
|
2021-03-25 16:52:33 +01: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 12:13:49 +02:00
|
|
|
// protect memory block from being freed before this call
|
|
|
|
fn C.GC_reachable_here(voidptr)
|
|
|
|
|
2021-03-25 16:52:33 +01:00
|
|
|
// for leak detection it is advisable to do explicit garbage collections
|
|
|
|
pub fn gc_check_leaks() {
|
|
|
|
$if gcboehm_leak ? {
|
|
|
|
C.GC_gcollect()
|
|
|
|
}
|
|
|
|
}
|