v2 / vlib / builtin / builtin_notd_gcboehm.c.v
68 lines · 47 sloc · 2.2 KB · 47593c815a02507f0916c2e2a486e4cc86c7bd8c
Raw
1module builtin
2
3// Just define the C functions, so that V does not error because of the missing definitions.
4
5// Note: they will NOT be used, since calls to them are wrapped with `$if gcboehm ? { }`
6
7fn C.GC_MALLOC(n usize) voidptr
8
9fn C.GC_MALLOC_ATOMIC(n usize) voidptr
10
11fn C.GC_MALLOC_UNCOLLECTABLE(n usize) voidptr
12
13fn C.GC_REALLOC(ptr voidptr, n usize) voidptr
14
15fn C.GC_FREE(ptr voidptr)
16
17fn C.GC_memalign(align isize, size isize) voidptr
18
19fn C.GC_get_heap_usage_safe(pheap_size &usize, pfree_bytes &usize, punmapped_bytes &usize, pbytes_since_gc &usize,
20 ptotal_bytes &usize)
21
22fn C.GC_get_memory_use() usize
23
24fn C.GC_gcollect()
25
26// gc_check_leaks is useful for detecting leaks, but it needs the GC to run.
27// When GC is not used, it is a NOP.
28pub fn gc_check_leaks() {}
29
30// gc_is_enabled() returns true, if the GC is enabled at runtime.
31// It will always return false, with `-gc none`.
32// See also gc_disable() and gc_enable().
33pub fn gc_is_enabled() bool {
34 return false
35}
36
37// gc_enable explicitly enables the GC.
38// Note, that garbage collections are done automatically, when needed in most cases,
39// and also that by default the GC is on, so you do not need to enable it.
40// See also gc_disable() and gc_collect().
41// Note that gc_enable() is a NOP with `-gc none`.
42pub fn gc_enable() {}
43
44// gc_disable explicitly disables the GC.
45// Do not forget to enable it again by calling gc_enable(), when your program is otherwise idle, and can afford it.
46// See also gc_enable() and gc_collect().
47// Note that gc_disable() is a NOP with `-gc none`.
48pub fn gc_disable() {}
49
50// gc_collect explicitly performs a garbage collection.
51// When the GC is not on, (with `-gc none`), it is a NOP.
52pub fn gc_collect() {}
53
54pub type FnGC_WarnCB = fn (msg &char, arg usize)
55
56fn C.GC_get_warn_proc() FnGC_WarnCB
57fn C.GC_set_warn_proc(cb FnGC_WarnCB)
58
59// gc_get_warn_proc returns the current callback fn, that will be used for printing GC warnings.
60// When the GC is not on, it is a NOP.
61pub fn gc_get_warn_proc() {}
62
63// gc_set_warn_proc sets the callback fn, that will be used for printing GC warnings.
64// When the GC is not on, it is a NOP.
65pub fn gc_set_warn_proc(cb FnGC_WarnCB) {}
66
67// used by builtin_init
68fn internal_gc_warn_proc_none(msg &char, arg usize) {}
69