From 8a9aa640169471595426266654e454d2eb8ae7b3 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 5 Dec 2018 11:59:09 +0100 Subject: [PATCH] kernel: add RequireMutableSet helper in set.c --- src/set.c | 40 +++++++++------------------------- tst/testinstall/kernel/set.tst | 10 ++++----- 2 files changed, 15 insertions(+), 35 deletions(-) diff --git a/src/set.c b/src/set.c index 6e41d58acc..99193b6494 100644 --- a/src/set.c +++ b/src/set.c @@ -34,6 +34,11 @@ #include "sysopt.h" // for SyInitializing +#define RequireMutableSet(funcname, op) \ + RequireArgumentCondition(funcname, op, #op, IS_MUTABLE_OBJ(op) && IsSet(op), \ + "must be a mutable proper set") + + /**************************************************************************** ** *F IsSet( ) . . . . . . . . . . . . . . . . . test if a list is a set @@ -409,12 +414,7 @@ Obj FuncADD_SET ( UInt wasTab; /* check the arguments */ - while ( ! IS_MUTABLE_OBJ(set) || ! IsSet(set) ) { - set = ErrorReturnObj( - "AddSet: must be a mutable proper set (not a %s)", - (Int)TNAM_OBJ(set), 0L, - "you can replace via 'return ;'" ); - } + RequireMutableSet("AddSet", set); len = LEN_LIST(set); /* perform the binary search to find the position */ @@ -533,12 +533,7 @@ Obj FuncREM_SET ( Obj *ptr; /* check the arguments */ - while ( ! IS_MUTABLE_OBJ(set) || ! IsSet(set) ) { - set = ErrorReturnObj( - "RemoveSet: must be a mutable proper set (not a %s)", - (Int)TNAM_OBJ(set), 0L, - "you can replace via 'return ;'" ); - } + RequireMutableSet("RemoveSet", set); len = LEN_LIST(set); /* perform the binary search to find the position */ @@ -600,12 +595,7 @@ Obj FuncUNITE_SET ( Obj TmpUnion; /* check the arguments */ - while ( ! IS_MUTABLE_OBJ(set1) || ! IsSet(set1) ) { - set1 = ErrorReturnObj( - "UniteSet: must be a mutable proper set (not a %s)", - (Int)TNAM_OBJ(set1), 0L, - "you can replace via 'return ;'" ); - } + RequireMutableSet("UniteSet", set1); RequireSmallList("UniteSet", set2); if ( ! IsSet(set2) ) set2 = SetList(set2); @@ -773,12 +763,7 @@ Obj FuncINTER_SET ( UInt lenr; /* length of result set */ /* check the arguments */ - while ( ! IS_MUTABLE_OBJ(set1) || ! IsSet(set1) ) { - set1 = ErrorReturnObj( - "IntersectSet: must be a mutable proper set (not a %s)", - (Int)TNAM_OBJ(set1), 0L, - "you can replace via 'return ;'" ); - } + RequireMutableSet("IntersectSet", set1); RequireSmallList("IntersectSet", set2); if ( ! IsSet(set2) ) set2 = SetList(set2); @@ -946,12 +931,7 @@ Obj FuncSUBTR_SET ( UInt ll; /* check the arguments */ - while ( ! IS_MUTABLE_OBJ(set1) || ! IsSet(set1) ) { - set1 = ErrorReturnObj( - "SubtractSet: must be a mutable proper set (not a %s)", - (Int)TNAM_OBJ(set1), 0L, - "you can replace via 'return ;'" ); - } + RequireMutableSet("SubtractSet", set1); RequireSmallList("SubtractSet", set2); if ( ! IsSet(set2) ) set2 = SetList(set2); diff --git a/tst/testinstall/kernel/set.tst b/tst/testinstall/kernel/set.tst index 7d43d96a3b..02027440d1 100644 --- a/tst/testinstall/kernel/set.tst +++ b/tst/testinstall/kernel/set.tst @@ -45,19 +45,19 @@ false gap> ADD_SET; function( set, val ) ... end gap> ADD_SET(1,1); -Error, AddSet: must be a mutable proper set (not a integer) +Error, AddSet: must be a mutable proper set (not the integer 1) # gap> REM_SET; function( set, val ) ... end gap> REM_SET(1,1); -Error, RemoveSet: must be a mutable proper set (not a integer) +Error, RemoveSet: must be a mutable proper set (not the integer 1) # gap> UNITE_SET; function( set1, set2 ) ... end gap> UNITE_SET(1,1); -Error, UniteSet: must be a mutable proper set (not a integer) +Error, UniteSet: must be a mutable proper set (not the integer 1) gap> UNITE_SET([],1); Error, UniteSet: must be a small list (not the integer 1) gap> UNITE_SET([],[]); @@ -66,7 +66,7 @@ gap> UNITE_SET([],[]); gap> INTER_SET; function( set1, set2 ) ... end gap> INTER_SET(1,1); -Error, IntersectSet: must be a mutable proper set (not a integer) +Error, IntersectSet: must be a mutable proper set (not the integer 1) gap> INTER_SET([],1); Error, IntersectSet: must be a small list (not the integer 1) gap> INTER_SET([],[]); @@ -75,7 +75,7 @@ gap> INTER_SET([],[]); gap> SUBTR_SET; function( set1, set2 ) ... end gap> SUBTR_SET(1,1); -Error, SubtractSet: must be a mutable proper set (not a integer) +Error, SubtractSet: must be a mutable proper set (not the integer 1) gap> SUBTR_SET([],1); Error, SubtractSet: must be a small list (not the integer 1) gap> SUBTR_SET([],[]);