diff --git a/src/julia_gc.c b/src/julia_gc.c index eb638b2449..3d978e7fbf 100644 --- a/src/julia_gc.c +++ b/src/julia_gc.c @@ -30,6 +30,7 @@ #include "julia.h" #include "julia_gcext.h" +#include "julia_gc.h" /**************************************************************************** @@ -482,6 +483,31 @@ static inline int JMark(void * obj) return jl_gc_mark_queue_obj(JuliaTLS, (jl_value_t *)obj); } +void MarkJuliaObjSafe(void * obj) +{ + if (!obj) + return; + // Validate that `obj` is still allocated and not on a + // free list already. We verify this by checking that the + // type is a pool object of type `jl_datatype_type`. + jl_value_t *ty = jl_typeof(obj); + if (jl_gc_internal_obj_base_ptr(ty) != ty) + return; + if (!jl_typeis(ty, jl_datatype_type)) + return; + if (jl_gc_mark_queue_obj(JuliaTLS, (jl_value_t *)obj)) + YoungRef++; +} + + +void MarkJuliaObj(void * obj) +{ + if (!obj) + return; + if (jl_gc_mark_queue_obj(JuliaTLS, (jl_value_t *)obj)) + YoungRef++; +} + // Overview of conservative stack scanning // diff --git a/src/julia_gc.h b/src/julia_gc.h new file mode 100644 index 0000000000..5e7480b3c7 --- /dev/null +++ b/src/julia_gc.h @@ -0,0 +1,35 @@ +/**************************************************************************** +** +** This file is part of GAP, a system for computational discrete algebra. +** +** Copyright of GAP belongs to its developers, whose names are too numerous +** to list here. Please refer to the COPYRIGHT file for details. +** +** SPDX-License-Identifier: GPL-2.0-or-later +** +** This file declares functions of the Julia GC interface. +*/ + +#ifndef GAP_JULIA_GC_H +#define GAP_JULIA_GC_H + +/**************************************************************************** +** +*F MarkJuliaObj() . . . . . . . . . . . . . . . . mark Julia object +** +** 'MarkJuliaObjSafe' marks a Julia object; the argument can be NULL. +*/ + +void MarkJuliaObj(void * obj); + +/**************************************************************************** +** +*F MarkJuliaObjSafe() . . . . . . . . . . . . . . mark Julia object +** +** 'MarkJuliaObjSafe' marks a Julia object, verifying that it is a valid +** object. +*/ + +void MarkJuliaObjSafe(void * obj); + +#endif