Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LibGAP API: Add GAP_AssignGlobalVariable and GAP_CanAssignGlobalVariable #3438

Merged
merged 1 commit into from
May 11, 2019
Merged
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
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_CanAssignGlobalVariable(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
17 changes: 12 additions & 5 deletions src/libgap-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void GAP_Initialize(int argc,
//// program evaluation and execution
////

// Evaluate a string of GAP commands
// Evaluate a string of GAP commands.
//
// To see an example of how to use this function see tst/testlibgap/basic.c
//
Expand All @@ -175,11 +175,18 @@ Obj GAP_EvalString(const char * cmd);
//// variables
////

// Combines GVarName and ValGVar. For a given string, it returns the value
// of the gvar with name <name>, or NULL if the global variable is not
// defined.
// Returns the value of the global GAP variable with name <name>, or NULL if
// no global variable with this this name is defined.
Obj GAP_ValueGlobalVariable(const char * name);

// Checks if assigning to the global GAP variable <name> is possible, by
// verifying that <name> is not the name of a read-only or constant variable.
int GAP_CanAssignGlobalVariable(const char * name);

// Assign <value> to the global GAP variable <name>. If <name> is the name of
// a readonly or constant variable, an error is raised.
void GAP_AssignGlobalVariable(const char * name, Obj value);


////
//// arithmetic
Expand Down Expand Up @@ -278,7 +285,7 @@ int GAP_IsLargeInt(Obj obj);
// `integer.c`). The absolute value of <size> determines the number of limbs.
// If <size> is zero, then `INTOBJ_INT(0)` is returned. Otherwise, the sign
// of the returned integer object is determined by the sign of <size>.
// //
//
// Note that GAP automatically reduces and normalized the integer object,
// i.e., it will discard any leading zeros; and if the integer fits into a
// small integer, it will be returned as such.
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_CanAssignGlobalVariable("GAPInfo");
assert(x == 0);

x = GAP_CanAssignGlobalVariable("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