Skip to content

Commit cbaff6a

Browse files
committed
builtin: C.GC_register_displacement
1 parent 4ebbf65 commit cbaff6a

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

vlib/builtin/builtin_d_gcboehm.c.v

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ pub type FnGC_WarnCB = fn (const_msg &char, arg usize)
255255
fn C.GC_get_warn_proc() FnGC_WarnCB
256256
fn C.GC_set_warn_proc(cb FnGC_WarnCB)
257257

258+
fn C.GC_register_displacement(offset usize)
259+
258260
// gc_get_warn_proc returns the current callback fn, that will be used for printing GC warnings.
259261
pub fn gc_get_warn_proc() FnGC_WarnCB {
260262
return C.GC_get_warn_proc()

vlib/v/gen/c/cmain.v

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ fn (mut g Gen) gen_boehm_gc_init() {
167167
g.writeln('\tGC_allow_register_threads();')
168168
}
169169
g.writeln('\tGC_INIT();')
170+
// Register V's array data header displacement so Boehm always recognises
171+
// the interior pointer kept in `array.data` (which is offset by
172+
// `array_data_header_size()` bytes from the GC allocation start).
173+
g.writeln('\tGC_register_displacement(sizeof(void*));')
170174
if g.pref.os == .linux && !g.pref.no_builtin {
171175
g.writeln('\tbuiltin__gc_restore_roots_after_debugger_init(__v_gc_debugger_workaround);')
172176
}
@@ -186,6 +190,7 @@ fn (mut g Gen) gen_windows_shared_library_boehm_init() {
186190
g.writeln('\tGC_set_free_space_divisor(2);')
187191
}
188192
g.writeln('\tGC_INIT();')
193+
g.writeln('\tGC_register_displacement(sizeof(void*));')
189194
g.writeln('#endif')
190195
}
191196

0 commit comments

Comments
 (0)