diff --git a/src/listfunc.c b/src/listfunc.c index 0a6a69bd0f..fe7a7704b7 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); /* handle the case of strings now */ diff --git a/src/lists.c b/src/lists.c index 13b5dfea73..1b3e0687ba 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); + 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..57060a3362 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); // 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); // 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); 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); // 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); + 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); + 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); + 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); + amount1 = GetNonnegativeSmallInt("SHIFT_RIGHT_GF2VEC", amount); ShiftRightGF2Vec(vec, amount1); return (Obj)0;