diff --git a/src/error.h b/src/error.h index 5d5309622c..66eba3c7d4 100644 --- a/src/error.h +++ b/src/error.h @@ -239,6 +239,14 @@ Obj RequireArgumentEx(const char * funcname, RequireArgumentCondition(funcname, op, op == True || op == False, \ "must be true or false") +/**************************************************************************** +** +*F RequireMutable +*/ +#define RequireMutable(funcname, op, type) \ + RequireArgumentCondition(funcname, op, IS_MUTABLE_OBJ(op), \ + "must be a mutable " type) + /**************************************************************************** ** diff --git a/src/listfunc.c b/src/listfunc.c index 0a6a69bd0f..1f7e3cb868 100644 --- a/src/listfunc.c +++ b/src/listfunc.c @@ -221,8 +221,7 @@ static Obj FuncAPPEND_LIST_INTR(Obj self, Obj list1, Obj list2) Int i; /* loop variable */ /* check the mutability of the first argument */ - if (!IS_MUTABLE_OBJ(list1)) - ErrorMayQuit("Append: must be a mutable list", 0, 0); + RequireMutable("Append", list1, "list"); /* handle the case of strings now */ diff --git a/src/lists.c b/src/lists.c index 13b5dfea73..5c8f14a834 100644 --- a/src/lists.c +++ b/src/lists.c @@ -863,16 +863,13 @@ void ASSB_LIST ( DoOperation3Args( AssListOper, list, pos, obj ); } -void ASS2_LIST(Obj list, Obj pos1, Obj pos2, Obj obj) +void ASS2_LIST(Obj mat, Obj pos1, Obj pos2, Obj obj) { - if (!IS_MUTABLE_OBJ(list)) { - ErrorMayQuit("Matrix Assignment: must be a mutable matrix", 0, - 0); - } - if (IS_POS_INTOBJ(pos1) && IS_POS_INTOBJ(pos2) && IS_PLIST(list)) { + RequireMutable("Matrix Assignment", mat, "matrix"); + if (IS_POS_INTOBJ(pos1) && IS_POS_INTOBJ(pos2) && IS_PLIST(mat)) { Int p1 = INT_INTOBJ(pos1); - if ( p1 <= LEN_PLIST(list) ) { - Obj row = ELM_PLIST( list, p1 ); + if (p1 <= LEN_PLIST(mat)) { + Obj row = ELM_PLIST(mat, p1); Int p2 = INT_INTOBJ(pos2); ASS_LIST( row, p2, obj ); @@ -880,7 +877,7 @@ void ASS2_LIST(Obj list, Obj pos1, Obj pos2, Obj obj) } } - DoOperation4Args( AssListOper, list, pos1, pos2, obj ); + DoOperation4Args(AssListOper, mat, pos1, pos2, obj); } diff --git a/src/vecgf2.c b/src/vecgf2.c index da1b6d0dea..2060c4e8ac 100644 --- a/src/vecgf2.c +++ b/src/vecgf2.c @@ -1845,11 +1845,7 @@ static Obj FuncELMS_GF2VEC(Obj self, Obj list, Obj poss) static Obj FuncASS_GF2VEC(Obj self, Obj list, Obj pos, Obj elm) { // check that is mutable - if (!IS_MUTABLE_OBJ(list)) { - ErrorReturnVoid("List Assignment: must be a mutable list", 0L, - 0L, "you can 'return;' and ignore the assignment"); - return 0; - } + RequireMutable("List Assignment", list, "list"); // get the position UInt p = GetSmallInt("ASS_GF2VEC", pos); @@ -1913,11 +1909,7 @@ static Obj FuncPLAIN_GF2MAT(Obj self, Obj list) static Obj FuncASS_GF2MAT(Obj self, Obj list, Obj pos, Obj elm) { // check that is mutable - if (!IS_MUTABLE_OBJ(list)) { - ErrorReturnVoid("List Assignment: must be a mutable list", 0L, - 0L, "you can 'return;' and ignore the assignment"); - return 0; - } + RequireMutable("List Assignment", list, "list"); // get the position UInt p = GetSmallInt("ASS_GF2MAT", pos); @@ -1984,11 +1976,7 @@ static Obj FuncELM_GF2MAT(Obj self, Obj mat, Obj row) static Obj FuncUNB_GF2VEC(Obj self, Obj list, Obj pos) { // check that is mutable - if (!IS_MUTABLE_OBJ(list)) { - ErrorReturnVoid("List Unbind: must be a mutable list", 0L, 0L, - "you can 'return;' and ignore the unbind"); - return 0; - } + RequireMutable("List Unbind", list, "vector"); if (DoFilter(IsLockedRepresentationVector, list) == True) { ErrorReturnVoid("Unbind forbidden on locked GF2 vector", 0L, 0L, @@ -2027,11 +2015,7 @@ static Obj FuncUNB_GF2VEC(Obj self, Obj list, Obj pos) static Obj FuncUNB_GF2MAT(Obj self, Obj list, Obj pos) { // check that is mutable - if (!IS_MUTABLE_OBJ(list)) { - ErrorReturnVoid("List Unbind: must be a mutable list", 0L, 0L, - "you can 'return;' and ignore the unbind"); - return 0; - } + RequireMutable("List Unbind", list, "matrix"); // get the position UInt p = GetSmallInt("UNB_GF2MAT", pos); @@ -2532,8 +2516,8 @@ static Obj FuncCOPY_SECTION_GF2VECS( if (ihowmany < 0 || ifrom + ihowmany - 1 > lens || ito + ihowmany - 1 > lend) ErrorMayQuit("Bad argument values", 0, 0); - if (!IS_MUTABLE_OBJ(dest)) - ErrorMayQuit("Immutable destination vector", 0, 0); + RequireMutable("COPY_SECTION_GF2VECS", dest, "vector"); + CopySection_GF2Vecs(src, dest, (UInt)ifrom, (UInt)ito, (UInt)ihowmany); return (Obj)0; } @@ -3381,11 +3365,8 @@ static void ResizeGF2Vec(Obj vec, UInt newlen) static Obj FuncRESIZE_GF2VEC(Obj self, Obj vec, Obj newlen) { Int newlen1; - if (!IS_MUTABLE_OBJ(vec)) { - ErrorReturnVoid("RESIZE_GF2VEC: the vector must be mutable", 0, 0, - "you may 'return;' to skip the operation"); - return (Obj)0; - } + RequireMutable("RESIZE_GF2VEC", vec, "vector"); + newlen1 = GetNonnegativeSmallInt("RESIZE_GF2VEC", newlen); ResizeGF2Vec(vec, newlen1); return (Obj)0; @@ -3445,11 +3426,8 @@ static void ShiftLeftGF2Vec(Obj vec, UInt amount) static Obj FuncSHIFT_LEFT_GF2VEC(Obj self, Obj vec, Obj amount) { Int amount1; - if (!IS_MUTABLE_OBJ(vec)) { - ErrorReturnVoid("SHIFT_LEFT_GF2VEC: the vector must be mutable", 0, 0, - "you may 'return;' to skip the operation"); - return (Obj)0; - } + RequireMutable("SHIFT_LEFT_GF2VEC", vec, "vector"); + amount1 = GetNonnegativeSmallInt("SHIFT_LEFT_GF2VEC", amount); ShiftLeftGF2Vec(vec, amount1); return (Obj)0; @@ -3513,11 +3491,8 @@ static void ShiftRightGF2Vec(Obj vec, UInt amount) static Obj FuncSHIFT_RIGHT_GF2VEC(Obj self, Obj vec, Obj amount) { Int amount1; - if (!IS_MUTABLE_OBJ(vec)) { - ErrorReturnVoid("SHIFT_RIGHT_GF2VEC: the vector must be mutable", 0, - 0, "you may 'return;' to skip the operation"); - return (Obj)0; - } + RequireMutable("SHIFT_RIGHT_GF2VEC", vec, "vector"); + amount1 = GetNonnegativeSmallInt("SHIFT_RIGHT_GF2VEC", amount); ShiftRightGF2Vec(vec, amount1); return (Obj)0; diff --git a/tst/testinstall/kernel/listfunc.tst b/tst/testinstall/kernel/listfunc.tst index 93e354297e..b006adf3f7 100644 --- a/tst/testinstall/kernel/listfunc.tst +++ b/tst/testinstall/kernel/listfunc.tst @@ -21,7 +21,7 @@ Error, Remove: must not be empty # gap> APPEND_LIST_INTR(fail, fail); -Error, Append: must be a mutable list +Error, Append: must be a mutable list (not the value 'fail') gap> APPEND_LIST_INTR(rec(), fail); Error, AppendList: must be a small list (not a record (plain)) diff --git a/tst/testinstall/listindex.tst b/tst/testinstall/listindex.tst index 3ce69f27e7..464b2f8448 100644 --- a/tst/testinstall/listindex.tst +++ b/tst/testinstall/listindex.tst @@ -201,11 +201,11 @@ gap> l := [];; Append(l,l); l; gap> l := [1,2,3,4];; Append(l,l); l; [ 1, 2, 3, 4, 1, 2, 3, 4 ] gap> Append(Immutable([1,2,3]), [1,2,3]); -Error, Append: must be a mutable list +Error, Append: must be a mutable list (not a list (plain,cyc,imm)) gap> Append([1,2,3], () ); Error, AppendList: must be a small list (not a permutation (small)) gap> Append( () , [1,2,3] ); -Error, Append: must be a mutable list +Error, Append: must be a mutable list (not a permutation (small)) gap> s; [ ] diff --git a/tst/testinstall/matblock.tst b/tst/testinstall/matblock.tst index b6920c6be3..511ba067cc 100644 --- a/tst/testinstall/matblock.tst +++ b/tst/testinstall/matblock.tst @@ -110,8 +110,15 @@ gap> tmp = MatrixByBlockMatrix(m2); true # block matrices are immutable +#@if IsHPCGAP gap> m1[1,2] := 5; -Error, Matrix Assignment: must be a mutable matrix +Error, Matrix Assignment: must be a mutable matrix (not a atomic compone\ +nt object) +#@else +gap> m1[1,2] := 5; +Error, Matrix Assignment: must be a mutable matrix (not a object (compon\ +ent)) +#@fi # gap> STOP_TEST( "matblock.tst", 1);