Skip to content

Commit

Permalink
Added GAP_AssignGlobalVariable and GAP_IsNameOfWritableGlobalVariable
Browse files Browse the repository at this point in the history
to libgap-api
  • Loading branch information
sebasguts committed May 7, 2019
1 parent 1afd3f7 commit add07b8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/libgap-api.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ Obj GAP_ValueGlobalVariable(const char * name)
}
}

int GAP_IsNameOfWritableGlobalVariable(const char * name)
{
UInt gvar = GVarName(name);
return !(IsReadOnlyGVar(gvar) || IsConstantGVar(gvar));
}

void GAP_AssignGlobalVariable(const char * name, Obj value)
{
UInt gvar = GVarName(name);
AssGVar(gvar, value);
}

////
//// arithmetic
Expand Down
8 changes: 8 additions & 0 deletions src/libgap-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ Obj GAP_EvalString(const char * cmd);
// defined.
Obj GAP_ValueGlobalVariable(const char * name);

// Checks if <name> belongs to a writable GVar
int GAP_IsNameOfWritableGlobalVariable(const char * name);

// Combines GVarName and AssGVar. For a given <name> and <value>,
// it assigns <value> to the global <name>. The function may raise
// an error if <name> refers to a readonly variable.
void GAP_AssignGlobalVariable(const char * name, Obj value);


////
//// arithmetic
Expand Down
11 changes: 11 additions & 0 deletions tst/testlibgap/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,24 @@ void operations(void)
void globalvars(void)
{
Obj a;
int x;

a = GAP_ValueGlobalVariable("yaddayaddayadda");
assert(a == 0);

// Hopefully this always exists.
a = GAP_ValueGlobalVariable("GAPInfo");
assert(GAP_IsRecord(a) != 0);

x = GAP_IsNameOfWritableGlobalVariable("GAPInfo");
assert(x == 0);

x = GAP_IsNameOfWritableGlobalVariable("GAPInfo_copy");
assert(x != 0);

GAP_AssignGlobalVariable("GAPInfo_copy", a);
a = GAP_ValueGlobalVariable("GAPInfo_copy");
assert(a != 0);
}

int main(int argc, char ** argv)
Expand Down

0 comments on commit add07b8

Please sign in to comment.