From 3850b481846d73f756887374847b0c6672757e46 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 7 Sep 2018 15:43:38 +0200 Subject: [PATCH] kernel: fix Julia GC code --- src/julia_gc.c | 14 ++++++++++++++ src/weakptr.c | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/julia_gc.c b/src/julia_gc.c index f9472809ab..8426e7ef9f 100644 --- a/src/julia_gc.c +++ b/src/julia_gc.c @@ -64,6 +64,13 @@ static inline Bag * DATA(BagHeader * bag) } +static TNumExtraMarkFuncBags ExtraMarkFuncBags; +void SetExtraMarkFuncBags(TNumExtraMarkFuncBags func) +{ + ExtraMarkFuncBags = func; +} + + /**************************************************************************** ** *F InitFreeFuncBag(,) @@ -498,6 +505,13 @@ void GapRootScanner(int full) // types, which thus also will not be collected prematurely) JMark(Module); + // allow installing a custom marking function. This is used for + // integrating GAP (possibly linked as a shared library) with other code + // bases which use their own form of garbage collection. For example, + // with Python (for SageMath). + if (ExtraMarkFuncBags) + (*ExtraMarkFuncBags)(); + // scan the stack for further object references, and mark them syJmp_buf registers; sySetjmp(registers); diff --git a/src/weakptr.c b/src/weakptr.c index 53a2978f60..803c278f1d 100644 --- a/src/weakptr.c +++ b/src/weakptr.c @@ -147,12 +147,12 @@ static inline void SET_ELM_WPOBJ(Obj list, UInt pos, Obj val) ptr[pos] = val; return; } - jl_weakref_t * wref = (jl_weakref_t *)(ptr[pos]); - if (!IS_BAG_REF(wref)) { + if (!IS_BAG_REF(ptr[pos])) { ptr[pos] = (Bag)jl_gc_new_weakref((jl_value_t *)val); jl_gc_wb_back(BAG_HEADER(list)); } else { + jl_weakref_t * wref = (jl_weakref_t *)(ptr[pos]); wref->value = (jl_value_t *)val; jl_gc_wb(wref, BAG_HEADER(val)); }