Skip to content

Commit

Permalink
kernel: reject invalid AND-filters
Browse files Browse the repository at this point in the history
This rejects invalid AND-filters like this:

    gap> Center and IsAssociative;
    <Filter "<<and-filter>>">
  • Loading branch information
fingolfin committed Aug 28, 2018
1 parent 2b48e81 commit 2506004
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 46 deletions.
16 changes: 2 additions & 14 deletions src/exprs.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,22 +183,10 @@ Obj EvalAnd (
}

/* handle the 'and' of two filters */
else if (IS_PSEUDO_FILTER(opL)) {
if (!IS_FILTER(opL)) {
// support this for backwards compatibility; see discussion on
// https://github.com/gap-system/gap/pull/2732
Warning("operation '%g' used in AND-filter is not a filter",
(Int)NAME_FUNC(opL), 0);
}
else if (IS_FILTER(opL)) {
tmp = READ_EXPR(expr, 1);
opR = EVAL_EXPR( tmp );
if (IS_PSEUDO_FILTER(opR)) {
if (!IS_FILTER(opR)) {
// support this for backwards compatibility; see discussion on
// https://github.com/gap-system/gap/pull/2732
Warning("operation '%g' used in AND-filter is not a filter",
(Int)NAME_FUNC(opR), 0);
}
if (IS_FILTER(opR)) {
return NewAndFilter( opL, opR );
}
else {
Expand Down
16 changes: 2 additions & 14 deletions src/intrprtr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1319,20 +1319,8 @@ void IntrAnd ( void )
}

/* handle the 'and' of two filters */
else if (IS_PSEUDO_FILTER(opL)) {
if (!IS_FILTER(opL)) {
// support this for backwards compatibility; see discussion on
// https://github.com/gap-system/gap/pull/2732
Warning("operation '%g' used in AND-filter is not a filter\n",
(Int)NAME_FUNC(opL), 0);
}
if (IS_PSEUDO_FILTER(opR)) {
if (!IS_FILTER(opR)) {
// support this for backwards compatibility; see discussion on
// https://github.com/gap-system/gap/pull/2732
Warning("operation '%g' used in AND-filter is not a filter",
(Int)NAME_FUNC(opR), 0);
}
else if (IS_FILTER(opL)) {
if (IS_FILTER(opR)) {
PushObj( NewAndFilter( opL, opR ) );
}
else {
Expand Down
9 changes: 0 additions & 9 deletions src/opers.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,6 @@ static inline Int IS_FILTER(Obj oper)
return v & OPER_IS_FILTER;
}

// temporary HACK, until all affected packages are fixed
static inline Int IS_PSEUDO_FILTER(Obj oper)
{
if (!IS_OPERATION(oper))
return 0;
Obj flags = FLAGS_FILT(oper);
return flags && TNUM_OBJ(flags) == T_FLAGS;
}


/****************************************************************************
**
Expand Down
13 changes: 4 additions & 9 deletions tst/testinstall/boolean.tst
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,13 @@ Error, <expr> must be a filter (not a function)
gap> IsAssociative and true;
Error, <expr> must be a filter (not a function)
gap> IsAssociative and Center;
Warning, operation 'Centre' used in AND-filter is not a filter in stream:1
<Filter "(IsAssociative and Centre)">
Error, <expr> must be a filter (not a function)
gap> IsAssociative and FirstOp;
Error, <expr> must be a filter (not a function)
gap> true and IsAssociative;
Error, <expr> must be 'true' or 'false' (not a function)
gap> Center and IsAssociative;
Warning, operation 'Centre' used in AND-filter is not a filter
in stream:1
<Filter "(Centre and IsAssociative)">
Error, <expr> must be 'true' or 'false' or a filter (not a function)
gap> FirstOp and IsAssociative;
Error, <expr> must be 'true' or 'false' or a filter (not a function)
gap> IsAssociative and IsAssociative;
Expand All @@ -119,15 +116,13 @@ Error, <expr> must be a filter (not a function)
gap> function() return IsAssociative and true; end();
Error, <expr> must be a filter (not a function)
gap> function() return IsAssociative and Center; end();
Warning, operation 'Centre' used in AND-filter is not a filter in stream:1
<Filter "(IsAssociative and Centre)">
Error, <expr> must be a filter (not a function)
gap> function() return IsAssociative and FirstOp; end();
Error, <expr> must be a filter (not a function)
gap> function() return true and IsAssociative; end();
Error, <expr> must be 'true' or 'false' (not a function)
gap> function() return Center and IsAssociative; end();
Warning, operation 'Centre' used in AND-filter is not a filter in stream:1
<Filter "(Centre and IsAssociative)">
Error, <expr> must be 'true' or 'false' or a filter (not a function)
gap> function() return FirstOp and IsAssociative; end();
Error, <expr> must be 'true' or 'false' or a filter (not a function)
gap> function() return IsAssociative and IsAssociative; end();
Expand Down

0 comments on commit 2506004

Please sign in to comment.