From 4489660aa2efc909cc134f66a58609592a33ab87 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 27 Apr 2018 00:59:35 +0200 Subject: [PATCH] kernel: fix marking of precords and component objects --- src/objects.c | 4 ++-- src/precord.c | 31 +++++++++++++++++++++++++++---- src/precord.h | 4 ++++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/objects.c b/src/objects.c index 8463ead514..5a5076a0d3 100644 --- a/src/objects.c +++ b/src/objects.c @@ -2009,14 +2009,14 @@ static Int InitKernel ( /* install the marking methods */ InfoBags[ T_COMOBJ ].name = "object (component)"; - InitMarkFuncBags( T_COMOBJ , MarkAllSubBags ); + InitMarkFuncBags( T_COMOBJ , MarkPRecSubBags ); InfoBags[ T_POSOBJ ].name = "object (positional)"; InitMarkFuncBags( T_POSOBJ , MarkAllSubBags ); InfoBags[ T_DATOBJ ].name = "object (data)"; InitMarkFuncBags( T_DATOBJ , MarkOneSubBags ); #if !defined(USE_THREADSAFE_COPYING) InfoBags[ T_COMOBJ +COPYING ].name = "object (component,copied)"; - InitMarkFuncBags( T_COMOBJ +COPYING , MarkAllSubBags ); + InitMarkFuncBags( T_COMOBJ +COPYING , MarkPRecSubBags ); InfoBags[ T_POSOBJ +COPYING ].name = "object (positional,copied)"; InitMarkFuncBags( T_POSOBJ +COPYING , MarkAllSubBags ); InfoBags[ T_DATOBJ +COPYING ].name = "object (data,copied)"; diff --git a/src/precord.c b/src/precord.c index c10c42ce24..ee3558a57e 100644 --- a/src/precord.c +++ b/src/precord.c @@ -821,6 +821,29 @@ void LoadPRec( Obj prec ) } } +/**************************************************************************** +** +*F MarkPRecSubBags( ) . . . . marking function for precs and com. objs +** +** 'MarkPRecSubBags' is the marking function for bags of type 'T_PREC' or +** 'T_COMOBJ'. +*/ +void MarkPRecSubBags(Obj bag) +{ + const Bag * data = CONST_PTR_BAG(bag); + const UInt count = SIZE_BAG(bag) / sizeof(Bag); + + // while data[0] is unused for regular precords, it used during copying + // to store a pointer to the copy; moreover, this mark function is also + // used for component objects, which store their type in slot 0 + MarkBag(data[0]); + + for (UInt i = 3; i < count; i += 2) { + MarkBag(data[i]); + } +} + + /**************************************************************************** ** *F * * * * * * * * * * * * * initialize module * * * * * * * * * * * * * * * @@ -864,11 +887,11 @@ static Int InitKernel ( /* GASMAN marking functions and GASMAN names */ InitBagNamesFromTable( BagNames ); - InitMarkFuncBags( T_PREC , MarkAllSubBags ); - InitMarkFuncBags( T_PREC +IMMUTABLE , MarkAllSubBags ); + InitMarkFuncBags( T_PREC , MarkPRecSubBags ); + InitMarkFuncBags( T_PREC +IMMUTABLE , MarkPRecSubBags ); #if !defined(USE_THREADSAFE_COPYING) - InitMarkFuncBags( T_PREC +COPYING , MarkAllSubBags ); - InitMarkFuncBags( T_PREC +IMMUTABLE +COPYING , MarkAllSubBags ); + InitMarkFuncBags( T_PREC +COPYING , MarkPRecSubBags ); + InitMarkFuncBags( T_PREC +IMMUTABLE +COPYING , MarkPRecSubBags ); #endif /* Immutable records are public */ diff --git a/src/precord.h b/src/precord.h index e753f5c376..f2d23e9769 100644 --- a/src/precord.h +++ b/src/precord.h @@ -260,6 +260,10 @@ extern void CopyPRecord(Obj copy, Obj original); #endif + +extern void MarkPRecSubBags(Obj bag); + + /**************************************************************************** ** *F * * * * * * * * * * * * * initialize module * * * * * * * * * * * * * * *