netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Patrick McHardy <kaber@trash.net>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH 2/2] expression: fix printing of binary operation
Date: Wed, 15 Jan 2014 12:59:59 +0100	[thread overview]
Message-ID: <20140115115959.GA20144@localhost> (raw)
In-Reply-To: <20140115114939.GA21225@macbook.localnet>

On Wed, Jan 15, 2014 at 11:49:39AM +0000, Patrick McHardy wrote:
> On Wed, Jan 15, 2014 at 12:41:34PM +0100, Pablo Neira Ayuso wrote:
> > On Wed, Jan 15, 2014 at 11:27:17AM +0000, Patrick McHardy wrote:
> > > On Wed, Jan 15, 2014 at 11:21:29AM +0000, Patrick McHardy wrote:
> > > > 
> > > > That doesn't look right, binops can also occur outside of relational
> > > > expressions. I'd suggest to special case OP_EQ and not print it by
> > > > default unless the LHS is an EXPR_BINOP.
> > > 
> > > Something like this:
> > > 
> > > 
> > > diff --git a/src/expression.c b/src/expression.c
> > > index 71154cc..518f71c 100644
> > > --- a/src/expression.c
> > > +++ b/src/expression.c
> > > @@ -356,7 +356,7 @@ const char *expr_op_symbols[] = {
> > >  	[OP_XOR]	= "^",
> > >  	[OP_LSHIFT]	= "<<",
> > >  	[OP_RSHIFT]	= ">>",
> > > -	[OP_EQ]		= NULL,
> > > +	[OP_EQ]		= "==",
> > >  	[OP_NEQ]	= "!=",
> > >  	[OP_LT]		= "<",
> > >  	[OP_GT]		= ">",
> > > @@ -407,7 +407,9 @@ struct expr *unary_expr_alloc(const struct location *loc,
> > >  static void binop_expr_print(const struct expr *expr)
> > >  {
> > >  	expr_print(expr->left);
> > > -	if (expr_op_symbols[expr->op] != NULL)
> > > +	if (expr_op_symbols[expr->op] &&
> > > +	    (expr->op != OP_EQ ||
> > > +	     expr->left->ops->type == EXPR_BINOP))
> > >  		printf(" %s ", expr_op_symbols[expr->op]);
> > >  	else
> > >  		printf(" ");
> > 
> > This looks a bit more complicated. To my understanding, the right-hand
> > side of the relational tree contains the value. The left-hand side
> > contains the binop tree, whose left-hand side is the meta mark and the
> > right-hand side is the value to apply the operation. The print
> > function doesn't have context to know what's on the right-hand side of
> > the upper relational expression. Thinking how to fix this...
> 
> This OP_EQ case is the upper relational expression. Try it, it works fine :)

Indeed, thanks Patrick.

  reply	other threads:[~2014-01-15 12:01 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-15 11:09 [PATCH 1/2 nft RFC] expression: default to print binary operations using nominal representation Pablo Neira Ayuso
2014-01-15 11:09 ` [PATCH 2/2] expression: fix printing of binary operation Pablo Neira Ayuso
2014-01-15 11:21   ` Patrick McHardy
2014-01-15 11:25     ` Pablo Neira Ayuso
2014-01-15 11:28       ` Patrick McHardy
2014-01-15 11:27     ` Patrick McHardy
2014-01-15 11:41       ` Pablo Neira Ayuso
2014-01-15 11:49         ` Patrick McHardy
2014-01-15 11:59           ` Pablo Neira Ayuso [this message]
2014-01-15 11:18 ` [PATCH 1/2 nft RFC] expression: default to print binary operations using nominal representation Patrick McHardy
2014-01-15 11:32   ` Arturo Borrero Gonzalez
2014-01-15 11:36     ` Patrick McHardy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140115115959.GA20144@localhost \
    --to=pablo@netfilter.org \
    --cc=kaber@trash.net \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).