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

Prevent blist functions from modifying immutable blists (and several other kernel tweaks leading up to this) #3392

Merged
merged 6 commits into from
Apr 10, 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
215 changes: 101 additions & 114 deletions src/blister.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ void ErrorMayQuit(const Char * msg, Int arg1, Int arg2)
void CheckIsPossList(const Char * desc, Obj poss)
{
if ( ! IS_POSS_LIST( poss ) ) {
ErrorMayQuit("%s: <positions> must be a dense list of positive integers",
ErrorMayQuit("%s: <poss> must be a dense list of positive integers",
(Int)desc, 0 );
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/intrprtr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2894,7 +2894,7 @@ void IntrAsssList ( void )
/* get and check the positions */
poss = PopObj();
CheckIsPossList("List Assignments", poss);
CheckSameLength("List Assignments", "rhss", "positions", rhss, poss);
RequireSameLength("List Assignments", rhss, poss);

/* get the list (checking is done by 'ASSS_LIST') */
list = PopObj();
Expand Down
6 changes: 3 additions & 3 deletions src/lists.c
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ void AsssListDefault (

CheckIsPossList("List Assignments", poss);
CheckIsDenseList("List Assignments", "rhss", objs);
CheckSameLength("List Assignments", "rhss", "positions", objs, poss);
CheckSameLength("List Assignments", "rhss", "poss", objs, poss);

/* general code */
if ( ! IS_RANGE(poss) ) {
Expand Down Expand Up @@ -1658,7 +1658,7 @@ void AsssListLevel (
/* select the elements to assign */
obj = ELMW_LIST( objs, i );
CheckIsDenseList("List Assignments", "objs", obj);
CheckSameLength("List Assignments", "objs", "positions", obj, poss);
CheckSameLength("List Assignments", "objs", "poss", obj, poss);

/* assign the elements */
ASSS_LIST( list, poss, obj );
Expand Down Expand Up @@ -1871,7 +1871,7 @@ void AsssListCheck (
{
CheckIsPossList("List Assignments", poss);
RequireDenseList("List Assignments", rhss);
CheckSameLength("List Assignments", "rhss", "positions", rhss, poss);
RequireSameLength("List Assignments", rhss, poss);
ASSS_LIST( list, poss, rhss );
}

Expand Down
2 changes: 1 addition & 1 deletion src/vars.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ static UInt ExecAsssList(Expr stat)
/* evaluate and check right hand sides */
rhss = EVAL_EXPR(READ_STAT(stat, 2));
RequireDenseList("List Assignments", rhss);
CheckSameLength("List Assignments", "rhss", "positions", rhss, poss);
RequireSameLength("List Assignments", rhss, poss);

/* assign the right hand sides to several elements of the list */
ASSS_LIST( list, poss, rhss );
Expand Down
37 changes: 36 additions & 1 deletion tst/testinstall/kernel/blister.tst
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ gap> IsPositionsList(d);
false
gap> x:=[1,2,3];;
gap> x{a};
Error, List Elements: <positions> must be a dense list of positive integers
Error, List Elements: <poss> must be a dense list of positive integers

# IsHomogBlist
gap> List(l, IsHomogeneousList);
Expand Down Expand Up @@ -150,6 +150,11 @@ gap> UniteBlist([true,false,true], [true,false]);
Error, UniteBlist: <blist1> must have the same length as <blist2> (lengths are\
3 and 2)
gap> x:= [false,true,true,false];;
gap> UniteBlist(Immutable(x), [true,true,false,false]);
Error, UniteBlist: <blist1> must be a mutable boolean list (not a list (boolea\
n,imm))
gap> x;
[ false, true, true, false ]
gap> UniteBlist(x, [true,true,false,false]);
gap> x;
[ true, true, true, false ]
Expand All @@ -165,6 +170,11 @@ e 1 and 2)
gap> UniteBlistList([1,2], [true,false], fail);
Error, UniteBlistList: <sub> must be a small list (not the value 'fail')
gap> x:= [true,true,false];;
gap> UniteBlistList([1,2,3], Immutable(x), [2,3]);
Error, UniteBlistList: <blist> must be a mutable boolean list (not a list (boo\
lean,imm))
gap> x;
[ true, true, false ]
gap> UniteBlistList([1,2,3], x, [2,3]);
gap> x;
[ true, true, true ]
Expand All @@ -178,6 +188,11 @@ gap> IntersectBlist([true,false,true], [true,false]);
Error, IntersectBlist: <blist1> must have the same length as <blist2> (lengths\
are 3 and 2)
gap> x:= [false,true,true,false];;
gap> IntersectBlist(Immutable(x), [true,true,false,false]);
Error, IntersectBlist: <blist1> must be a mutable boolean list (not a list (bo\
olean,imm))
gap> x;
[ false, true, true, false ]
gap> IntersectBlist(x, [true,true,false,false]);
gap> x;
[ false, true, false, false ]
Expand All @@ -191,6 +206,11 @@ gap> SubtractBlist([true,false,true], [true,false]);
Error, SubtractBlist: <blist1> must have the same length as <blist2> (lengths \
are 3 and 2)
gap> x:= [false,true,true,false];;
gap> SubtractBlist(Immutable(x), [true,true,false,false]);
Error, SubtractBlist: <blist1> must be a mutable boolean list (not a list (boo\
lean,imm))
gap> x;
[ false, true, true, false ]
gap> SubtractBlist(x, [true,true,false,false]);
gap> x;
[ false, false, true, false ]
Expand All @@ -213,6 +233,11 @@ false
gap> FLIP_BLIST(fail);
Error, FlipBlist: <blist> must be a boolean list (not the value 'fail')
gap> x:= [false,true,true,false];;
gap> FlipBlist(Immutable(x));
Error, FlipBlist: <blist> must be a mutable boolean list (not a list (boolean,\
imm))
gap> x;
[ false, true, true, false ]
gap> FLIP_BLIST(x);
gap> x;
[ true, false, false, true ]
Expand All @@ -232,6 +257,11 @@ gap> for i in [0..200] do
gap> SET_ALL_BLIST(fail);
Error, SetAllBitsBlist: <blist> must be a boolean list (not the value 'fail')
gap> x:= [false,true,true,false];;
gap> SET_ALL_BLIST(Immutable(x));
Error, SetAllBitsBlist: <blist> must be a mutable boolean list (not a list (bo\
olean,imm))
gap> x;
[ false, true, true, false ]
gap> SET_ALL_BLIST(x);
gap> x;
[ true, true, true, true ]
Expand All @@ -250,6 +280,11 @@ gap> CLEAR_ALL_BLIST(fail);
Error, ClearAllBitsBlist: <blist> must be a boolean list (not the value 'fail'\
)
gap> x:= [false,true,true,false];;
gap> CLEAR_ALL_BLIST(Immutable(x));
Error, ClearAllBitsBlist: <blist> must be a mutable boolean list (not a list (\
boolean,imm))
gap> x;
[ false, true, true, false ]
gap> CLEAR_ALL_BLIST(x);
gap> x;
[ false, false, false, false ]
Expand Down
8 changes: 4 additions & 4 deletions tst/testinstall/kernel/lists.tst
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ Error, List Element: <list> must be a list (not the integer 1)

#
gap> ELMS_LIST(1,1);
Error, List Elements: <positions> must be a dense list of positive integers
Error, List Elements: <poss> must be a dense list of positive integers
gap> ELMS_LIST([1],1);
Error, List Elements: <positions> must be a dense list of positive integers
Error, List Elements: <poss> must be a dense list of positive integers
gap> ELMS_LIST([1],[2]);
Error, List Elements: <list>[2] must have an assigned value
gap> ELMS_LIST([1,2,3],[1,3]);
Expand Down Expand Up @@ -105,7 +105,7 @@ gap> l:=[];; ASS_LIST(l,1,1); l;
gap> ASSS_LIST([1],[1],1);
Error, List Assignments: <rhss> must be a dense list (not the integer 1)
gap> ASSS_LIST([1],1,[1]);
Error, List Assignments: <positions> must be a dense list of positive integers
Error, List Assignments: <poss> must be a dense list of positive integers
gap> ASSS_LIST(1,[1],[1]);
Error, List Assignments: <list> must be a list (not the integer 1)
gap> l:=[];; ASSS_LIST(l,[1],[1]); l;
Expand All @@ -115,7 +115,7 @@ gap> l:=[];; ASSS_LIST(l,[1],[1]); l;
gap> ASSS_LIST_DEFAULT([1],[1],1);
Error, List Assignments: <rhss> must be a dense list
gap> ASSS_LIST_DEFAULT([1],1,[1]);
Error, List Assignments: <positions> must be a dense list of positive integers
Error, List Assignments: <poss> must be a dense list of positive integers
gap> ASSS_LIST_DEFAULT(1,[1],[1]);
Error, List Assignments: <list> must be a list (not the integer 1)
gap> l:=[];; ASSS_LIST_DEFAULT(l,[1],[1]); l;
Expand Down
18 changes: 9 additions & 9 deletions tst/testinstall/list.tst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ gap> a{[1]}{[1]}[1];
gap> a{[1,,2]}:=1;
Error, List Assignments: <rhss> must be a dense list (not the integer 1)
gap> a{[1,,2]}:=[1,2];
Error, List Assignments: <positions> must be a dense list of positive integers
Error, List Assignments: <poss> must be a dense list of positive integers

#
gap> a{[1]}{[1]}[1] := 42;
Expand All @@ -66,10 +66,10 @@ gap> a{[1]}{[1]} := [ 18, 19 ];
Error, List Assignments: <objs> must have the same length as <lists> (lengths \
are 2 and 1)
gap> a{[1]}{[1]} := [ [ 18, 19 ] ] ;
Error, List Assignments: <objs> must have the same length as <positions> (leng\
ths are 2 and 1)
Error, List Assignments: <objs> must have the same length as <poss> (lengths a\
re 2 and 1)
gap> a{[1]}{[1,,3]} := [ [ [ 18, 19 ] ] ];
Error, List Assignments: <positions> must be a dense list of positive integers
Error, List Assignments: <poss> must be a dense list of positive integers
gap> a{[1]}{[1]} := [ [ [ 18, 19 ] ] ];
[ [ [ 18, 19 ] ] ]
gap> a;
Expand Down Expand Up @@ -99,12 +99,12 @@ Unbind(a[1,1,1]);
# slices
#
gap> 1{1};
Error, List Elements: <positions> must be a dense list of positive integers
Error, List Elements: <poss> must be a dense list of positive integers

# ... for blists
gap> list := [true,false,true];;
gap> list{1};
Error, List Elements: <positions> must be a dense list of positive integers
Error, List Elements: <poss> must be a dense list of positive integers
gap> list{[4]};
Error, List Elements: <list>[4] must have an assigned value
gap> list{[1,2,3]} = list; # with a plist as selector
Expand All @@ -121,7 +121,7 @@ Error, List Elements: <list>[4] must have an assigned value
# ... for plists
gap> list := [1, 2, 4];;
gap> list{1};
Error, List Elements: <positions> must be a dense list of positive integers
Error, List Elements: <poss> must be a dense list of positive integers
gap> list{[4]};
Error, List Elements: <list>[4] must have an assigned value
gap> list{[1,2,3]} = list; # with a plist as selector
Expand All @@ -138,7 +138,7 @@ Error, List Elements: <list>[4] must have an assigned value
# ... for ranges
gap> list := [1..3];;
gap> list{1};
Error, List Elements: <positions> must be a dense list of positive integers
Error, List Elements: <poss> must be a dense list of positive integers
gap> list{[4]};
Error, List Elements: <list>[4] must have an assigned value
gap> list{[1,2,3]} = list; # with a plist as selector
Expand All @@ -155,7 +155,7 @@ Error, List Elements: <list>[4] must have an assigned value
# ... for strings
gap> list := "abc";;
gap> list{1};
Error, List Elements: <positions> must be a dense list of positive integers
Error, List Elements: <poss> must be a dense list of positive integers
gap> list{[4]};
Error, List Elements: <list>[4] must have an assigned value
gap> list{[1,2,3]} = list; # with a plist as selector
Expand Down
6 changes: 3 additions & 3 deletions tst/testinstall/range.tst
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ gap> [-5,-3..5]{[2..3]};
gap> [-5,-3..5]{[2..4]};
[ -3, -1 .. 1 ]
gap> [-5,-3..5]{[0..7]};
Error, List Elements: <positions> must be a dense list of positive integers
Error, List Elements: <poss> must be a dense list of positive integers
gap> [-5,-3..5]{[1..7]};
Error, List Elements: <list>[7] must have an assigned value
gap> [-5,-3..5]{[1..6]};
Expand All @@ -106,8 +106,8 @@ gap> x{[2,5,3]} := [7,8,9];
gap> x;
[ -5, 7, 9, 1, 8, 5 ]
gap> x{[2,4]} := [2..4];
Error, List Assignments: <rhss> must have the same length as <positions> (leng\
ths are 3 and 2)
Error, List Assignments: <rhss> must have the same length as <poss> (lengths a\
re 3 and 2)
gap> Immutable([-5,-3..5]){[2..3]} := [2..3];
Error, List Assignments: <list> must be a mutable list
gap> x := [-5,-3..5];
Expand Down