Skip to content

Commit

Permalink
kernel: let NAMI_FUNC, NAME_{L,H}VAR* return GAP strings
Browse files Browse the repository at this point in the history
... instead of pointers into those GAP strings, which could move during
a garbage collection
  • Loading branch information
fingolfin committed Apr 10, 2018
1 parent 6f96e15 commit d15a5d7
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 39 deletions.
8 changes: 4 additions & 4 deletions src/calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ void SET_NAME_FUNC(Obj func, Obj name)
FUNC(func)->name = name;
}

Char * NAMI_FUNC(Obj func, Int i)
Obj NAMI_FUNC(Obj func, Int i)
{
return CSTR_STRING(ELM_LIST(NAMS_FUNC(func),i));
return ELM_LIST(NAMS_FUNC(func),i);
}


Expand Down Expand Up @@ -1364,7 +1364,7 @@ void PrintFunction (
}
#endif
if ( NAMS_FUNC(func) != 0 )
Pr( "%I", (Int)NAMI_FUNC( func, (Int)i ), 0L );
Pr( "%H", (Int)NAMI_FUNC( func, (Int)i ), 0L );
else
Pr( "<<arg-%d>>", (Int)i, 0L );
if(isvarg && i == narg) {
Expand All @@ -1382,7 +1382,7 @@ void PrintFunction (
Pr("%>local ",0L,0L);
for ( i = 1; i <= nloc; i++ ) {
if ( NAMS_FUNC(func) != 0 )
Pr( "%I", (Int)NAMI_FUNC( func, (Int)(narg+i) ), 0L );
Pr( "%H", (Int)NAMI_FUNC( func, (Int)(narg+i) ), 0L );
else
Pr( "<<loc-%d>>", (Int)i, 0L );
if ( i != nloc ) Pr("%<, %>",0L,0L);
Expand Down
2 changes: 1 addition & 1 deletion src/calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ static inline Obj NAMS_FUNC(Obj func)
return CONST_FUNC(func)->namesOfLocals;
}

extern Char * NAMI_FUNC(Obj func, Int i);
extern Obj NAMI_FUNC(Obj func, Int i);

static inline Obj PROF_FUNC(Obj func)
{
Expand Down
14 changes: 7 additions & 7 deletions src/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -743,10 +743,10 @@ void Emit (
Pr( "t_%d", TEMP_CVAR(cvar), 0L );
}
else if ( LVAR_CVAR(cvar) <= narg ) {
Emit( "a_%n", NAME_LVAR( LVAR_CVAR(cvar) ) );
Emit( "a_%n", CSTR_STRING( NAME_LVAR( LVAR_CVAR(cvar) ) ) );
}
else {
Emit( "l_%n", NAME_LVAR( LVAR_CVAR(cvar) ) );
Emit( "l_%n", CSTR_STRING( NAME_LVAR( LVAR_CVAR(cvar) ) ) );
}
}

Expand All @@ -760,10 +760,10 @@ void Emit (
Pr( "INT_INTOBJ(t_%d)", TEMP_CVAR(cvar), 0L );
}
else if ( LVAR_CVAR(cvar) <= narg ) {
Emit( "INT_INTOBJ(a_%n)", NAME_LVAR( LVAR_CVAR(cvar) ) );
Emit( "INT_INTOBJ(a_%n)", CSTR_STRING( NAME_LVAR( LVAR_CVAR(cvar) ) ) );
}
else {
Emit( "INT_INTOBJ(l_%n)", NAME_LVAR( LVAR_CVAR(cvar) ) );
Emit( "INT_INTOBJ(l_%n)", CSTR_STRING( NAME_LVAR( LVAR_CVAR(cvar) ) ) );
}
}

Expand Down Expand Up @@ -814,11 +814,11 @@ void Emit (
*/
void CompCheckBound (
CVar obj,
Char * name )
Obj name )
{
if ( ! HasInfoCVar( obj, W_BOUND ) ) {
if ( CompCheckTypes ) {
Emit( "CHECK_BOUND( %c, \"%s\" )\n", obj, name );
Emit( "CHECK_BOUND( %c, \"%s\" )\n", obj, CSTR_STRING(name) );
}
SetInfoCVar( obj, W_BOUND );
}
Expand Down Expand Up @@ -2996,7 +2996,7 @@ CVar CompRefGVar (
Emit( "%c = GC_%n;\n", val, NameGVar(gvar) );

/* emit the code to check that the variable has a value */
CompCheckBound( val, NameGVar(gvar) );
CompCheckBound( val, NameGVarObj(gvar) );

/* return the value */
return val;
Expand Down
4 changes: 2 additions & 2 deletions src/intrprtr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2609,7 +2609,7 @@ void IntrRefLVar (
else {
while ((val = OBJ_LVAR(lvar))==0) {
ErrorReturnVoid(
"Variable: '%s' must have an assigned value",
"Variable: '%g' must have an assigned value",
(Int)NAME_LVAR( (UInt)( lvar )), 0L,
"you can 'return;' after assigning a value" );

Expand Down Expand Up @@ -2696,7 +2696,7 @@ void IntrRefHVar (
else {
while ((val = OBJ_HVAR(hvar))==0) {
ErrorReturnVoid(
"Variable: '%s' must have an assigned value",
"Variable: '%g' must have an assigned value",
(Int)NAME_HVAR( (UInt)( hvar )), 0L,
"you can 'return;' after assigning a value" );

Expand Down
31 changes: 14 additions & 17 deletions src/vars.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Obj ObjLVar (
Obj val; /* value result */
while ( (val = OBJ_LVAR(lvar)) == 0 ) {
ErrorReturnVoid(
"Variable: '%s' must have an assigned value",
"Variable: '%g' must have an assigned value",
(Int)NAME_LVAR( lvar ), 0L,
"you can 'return;' after assigning a value" );
}
Expand Down Expand Up @@ -179,7 +179,7 @@ void PrintAssLVar (
Stat stat )
{
Pr( "%2>", 0L, 0L );
Pr( "%I", (Int)NAME_LVAR( (UInt)(ADDR_STAT(stat)[0]) ), 0L );
Pr( "%H", (Int)NAME_LVAR( (UInt)(ADDR_STAT(stat)[0]) ), 0L );
Pr( "%< %>:= ", 0L, 0L );
PrintExpr( ADDR_EXPR(stat)[1] );
Pr( "%2<;", 0L, 0L );
Expand All @@ -189,7 +189,7 @@ void PrintUnbLVar (
Stat stat )
{
Pr( "Unbind( ", 0L, 0L );
Pr( "%I", (Int)NAME_LVAR( (UInt)(ADDR_STAT(stat)[0]) ), 0L );
Pr( "%H", (Int)NAME_LVAR( (UInt)(ADDR_STAT(stat)[0]) ), 0L );
Pr( " );", 0L, 0L );
}

Expand All @@ -203,14 +203,14 @@ void PrintUnbLVar (
void PrintRefLVar (
Expr expr )
{
Pr( "%I", (Int)NAME_LVAR( LVAR_REFLVAR(expr) ), 0L );
Pr( "%H", (Int)NAME_LVAR( LVAR_REFLVAR(expr) ), 0L );
}

void PrintIsbLVar (
Expr expr )
{
Pr( "IsBound( ", 0L, 0L );
Pr( "%I", (Int)NAME_LVAR( (UInt)(ADDR_EXPR(expr)[0]) ), 0L );
Pr( "%H", (Int)NAME_LVAR( (UInt)(ADDR_EXPR(expr)[0]) ), 0L );
Pr( " )", 0L, 0L );
}

Expand All @@ -225,7 +225,7 @@ void PrintIsbLVar (
**
** 'OBJ_HVAR' returns the value of the higher variable <hvar>.
**
** 'NAME_HVAR' returns the name of the higher variable <hvar> as a C string.
** 'NAME_HVAR' returns the name of the higher variable <hvar>.
*/
void ASS_HVAR(UInt hvar, Obj val)
{
Expand All @@ -237,7 +237,7 @@ Obj OBJ_HVAR(UInt hvar)
return OBJ_HVAR_WITH_CONTEXT(STATE(CurrLVars), hvar);
}

Char * NAME_HVAR(UInt hvar)
Obj NAME_HVAR(UInt hvar)
{
return NAME_HVAR_WITH_CONTEXT(STATE(CurrLVars), hvar);
}
Expand Down Expand Up @@ -268,18 +268,15 @@ Obj OBJ_HVAR_WITH_CONTEXT(Obj context, UInt hvar)
return val;
}

Char * NAME_HVAR_WITH_CONTEXT(Obj context, UInt hvar)
Obj NAME_HVAR_WITH_CONTEXT(Obj context, UInt hvar)
{
// walk up the environment chain to the correct values bag
for (UInt i = 1; i <= (hvar >> 16); i++) {
context = ENVI_FUNC(FUNC_LVARS(context));
}

// get the name
Char * name = NAME_LVAR_WITH_CONTEXT(context, hvar & 0xFFFF);

// return the name
return name;
return NAME_LVAR_WITH_CONTEXT(context, hvar & 0xFFFF);
}


Expand Down Expand Up @@ -331,7 +328,7 @@ Obj EvalRefHVar (
if ( (val = OBJ_HVAR( (UInt)(ADDR_EXPR(expr)[0]) )) == 0 ) {
while ( (val = OBJ_HVAR( (UInt)(ADDR_EXPR(expr)[0]) )) == 0 ) {
ErrorReturnVoid(
"Variable: '%s' must have an assigned value",
"Variable: '%g' must have an assigned value",
(Int)NAME_HVAR( (UInt)(ADDR_EXPR(expr)[0]) ), 0L,
"you can 'return;' after assigning a value" );
}
Expand Down Expand Up @@ -364,7 +361,7 @@ void PrintAssHVar (
Stat stat )
{
Pr( "%2>", 0L, 0L );
Pr( "%I", (Int)NAME_HVAR( (UInt)(ADDR_STAT(stat)[0]) ), 0L );
Pr( "%H", (Int)NAME_HVAR( (UInt)(ADDR_STAT(stat)[0]) ), 0L );
Pr( "%< %>:= ", 0L, 0L );
PrintExpr( ADDR_EXPR(stat)[1] );
Pr( "%2<;", 0L, 0L );
Expand All @@ -374,7 +371,7 @@ void PrintUnbHVar (
Stat stat )
{
Pr( "Unbind( ", 0L, 0L );
Pr( "%I", (Int)NAME_HVAR( (UInt)(ADDR_STAT(stat)[0]) ), 0L );
Pr( "%H", (Int)NAME_HVAR( (UInt)(ADDR_STAT(stat)[0]) ), 0L );
Pr( " );", 0L, 0L );
}

Expand All @@ -388,14 +385,14 @@ void PrintUnbHVar (
void PrintRefHVar (
Expr expr )
{
Pr( "%I", (Int)NAME_HVAR( (UInt)(ADDR_EXPR(expr)[0]) ), 0L );
Pr( "%H", (Int)NAME_HVAR( (UInt)(ADDR_EXPR(expr)[0]) ), 0L );
}

void PrintIsbHVar (
Expr expr )
{
Pr( "IsBound( ", 0L, 0L );
Pr( "%I", (Int)NAME_HVAR( (UInt)(ADDR_EXPR(expr)[0]) ), 0L );
Pr( "%H", (Int)NAME_HVAR( (UInt)(ADDR_EXPR(expr)[0]) ), 0L );
Pr( " )", 0L, 0L );
}

Expand Down
16 changes: 8 additions & 8 deletions src/vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ static inline void SwitchToOldLVarsAndFree(Obj old, const char *file, int line)
**
*F NAME_LVAR( <lvar> ) . . . . . . . . . . . . . . . name of local variable
**
** 'NAME_LVAR' returns the name of the local variable <lvar> as a C string.
** 'NAME_LVAR' returns the name of the local variable <lvar>.
*/
#define NAME_LVAR(lvar) NAMI_FUNC( CURR_FUNC(), lvar )
#define NAME_LVAR_WITH_CONTEXT(context,lvar) NAMI_FUNC( FUNC_LVARS(context), lvar )
Expand All @@ -322,15 +322,15 @@ extern Obj ObjLVar (
**
** 'OBJ_HVAR' returns the value of the higher variable <hvar>.
**
** 'NAME_HVAR' returns the name of the higher variable <hvar> as a C string.
** 'NAME_HVAR' returns the name of the higher variable <hvar>.
*/
extern void ASS_HVAR(UInt hvar, Obj val);
extern Obj OBJ_HVAR(UInt hvar);
extern Char * NAME_HVAR(UInt hvar);
extern void ASS_HVAR(UInt hvar, Obj val);
extern Obj OBJ_HVAR(UInt hvar);
extern Obj NAME_HVAR(UInt hvar);

extern void ASS_HVAR_WITH_CONTEXT(Obj context, UInt hvar, Obj val);
extern Obj OBJ_HVAR_WITH_CONTEXT(Obj context, UInt hvar);
extern Char * NAME_HVAR_WITH_CONTEXT(Obj context, UInt hvar);
extern void ASS_HVAR_WITH_CONTEXT(Obj context, UInt hvar, Obj val);
extern Obj OBJ_HVAR_WITH_CONTEXT(Obj context, UInt hvar);
extern Obj NAME_HVAR_WITH_CONTEXT(Obj context, UInt hvar);


/****************************************************************************
Expand Down

0 comments on commit d15a5d7

Please sign in to comment.