Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kernel: add RequireStringRep(MayReplace)
Browse files Browse the repository at this point in the history
fingolfin committed Oct 30, 2018
1 parent 8b99f68 commit 28e53d9
Showing 17 changed files with 155 additions and 386 deletions.
6 changes: 2 additions & 4 deletions src/calls.c
Original file line number Diff line number Diff line change
@@ -1372,10 +1372,8 @@ Obj FuncSET_NAME_FUNC(
Obj func,
Obj name )
{
while (!IsStringConv(name)) {
name = ErrorReturnObj("SET_NAME_FUNC( <func>, <name> ): <name> must be a string, not a %s",
(Int)TNAM_OBJ(name), 0, "You can return a new name to continue");
}
RequireStringRepMayReplace("SET_NAME_FUNC", name);

if (TNUM_OBJ(func) == T_FUNCTION ) {
SET_NAME_FUNC(func, ImmutableString(name));
CHANGED_BAG(func);
18 changes: 18 additions & 0 deletions src/error.h
Original file line number Diff line number Diff line change
@@ -251,6 +251,24 @@ extern Obj RACErrorHelper(int mayReturn,
"must be a function")


/****************************************************************************
**
*F RequireStringRep
*/
#define RequireStringRep(funcname, op) \
RequireArgumentCondition(funcname, op, #op, IsStringConv(op), \
"must be a string")


/****************************************************************************
**
*F RequireStringRepMayReplace
*/
#define RequireStringRepMayReplace(funcname, op) \
RequireArgumentConditionMayReplace(funcname, op, #op, IsStringConv(op), \
"must be a string")


/****************************************************************************
**
*F CheckIsPossList( <desc>, <poss> ) . . . . . . . . . . check for poss list
7 changes: 1 addition & 6 deletions src/gap.c
Original file line number Diff line number Diff line change
@@ -892,12 +892,7 @@ Obj FuncGASMAN (
/* evaluate and check the command */
Obj cmd = ELM_PLIST( args, i );
again:
while ( ! IsStringConv(cmd) ) {
cmd = ErrorReturnObj(
"GASMAN: <cmd> must be a string (not a %s)",
(Int)TNAM_OBJ(cmd), 0L,
"you can replace <cmd> via 'return <cmd>;'" );
}
RequireStringRepMayReplace("GASMAN", cmd);

// perform full garbage collection
if ( strcmp( CONST_CSTR_STRING(cmd), "collect" ) == 0 ) {
84 changes: 18 additions & 66 deletions src/gvars.c
Original file line number Diff line number Diff line change
@@ -740,13 +740,8 @@ Obj FuncMakeReadOnlyGVar (
Obj self,
Obj name )
{
/* check the argument */
while ( ! IsStringConv( name ) ) {
name = ErrorReturnObj(
"MakeReadOnlyGVar: <name> must be a string (not a %s)",
(Int)TNAM_OBJ(name), 0L,
"you can return a string for <name>" );
}
// check the argument
RequireStringRepMayReplace("MakeReadOnlyGVar", name);

/* get the variable and make it read only */
MakeReadOnlyGVar(GVarName(CONST_CSTR_STRING(name)));
@@ -768,12 +763,8 @@ Obj FuncMakeReadOnlyGVar (
*/
Obj FuncMakeConstantGVar(Obj self, Obj name)
{
/* check the argument */
while (!IsStringConv(name)) {
name = ErrorReturnObj(
"MakeConstantGVar: <name> must be a string (not a %s)",
(Int)TNAM_OBJ(name), 0L, "you can return a string for <name>");
}
// check the argument
RequireStringRepMayReplace("MakeConstantGVar", name);

/* get the variable and make it read only */
MakeConstantGVar(GVarName(CONST_CSTR_STRING(name)));
@@ -812,13 +803,8 @@ Obj FuncMakeReadWriteGVar (
Obj self,
Obj name )
{
/* check the argument */
while ( ! IsStringConv( name ) ) {
name = ErrorReturnObj(
"MakeReadWriteGVar: <name> must be a string (not a %s)",
(Int)TNAM_OBJ(name), 0L,
"you can return a string for <name>" );
}
// check the argument
RequireStringRepMayReplace("MakeReadWriteGVar", name);

/* get the variable and make it read write */
MakeReadWriteGVar(GVarName(CONST_CSTR_STRING(name)));
@@ -847,13 +833,8 @@ static Obj FuncIsReadOnlyGVar (
Obj self,
Obj name )
{
/* check the argument */
while ( ! IsStringConv( name ) ) {
name = ErrorReturnObj(
"IsReadOnlyGVar: <name> must be a string (not a %s)",
(Int)TNAM_OBJ(name), 0L,
"you can return a string for <name>" );
}
// check the argument
RequireStringRepMayReplace("IsReadOnlyGVar", name);

/* get the answer */
return IsReadOnlyGVar(GVarName(CONST_CSTR_STRING(name))) ? True : False;
@@ -877,11 +858,7 @@ Int IsConstantGVar(UInt gvar)
static Obj FuncIsConstantGVar(Obj self, Obj name)
{
// check the argument
while (!IsStringConv(name)) {
name = ErrorReturnObj(
"IsConstantGVar: <name> must be a string (not a %s)",
(Int)TNAM_OBJ(name), 0L, "you can return a string for <name>");
}
RequireStringRepMayReplace("IsConstantGVar", name);

/* get the answer */
return IsConstantGVar(GVarName(CONST_CSTR_STRING(name))) ? True : False;
@@ -943,12 +920,7 @@ Obj FuncAUTO (
/* make the global variables automatic */
for ( i = 3; i <= LEN_LIST(args); i++ ) {
name = ELM_LIST( args, i );
while ( ! IsStringConv(name) ) {
name = ErrorReturnObj(
"AUTO: <name> must be a string (not a %s)",
(Int)TNAM_OBJ(name), 0L,
"you can return a string for <name>" );
}
RequireStringRepMayReplace("AUTO", name);
gvar = GVarName( CONST_CSTR_STRING(name) );
SET_ELM_GVAR_LIST( ValGVars, gvar, 0 );
SET_ELM_GVAR_LIST( ExprGVars, gvar, list );
@@ -1090,13 +1062,8 @@ Obj FuncASS_GVAR (
Obj gvar,
Obj val )
{
/* check the argument */
while ( ! IsStringConv( gvar ) ) {
gvar = ErrorReturnObj(
"READ: <gvar> must be a string (not a %s)",
(Int)TNAM_OBJ(gvar), 0L,
"you can return a string for <gvar>" );
}
// check the argument
RequireStringRepMayReplace("READ", gvar);

AssGVar( GVarName( CONST_CSTR_STRING(gvar) ), val );
return 0L;
@@ -1111,13 +1078,8 @@ Obj FuncISB_GVAR (
Obj self,
Obj gvar )
{
/* check the argument */
while ( ! IsStringConv( gvar ) ) {
gvar = ErrorReturnObj(
"ISB_GVAR: <gvar> must be a string (not a %s)",
(Int)TNAM_OBJ(gvar), 0L,
"you can return a string for <gvar>" );
}
// check the argument
RequireStringRepMayReplace("ISB_GVAR", gvar);

UInt gv = GVarName( CONST_CSTR_STRING(gvar) );
if (VAL_GVAR_INTERN(gv))
@@ -1145,13 +1107,8 @@ Obj FuncVAL_GVAR (
Obj gvar )
{
Obj val;
/* check the argument */
while ( ! IsStringConv( gvar ) ) {
gvar = ErrorReturnObj(
"VAL_GVAR: <gvar> must be a string (not a %s)",
(Int)TNAM_OBJ(gvar), 0L,
"you can return a string for <gvar>" );
}
// check the argument
RequireStringRepMayReplace("VAL_GVAR", gvar);

/* get the value */
val = ValAutoGVar( GVarName( CONST_CSTR_STRING(gvar) ) );
@@ -1172,13 +1129,8 @@ Obj FuncUNB_GVAR (
Obj self,
Obj gvar )
{
/* check the argument */
while ( ! IsStringConv( gvar ) ) {
gvar = ErrorReturnObj(
"UNB_GVAR: <gvar> must be a string (not a %s)",
(Int)TNAM_OBJ(gvar), 0L,
"you can return a string for <gvar>" );
}
// check the argument
RequireStringRepMayReplace("UNB_GVAR", gvar);

/* */
AssGVar( GVarName( CONST_CSTR_STRING(gvar) ), (Obj)0 );
11 changes: 3 additions & 8 deletions src/integer.c
Original file line number Diff line number Diff line change
@@ -2647,21 +2647,16 @@ Obj FuncRandomIntegerMT(Obj self, Obj mtstr, Obj nrbits)
Int i, n, q, r, qoff, len;
UInt4 *mt;
UInt4 *pt;
while (! IsStringConv(mtstr)) {
mtstr = ErrorReturnObj(
"<mtstr> must be a string (not a %s)",
(Int)TNAM_OBJ(mtstr), 0L,
"you can replace <mtstr> via 'return <mtstr>;'" );
}
RequireStringRepMayReplace("RandomIntegerMT", mtstr);
while ((! IsStringConv(mtstr)) || GET_LEN_STRING(mtstr) < 2500) {
mtstr = ErrorReturnObj(
"<mtstr> must be a string with at least 2500 characters",
"RandomIntegerMT: <mtstr> must be a string with at least 2500 characters",
0L, 0L,
"you can replace <mtstr> via 'return <mtstr>;'" );
}
while ((! IS_INTOBJ(nrbits)) || INT_INTOBJ(nrbits) < 0) {
nrbits = ErrorReturnObj(
"<nrbits> must be a small non-negative integer (not a %s)",
"RandomIntegerMT: <nrbits> must be a small non-negative integer (not a %s)",
(Int)TNAM_OBJ(nrbits), 0L,
"you can replace <mtstr> via 'return <mtstr>;'" );
}
7 changes: 1 addition & 6 deletions src/intfuncs.c
Original file line number Diff line number Diff line change
@@ -92,12 +92,7 @@ Obj FuncInitRandomMT( Obj self, Obj initstr)
UInt4 *mt, key_length, byte_key_length, i, j, k, N = 624;

/* check the seed, given as string */
while (! IsStringConv(initstr)) {
initstr = ErrorReturnObj(
"<initstr> must be a string (not a %s)",
(Int)TNAM_OBJ(initstr), 0L,
"you can replace <initstr> via 'return <initstr>;'" );
}
RequireStringRepMayReplace("InitRandomMT", initstr);

/* store array of 624 UInt4 and one UInt4 as counter "mti" and an
endianness marker */
6 changes: 1 addition & 5 deletions src/macfloat.c
Original file line number Diff line number Diff line change
@@ -308,12 +308,8 @@ Obj FuncMACFLOAT_INT( Obj self, Obj i )

Obj FuncMACFLOAT_STRING( Obj self, Obj s )
{
RequireStringRepMayReplace("MACFLOAT_STRING", s);

while (!IsStringConv(s))
{
s = ErrorReturnObj("MACFLOAT_STRING: object to be converted must be a string not a %s",
(Int)TNAM_OBJ(s),0,"You can return a string to continue" );
}
char * endptr;
UChar *sp = CHARS_STRING(s);
Obj res= NEW_MACFLOAT((Double) STRTOD((char *)sp,&endptr));
22 changes: 5 additions & 17 deletions src/modules.c
Original file line number Diff line number Diff line change
@@ -125,11 +125,7 @@ static void RegisterModuleState(StructInitInfo * info)
Obj FuncGAP_CRC(Obj self, Obj filename)
{
/* check the argument */
while (!IsStringConv(filename)) {
filename = ErrorReturnObj(
"<filename> must be a string (not a %s)", (Int)TNAM_OBJ(filename),
0L, "you can replace <filename> via 'return <filename>;'");
}
RequireStringRepMayReplace("GAP_CRC", filename);

/* compute the crc value */
return INTOBJ_INT(SyGAPCRC(CONST_CSTR_STRING(filename)));
@@ -217,14 +213,10 @@ Obj FuncLOAD_DYN(Obj self, Obj filename, Obj crc)
InitInfoFunc init;

/* check the argument */
while (!IsStringConv(filename)) {
filename = ErrorReturnObj(
"<filename> must be a string (not a %s)", (Int)TNAM_OBJ(filename),
0L, "you can replace <filename> via 'return <filename>;'");
}
RequireStringRepMayReplace("LOAD_DYN", filename);
while (!IS_INTOBJ(crc) && crc != False) {
crc = ErrorReturnObj(
"<crc> must be a small integer or 'false' (not a %s)",
"LOAD_DYN: <crc> must be a small integer or 'false' (not a %s)",
(Int)TNAM_OBJ(crc), 0L,
"you can replace <crc> via 'return <crc>;'");
}
@@ -298,14 +290,10 @@ Obj FuncLOAD_STAT(Obj self, Obj filename, Obj crc)
Int k;

/* check the argument */
while (!IsStringConv(filename)) {
filename = ErrorReturnObj(
"<filename> must be a string (not a %s)", (Int)TNAM_OBJ(filename),
0L, "you can replace <filename> via 'return <filename>;'");
}
RequireStringRepMayReplace("LOAD_STAT", filename);
while (!IS_INTOBJ(crc) && crc != False) {
crc = ErrorReturnObj(
"<crc> must be a small integer or 'false' (not a %s)",
"LOAD_STAT: <crc> must be a small integer or 'false' (not a %s)",
(Int)TNAM_OBJ(crc), 0L,
"you can replace <crc> via 'return <crc>;'");
}
Loading
Oops, something went wrong.

0 comments on commit 28e53d9

Please sign in to comment.