Re: ecpg: issue related to preprocessor directives - Mailing list pgsql-interfaces

From Ashutosh Sharma
Subject Re: ecpg: issue related to preprocessor directives
Date
Msg-id CAE9k0Pm1nzxJsmHM77ZmyCG==89mKyYqofz93WkqBm7LgtiiGA@mail.gmail.com
Whole thread Raw
In response to Re: ecpg: issue related to preprocessor directives  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-interfaces
On Sat, Aug 1, 2020 at 5:36 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Ashutosh Sharma <ashu.coek88@gmail.com> writes:
> > When the following ecpg program having preprocessor directives is compiled,
> > the output produced is not correct.
> > ...
> > As seen from above output, both exec sql ifdef and exec sql else block got
> > compiled which is wrong. If the above output is further compiled using gcc
> > compiler, the compilation would fail.
>
> Looking at pgc.l, it seems that 'elif' is treated as though it were
> 'endif' followed by 'ifdef', which of course completely loses the
> expected property that a previous successful branch would keep the
> elif branch from being expanded.

Yeah, that's right. The point is, while processing the elif branch, we
remove an entry for the previous branch (ifdef, ifndef) from the stack
and push a new entry for the current elif branch. So, if the elif
branch is evaluated to false, the else branch gets automatically
evaluated to true. And as a result of that both ifdef and else branch
gets evaluated to true thereby compiling both (ifdef/ifndef, else)
blocks.

--
With Regards,
Ashutosh Sharma
EnterpriseDB:http://www.enterprisedb.com



pgsql-interfaces by date:

Previous
From: Tom Lane
Date:
Subject: Re: ecpg: issue related to preprocessor directives
Next
From: Ashutosh Sharma
Date:
Subject: Re: ecpg: issue related to preprocessor directives