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

Make the assertion level (which controls Assert statements) thread local when using HPC-GAP #3822

Merged

Conversation

fingolfin
Copy link
Member

... by moving CurrentAssertionLevel to the kernel, into the GAPState.

While at it, also validate the level argument given to Assert(), and error out if it is not a non-negative small integer.

Also fix a potential issue in gac where INT_INTOBJ was called on inputs without validation; we now use Int_ObjInt instead, which produces an error if the input is not a small integer.

Resolves #3821

@fingolfin fingolfin added topic: HPC-GAP Issues and PRs related to HPC-GAP topic: kernel release notes: to be added PRs introducing changes that should be (but have not yet been) mentioned in the release notes labels Jan 1, 2020
@fingolfin fingolfin force-pushed the mh/CurrentAssertionLevel branch 2 times, most recently from e24b3a9 to 50ad246 Compare January 2, 2020 09:02
@ChrisJefferson
Copy link
Contributor

One first comment, That INT_INTOBJ -> Int_ObjInt change I like, but I'd like it in a separate commit (either in this PR, or seperately).

Last time I edited this code I left the GAP-level CurrentAssertionLevel, because I was worried someone might be using it. Any code which was using it will now silently just change a GAP global variable without doing anything, which slightly worries me.

Could we instead just make the variable thread-local at the GAP level?

@fingolfin
Copy link
Member Author

@ChrisJefferson split into two commits (good idea, thanks). Making CurrentAssertionLevel into a GAP visible TLS variable would have substantially complicated the code. Instead, I chose to BindConstant it to the value false. This way, any attempts to modify it, or to compare it integers, will raise an error.


static Obj FuncAssertionLevel(Obj self)
{
return INTOBJ_INT(STATE(CurrentAssertionLevel));
Copy link
Member Author

Choose a reason for hiding this comment

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

BTW, placing these into gap.c was somewhat arbitrary. If somebody has a preference for another location, let me know.

@@ -12,6 +12,8 @@ gap> f('x');
Error, Range: <last> must be a small integer (not a character)

# test Assert with two arguments
gap> function() Assert(fail, 0); end();
Error, Assert: <lev> must be a small integer (not the value 'fail')
Copy link
Member Author

Choose a reason for hiding this comment

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

For the record, I am using <lev> here as that matches what the documentation for Assert calls that argument (that's my general rule for the name of the arguments in error messages). I am fine with changing it here, e.g. to level, but IMHO it then should be changed in the documentation as well.

Fix a potential issue in gac where `INT_INTOBJ` was called on inputs without
validation; this could lead to unexpected behavior. We now use `Int_ObjInt`
instead, which raises an error if the input is not a small integer.
... by moving CurrentAssertionLevel to the kernel, into the GAPState.

While at it, also validate the level argument given to Assert(), and error out
if it is not a non-negative small integer.

While no code should have ever directly accessed CurrentAssertionLevel, there
is a minimal chance that some legacy code somewhere does this. To make sure it
suddenly runs with an incorrect assertion level without anybody noticing, we
keep defining CurrentAssertionLevel, but as a constant bound to `false`. This
way, any code trying to modify it, or to compare it against an integer, will
run into an error.
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.0004%) to 84.702% when pulling c17e62f on fingolfin:mh/CurrentAssertionLevel into 4e0a1c0 on gap-system:master.

@ChrisJefferson ChrisJefferson merged commit 056e7d5 into gap-system:master Jan 5, 2020
@fingolfin fingolfin deleted the mh/CurrentAssertionLevel branch January 6, 2020 07:20
@ThomasBreuer ThomasBreuer self-assigned this Feb 17, 2021
@ThomasBreuer ThomasBreuer added release notes: added PRs introducing changes that have since been mentioned in the release notes and removed release notes: to be added PRs introducing changes that should be (but have not yet been) mentioned in the release notes labels Feb 17, 2021
@ThomasBreuer ThomasBreuer removed their assignment Feb 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release notes: added PRs introducing changes that have since been mentioned in the release notes topic: HPC-GAP Issues and PRs related to HPC-GAP topic: kernel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make CurrentAssertionLevel thread local
4 participants