Skip to content

Commit

Permalink
Restrict CallbackForAllBags to builds using GASMAN
Browse files Browse the repository at this point in the history
This function is not available in Boehm GC -- we did provide an
empty stub for it, but that's a dangerous illusion, so we are better
off removing it.
  • Loading branch information
fingolfin committed Mar 26, 2018
1 parent e3996ea commit 26cd0bf
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 53 deletions.
24 changes: 12 additions & 12 deletions hpcgap/src/c_type1.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
/* global variables used in handlers */
static GVar G_NAME__FUNC;
static Obj GF_NAME__FUNC;
static GVar G_IsType;
static Obj GF_IsType;
static GVar G_FLUSH__ALL__METHOD__CACHES;
static Obj GF_FLUSH__ALL__METHOD__CACHES;
static GVar G_IS__REC;
static Obj GF_IS__REC;
static GVar G_IS__LIST;
Expand Down Expand Up @@ -79,8 +75,6 @@ static GVar G_GETTER__FUNCTION;
static Obj GF_GETTER__FUNCTION;
static GVar G_IS__AND__FILTER;
static Obj GF_IS__AND__FILTER;
static GVar G_COMPACT__TYPE__IDS;
static Obj GF_COMPACT__TYPE__IDS;
static GVar G_fail;
static Obj GC_fail;
static GVar G_LEN__LIST;
Expand Down Expand Up @@ -166,6 +160,10 @@ static GVar G_NEW__TYPE__NEXT__ID;
static Obj GC_NEW__TYPE__NEXT__ID;
static GVar G_NEW__TYPE__ID__LIMIT;
static Obj GC_NEW__TYPE__ID__LIMIT;
static GVar G_FLUSH__ALL__METHOD__CACHES;
static Obj GF_FLUSH__ALL__METHOD__CACHES;
static GVar G_COMPACT__TYPE__IDS;
static Obj GF_COMPACT__TYPE__IDS;
static GVar G_POS__NUMB__TYPE;
static Obj GC_POS__NUMB__TYPE;
static GVar G_NEW__TYPE;
Expand All @@ -178,6 +176,8 @@ static GVar G_TypeOfTypes;
static Obj GC_TypeOfTypes;
static GVar G_NewType4;
static Obj GF_NewType4;
static GVar G_IsType;
static Obj GF_IsType;
static GVar G_Subtype2;
static Obj GF_Subtype2;
static GVar G_Subtype3;
Expand Down Expand Up @@ -4417,8 +4417,6 @@ static Int PostRestore ( StructInitInfo * module )

/* global variables used in handlers */
G_NAME__FUNC = GVarName( "NAME_FUNC" );
G_IsType = GVarName( "IsType" );
G_FLUSH__ALL__METHOD__CACHES = GVarName( "FLUSH_ALL_METHOD_CACHES" );
G_IS__REC = GVarName( "IS_REC" );
G_IS__LIST = GVarName( "IS_LIST" );
G_ADD__LIST = GVarName( "ADD_LIST" );
Expand Down Expand Up @@ -4453,7 +4451,6 @@ static Int PostRestore ( StructInitInfo * module )
G_SETTER__FUNCTION = GVarName( "SETTER_FUNCTION" );
G_GETTER__FUNCTION = GVarName( "GETTER_FUNCTION" );
G_IS__AND__FILTER = GVarName( "IS_AND_FILTER" );
G_COMPACT__TYPE__IDS = GVarName( "COMPACT_TYPE_IDS" );
G_fail = GVarName( "fail" );
G_LEN__LIST = GVarName( "LEN_LIST" );
G_SET__FILTER__LIST = GVarName( "SET_FILTER_LIST" );
Expand Down Expand Up @@ -4496,12 +4493,15 @@ static Int PostRestore ( StructInitInfo * module )
G_POS__FIRST__FREE__TYPE = GVarName( "POS_FIRST_FREE_TYPE" );
G_NEW__TYPE__NEXT__ID = GVarName( "NEW_TYPE_NEXT_ID" );
G_NEW__TYPE__ID__LIMIT = GVarName( "NEW_TYPE_ID_LIMIT" );
G_FLUSH__ALL__METHOD__CACHES = GVarName( "FLUSH_ALL_METHOD_CACHES" );
G_COMPACT__TYPE__IDS = GVarName( "COMPACT_TYPE_IDS" );
G_POS__NUMB__TYPE = GVarName( "POS_NUMB_TYPE" );
G_NEW__TYPE = GVarName( "NEW_TYPE" );
G_IsFamily = GVarName( "IsFamily" );
G_NewType3 = GVarName( "NewType3" );
G_TypeOfTypes = GVarName( "TypeOfTypes" );
G_NewType4 = GVarName( "NewType4" );
G_IsType = GVarName( "IsType" );
G_Subtype2 = GVarName( "Subtype2" );
G_Subtype3 = GVarName( "Subtype3" );
G_SupType2 = GVarName( "SupType2" );
Expand Down Expand Up @@ -4581,8 +4581,6 @@ static Int InitKernel ( StructInitInfo * module )

/* global variables used in handlers */
InitFopyGVar( "NAME_FUNC", &GF_NAME__FUNC );
InitFopyGVar( "IsType", &GF_IsType );
InitFopyGVar( "FLUSH_ALL_METHOD_CACHES", &GF_FLUSH__ALL__METHOD__CACHES );
InitFopyGVar( "IS_REC", &GF_IS__REC );
InitFopyGVar( "IS_LIST", &GF_IS__LIST );
InitFopyGVar( "ADD_LIST", &GF_ADD__LIST );
Expand Down Expand Up @@ -4618,7 +4616,6 @@ static Int InitKernel ( StructInitInfo * module )
InitFopyGVar( "SETTER_FUNCTION", &GF_SETTER__FUNCTION );
InitFopyGVar( "GETTER_FUNCTION", &GF_GETTER__FUNCTION );
InitFopyGVar( "IS_AND_FILTER", &GF_IS__AND__FILTER );
InitFopyGVar( "COMPACT_TYPE_IDS", &GF_COMPACT__TYPE__IDS );
InitCopyGVar( "fail", &GC_fail );
InitFopyGVar( "LEN_LIST", &GF_LEN__LIST );
InitFopyGVar( "SET_FILTER_LIST", &GF_SET__FILTER__LIST );
Expand Down Expand Up @@ -4662,12 +4659,15 @@ static Int InitKernel ( StructInitInfo * module )
InitCopyGVar( "POS_FIRST_FREE_TYPE", &GC_POS__FIRST__FREE__TYPE );
InitCopyGVar( "NEW_TYPE_NEXT_ID", &GC_NEW__TYPE__NEXT__ID );
InitCopyGVar( "NEW_TYPE_ID_LIMIT", &GC_NEW__TYPE__ID__LIMIT );
InitFopyGVar( "FLUSH_ALL_METHOD_CACHES", &GF_FLUSH__ALL__METHOD__CACHES );
InitFopyGVar( "COMPACT_TYPE_IDS", &GF_COMPACT__TYPE__IDS );
InitCopyGVar( "POS_NUMB_TYPE", &GC_POS__NUMB__TYPE );
InitFopyGVar( "NEW_TYPE", &GF_NEW__TYPE );
InitFopyGVar( "IsFamily", &GF_IsFamily );
InitFopyGVar( "NewType3", &GF_NewType3 );
InitCopyGVar( "TypeOfTypes", &GC_TypeOfTypes );
InitFopyGVar( "NewType4", &GF_NewType4 );
InitFopyGVar( "IsType", &GF_IsType );
InitFopyGVar( "Subtype2", &GF_Subtype2 );
InitFopyGVar( "Subtype3", &GF_Subtype3 );
InitFopyGVar( "SupType2", &GF_SupType2 );
Expand Down
4 changes: 0 additions & 4 deletions src/boehm_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,10 +587,6 @@ void InitGlobalBag(Bag * addr, const Char * cookie)
{
}

void CallbackForAllBags(void (*func)(Bag))
{
}

void InitCollectFuncBags(TNumCollectFuncBags before_func,
TNumCollectFuncBags after_func)
{
Expand Down
43 changes: 41 additions & 2 deletions src/calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,8 @@ void InitHandlerFunc (
**
*f CheckHandlersBag( <bag> ) . . . . . . check that handlers are initialised
*/
#ifdef USE_GASMAN

static void CheckHandlersBag(
Bag bag )
{
Expand Down Expand Up @@ -1096,8 +1098,9 @@ ObjFunc HandlerOfCookie(
return (ObjFunc)0L;
}
}



#endif


/****************************************************************************
**
Expand Down Expand Up @@ -1924,6 +1927,8 @@ Int IsKernelFunction(Obj func)
(SIZE_OBJ(BODY_FUNC(func)) == sizeof(BodyHeader));
}

#ifdef USE_GASMAN

Obj FuncHandlerCookieOfFunction(Obj self, Obj func)
{
Int narg;
Expand All @@ -1941,6 +1946,34 @@ Obj FuncHandlerCookieOfFunction(Obj self, Obj func)
return cookieStr;
}

static void SaveHandler( ObjFunc hdlr )
{
const Char * cookie;
if (hdlr == (ObjFunc)0)
SaveCStr("");
else
{
cookie = CookieOfHandler(hdlr);
if (!cookie)
{
Pr("No cookie for Handler -- workspace will be corrupt\n",0,0);
SaveCStr("");
}
SaveCStr(cookie);
}
}


static ObjFunc LoadHandler( void )
{
Char buf[256];
LoadCStr(buf, 256);
if (buf[0] == '\0')
return (ObjFunc) 0;
else
return HandlerOfCookie(buf);
}

/****************************************************************************
**
*F SaveFunction( <func> ) . . . . . . . . . . . . . . . . . save a function
Expand Down Expand Up @@ -1985,6 +2018,8 @@ void LoadFunction ( Obj func )
LoadOperationExtras( func );
}

#endif


/****************************************************************************
**
Expand Down Expand Up @@ -2033,7 +2068,9 @@ static StructGVarFunc GVarFuncs [] = {
GVAR_FUNC(PROFILE_FUNC, 1, "func"),
GVAR_FUNC(UNPROFILE_FUNC, 1, "func"),
GVAR_FUNC(IsKernelFunction, 1, "func"),
#ifdef USE_GASMAN
GVAR_FUNC(HandlerCookieOfFunction, 1, "func"),
#endif
GVAR_FUNC(FILENAME_FUNC, 1, "func"),
GVAR_FUNC(LOCATION_FUNC, 1, "func"),
GVAR_FUNC(STARTLINE_FUNC, 1, "func"),
Expand Down Expand Up @@ -2068,9 +2105,11 @@ static Int InitKernel (
InitHdlrOpersFromTable( GVarOpers );
InitHdlrFuncsFromTable( GVarFuncs );

#ifdef USE_GASMAN
/* and the saving function */
SaveObjFuncs[ T_FUNCTION ] = SaveFunction;
LoadObjFuncs[ T_FUNCTION ] = LoadFunction;
#endif

/* install the printer */
InitFopyGVar( "PRINT_OPERATION", &PrintOperation );
Expand Down
3 changes: 3 additions & 0 deletions src/calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ extern void InitHandlerFunc (
ObjFunc hdlr,
const Char * cookie );

#ifdef USE_GASMAN

extern const Char * CookieOfHandler(
ObjFunc hdlr );

Expand All @@ -371,6 +373,7 @@ extern void SortHandlers( UInt byWhat );

extern void CheckAllHandlers(void);

#endif

/****************************************************************************
**
Expand Down
2 changes: 2 additions & 0 deletions src/gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -3169,7 +3169,9 @@ void InitializeGap (

/* otherwise call library initialisation */
else {
#ifdef USE_GASMAN
CheckAllHandlers();
#endif

SyInitializing = 1;
for ( i = 0; i < NrBuiltinModules; i++ ) {
Expand Down
6 changes: 3 additions & 3 deletions src/gasman.h
Original file line number Diff line number Diff line change
Expand Up @@ -1135,9 +1135,9 @@ extern void FinishBags( void );
** collection, by simply walking the masterpointer area. Not terribly safe
**
*/

extern void CallbackForAllBags(
void (*func)(Bag) );
#ifdef USE_GASMAN
extern void CallbackForAllBags( void (*func)(Bag) );
#endif


#if !defined(USE_GASMAN)
Expand Down
11 changes: 9 additions & 2 deletions src/opers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1799,6 +1799,8 @@ Obj CallHandleMethodNotFound( Obj oper,
**
*/

#ifdef USE_GASMAN

static Obj FLUSH_ALL_METHOD_CACHES;

static Int NextTypeID;
Expand All @@ -1822,6 +1824,8 @@ Obj FuncCOMPACT_TYPE_IDS( Obj self )
return INTOBJ_INT(NextTypeID);
}

#endif

/****************************************************************************
**
*F DoOperation<N>Args( <oper>, ... ) . . . . . . . . . . Operation Handlers
Expand Down Expand Up @@ -4142,7 +4146,9 @@ static StructGVarFunc GVarFuncs [] = {
GVAR_FUNC(DO_NOTHING_SETTER, 2, "obj, val"),
GVAR_FUNC(IS_AND_FILTER, 1, "filter"),
GVAR_FUNC(IS_CONSTRUCTOR, 1, "x"),
#ifdef USE_GASMAN
GVAR_FUNC(COMPACT_TYPE_IDS, 0, ""),
#endif
GVAR_FUNC(OPER_TO_ATTRIBUTE, 1, "oper"),
GVAR_FUNC(OPER_TO_MUTABLE_ATTRIBUTE, 1, "oper"),
{ 0, 0, 0, 0, 0 }
Expand All @@ -4158,7 +4164,6 @@ static Int InitKernel (
StructInitInfo * module )
{

NextTypeID = 0;
CountFlags = 0;

InitGlobalBag( &StringFilterSetter, "src/opers.c:StringFilterSetter" );
Expand Down Expand Up @@ -4333,9 +4338,11 @@ static Int InitKernel (
ImportFuncFromLibrary( "RESET_FILTER_OBJ", &RESET_FILTER_OBJ );

ImportFuncFromLibrary( "HANDLE_METHOD_NOT_FOUND", &HandleMethodNotFound );
ImportGVarFromLibrary( "IsType", &IsType );

#ifdef USE_GASMAN
ImportGVarFromLibrary( "IsType", &IsType );
ImportFuncFromLibrary( "FLUSH_ALL_METHOD_CACHES", &FLUSH_ALL_METHOD_CACHES );
#endif

/* init filters and functions */
InitHdlrFiltsFromTable( GVarFilts );
Expand Down
38 changes: 10 additions & 28 deletions src/saveload.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,34 +341,6 @@ Obj LoadSubObj( void )
#endif
}

void SaveHandler( ObjFunc hdlr )
{
const Char * cookie;
if (hdlr == (ObjFunc)0)
SaveCStr("");
else
{
cookie = CookieOfHandler(hdlr);
if (!cookie)
{
Pr("No cookie for Handler -- workspace will be corrupt\n",0,0);
SaveCStr("");
}
SaveCStr(cookie);
}
}


ObjFunc LoadHandler( void )
{
Char buf[256];
LoadCStr(buf, 256);
if (buf[0] == '\0')
return (ObjFunc) 0;
else
return HandlerOfCookie(buf);
}


/***************************************************************************
**
Expand Down Expand Up @@ -475,6 +447,8 @@ static void CheckEndiannessMarker( void )
** FuncBagStats
*/

#ifdef USE_GASMAN

static FILE *file;

static void report( Bag bag)
Expand All @@ -490,6 +464,9 @@ Obj FuncBagStats(Obj self, Obj filename)
return (Obj) 0;
}

#endif


/***************************************************************************
**
** Find Bags -- a useful debugging tool -- scan for a bag of specified
Expand All @@ -498,6 +475,7 @@ Obj FuncBagStats(Obj self, Obj filename)
** a functions body.
*/

#ifdef USE_GASMAN

static UInt fb_minsize, fb_maxsize, fb_tnum;
static Bag hit;
Expand All @@ -521,6 +499,8 @@ Obj FuncFindBag( Obj self, Obj minsize, Obj maxsize, Obj tnum )
return (hit != (Bag) 0) ? hit : Fail;
}

#endif


/***************************************************************************
**
Expand Down Expand Up @@ -942,8 +922,10 @@ static StructGVarFunc GVarFuncs [] = {

GVAR_FUNC(SaveWorkspace, 1, "fname"),
GVAR_FUNC(DumpWorkspace, 1, "fname"),
#ifdef USE_GASMAN
GVAR_FUNC(FindBag, 3, "minsize, maxsize, tnum"),
GVAR_FUNC(BagStats, 1, "filename"),
#endif
{ 0, 0, 0, 0, 0 }

};
Expand Down
2 changes: 0 additions & 2 deletions src/saveload.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ extern void SaveCStr(const Char *s);
extern void SaveString(Obj string);
extern void LoadString(Obj string);
extern void SaveSubObj(Obj o);
extern void SaveHandler(ObjFunc hdlr);

extern UInt1 LoadUInt1( void );
extern UInt2 LoadUInt2( void );
Expand All @@ -57,7 +56,6 @@ extern UInt8 LoadUInt8( void);
#endif
extern void LoadCStr(Char *buf, UInt maxlen );
extern Obj LoadSubObj( void );
extern ObjFunc LoadHandler();



Expand Down

0 comments on commit 26cd0bf

Please sign in to comment.