Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ void SET_NAME_FUNC(Obj func, Obj name)
FUNC(func)->name = name;
}

Obj NAMI_OBJ_FUNC(Obj func, Int i)
{
return ELM_LIST(NAMS_FUNC(func),i);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to not do this, let's instead change NAMI_FUNC, NAME_LVAR, etc to return a GAP string, to fix a ton of additional identical problems not yet covered by this PR.

I just sat down (during vacation, yes...) and had a quick look, it shouldn't be a problem, and no package calls these, either. Might even be able to do this for NAME_RNAM and NameGVar, too

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


Expand Down
4 changes: 4 additions & 0 deletions src/calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ typedef Obj (* ObjFunc_6ARGS) (Obj self, Obj a1, Obj a2, Obj a3, Obj a4, Obj a5,
**
** 'NAMI_FUNC(<func>,<i>)' is the name of the <i>-th local variable.
**
** 'NAMI_OBJ_FUNC(<func>,<i>)' is the name of the <i>-th local variable
** as a GAP string
**
** 'PROF_FUNC(<func>)' is the profiling information bag.
**
** 'NLOC_FUNC(<func>)' is the number of local variables of the interpreted
Expand Down Expand Up @@ -155,6 +158,7 @@ static inline Obj NAMS_FUNC(Obj func)
}

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

static inline Obj PROF_FUNC(Obj func)
{
Expand Down
4 changes: 2 additions & 2 deletions src/gvars.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,8 @@ Obj ValAutoGVar (
/* if this is still an automatic variable, this is an error */
while ( (val = ValGVar(gvar)) == 0 ) {
ErrorReturnVoid(
"Variable: automatic variable '%s' must get a value by function call",
(Int)NameGVar(gvar), 0L,
"Variable: automatic variable '%g' must get a value by function call",
(Int)NameGVarObj(gvar), 0L,
"you can 'return;' after assigning a value" );
}

Expand Down
4 changes: 2 additions & 2 deletions src/hpc/aobjects.c
Original file line number Diff line number Diff line change
Expand Up @@ -1161,8 +1161,8 @@ static Obj FuncSET_ATOMIC_RECORD(Obj self, Obj record, Obj field, Obj value)
fieldname = RNamName(CSTR_STRING(field));
result = SetARecordField(record, fieldname, value);
if (!result)
ErrorQuit("SET_ATOMIC_RECORD: Field '%s' already exists",
(UInt) CSTR_STRING(field), 0L);
ErrorQuit("SET_ATOMIC_RECORD: Field '%g' already exists",
(UInt)field, 0L);
return result;
}

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

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

}
Expand Down
20 changes: 15 additions & 5 deletions src/vars.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ Obj ObjLVar (
Obj val; /* value result */
while ( (val = OBJ_LVAR(lvar)) == 0 ) {
ErrorReturnVoid(
"Variable: '%s' must have an assigned value",
(Int)NAME_LVAR( lvar ), 0L,
"Variable: '%g' must have an assigned value",
(Int)NAME_OBJ_LVAR( lvar ), 0L,
"you can 'return;' after assigning a value" );
}
return val;
Expand Down Expand Up @@ -237,6 +237,11 @@ Obj OBJ_HVAR(UInt hvar)
return OBJ_HVAR_WITH_CONTEXT(STATE(CurrLVars), hvar);
}

Obj NAME_OBJ_HVAR(UInt hvar)
{
return NAME_OBJ_HVAR_WITH_CONTEXT(STATE(CurrLVars), hvar);
}

Char * NAME_HVAR(UInt hvar)
{
return NAME_HVAR_WITH_CONTEXT(STATE(CurrLVars), hvar);
Expand Down Expand Up @@ -269,14 +274,19 @@ Obj OBJ_HVAR_WITH_CONTEXT(Obj context, UInt hvar)
}

Char * NAME_HVAR_WITH_CONTEXT(Obj context, UInt hvar)
{
return CSTR_STRING(NAME_OBJ_HVAR_WITH_CONTEXT(context, hvar));
}

Obj NAME_OBJ_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);
Obj name = NAME_OBJ_LVAR_WITH_CONTEXT(context, hvar & 0xFFFF);

// return the name
return name;
Expand Down Expand Up @@ -331,8 +341,8 @@ 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",
(Int)NAME_HVAR( (UInt)(ADDR_EXPR(expr)[0]) ), 0L,
"Variable: '%g' must have an assigned value",
(Int)NAME_OBJ_HVAR( (UInt)(ADDR_EXPR(expr)[0]) ), 0L,
"you can 'return;' after assigning a value" );
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,15 @@ static inline void SwitchToOldLVarsAndFree(Obj old, const char *file, int line)
/****************************************************************************
**
*F NAME_LVAR( <lvar> ) . . . . . . . . . . . . . . . name of local variable
*F NAME_OBJ_LVAR( <lvar> ) . . . . . . name of local variable as GAP string
**
** 'NAME_LVAR' returns the name of the local variable <lvar> as a C string.
** 'NAME_OBJ_LVAR' acts like 'NAME_LVAR' but returns a GAP string.
*/
#define NAME_LVAR(lvar) NAMI_FUNC( CURR_FUNC(), lvar )
#define NAME_OBJ_LVAR(lvar) NAMI_OBJ_FUNC( CURR_FUNC(), lvar )
#define NAME_LVAR_WITH_CONTEXT(context,lvar) NAMI_FUNC( FUNC_LVARS(context), lvar )
#define NAME_OBJ_LVAR_WITH_CONTEXT(context,lvar) NAMI_OBJ_FUNC( FUNC_LVARS(context), lvar )


/****************************************************************************
Expand All @@ -317,20 +321,25 @@ extern Obj ObjLVar (
*F ASS_HVAR(<hvar>,<val>) . . . . . . . . . . . assign to a higher variable
*F OBJ_HVAR(<hvar>) . . . . . . . . . . . . . . value of a higher variable
*F NAME_HVAR(<hvar>) . . . . . . . . . . . . . . . name of a higher variable
*F NAME_OBJ_HVAR(<hvar>) . . . . . name of a higher variable as a GAP string
**
** 'ASS_HVAR' assigns the value <val> to the higher variable <hvar>.
**
** '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_OBJ_HVAR' returns the name of the higher variable <hvar> as a GAP
** string.
*/
extern void ASS_HVAR(UInt hvar, Obj val);
extern Obj OBJ_HVAR(UInt hvar);
extern Obj NAME_OBJ_HVAR(UInt hvar);
extern Char * 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 Obj NAME_OBJ_HVAR_WITH_CONTEXT(Obj context, UInt hvar);


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