Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k2Xjh-0005O8-0I for pgsql-interfaces@arkaria.postgresql.org; Mon, 03 Aug 2020 10:30:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k2Xje-00063m-6W for pgsql-interfaces@arkaria.postgresql.org; Mon, 03 Aug 2020 10:30:26 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k2Xjd-00063e-PN for pgsql-interfaces@lists.postgresql.org; Mon, 03 Aug 2020 10:30:25 +0000 Received: from mail-yb1-xb42.google.com ([2607:f8b0:4864:20::b42]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1k2XjW-0000WU-Rq for pgsql-interfaces@postgresql.org; Mon, 03 Aug 2020 10:30:24 +0000 Received: by mail-yb1-xb42.google.com with SMTP id m200so15727728ybf.10 for ; Mon, 03 Aug 2020 03:30:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=OoL8booPsAP0UPh1w11CtqZ4OYvG8CBbOLK8LBmyA4g=; b=AvFXb4KIspcK7Kih14sMbM9WbfbsBCe1GAiX2nfuF7APUhgEwIUKcHHvHW5aksXCu+ slUDpN2EdDnPTIOrRV3u6IpuvMLI8Iw0yzHY9EksapqUkSMssUJdd2+Yr79QN0Q5dpdL v1pxi64cIS8QE1yLp1u3gnfOseDJAypFeG1ro3C/q3U5MXLmBxYJVptAmEI/Nk0tjTq0 9ig9OufOn5nIl0N25671P39G8UfqqIBV6vqxBdLSVhAYM1OnIMKN4n+TyovOhbCQOAVN bb6gy/yxevXPXeSeb0bQ+YSMhNjhS0txwsPhYCLycGbjGael56P1d/e+Yj2VQGrTBqyC iD6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=OoL8booPsAP0UPh1w11CtqZ4OYvG8CBbOLK8LBmyA4g=; b=EWiMqwysazaE49uO2LBXaw7vKQh779leNYDh9iRhYzEn+FhErV0B/kJc/CrP34IXOw zhlB4uJAFlR62Us2wj25ZWhRzw6UjgqlvLZOqA6UjuOfCz5ma0ppee0N200IZHFSzGZE u9839doWT5NlXgkF+dVBc8SfkGHNRRaiCOnT1yjP+wYG8W6uxpelBG1iU7WMaQP4D5NO FqnDTVPH9Nbsen45bWxpauxsb99nCQJNU3P2AEfYeywZjrNwhxWt7j8acapU6u6VTHoj P2nUrX/28EuCXsNQZfdRoj3jV/Yaow2rorjStm7iFNbW200RzzcbX/TSO1xXUGeINufB rdJg== X-Gm-Message-State: AOAM533Ncj2OXN/7kg3ojWoVXeysdOslMXt4GsyP/qZxJQ/iTfc3RVCx OiDJdMtPAzsjVgJMr07djFF8GuT0FJH8IIxyOAc= X-Google-Smtp-Source: ABdhPJy9lf3xZfV5qgcfYE6ZPYVIyZf3dacERoiKgvyBig7PBrGx1JwlUzsABNxg7eofyDtrhaWP1IvPmQtKbNtwyk8= X-Received: by 2002:a25:d1d5:: with SMTP id i204mr24863009ybg.146.1596450617179; Mon, 03 Aug 2020 03:30:17 -0700 (PDT) MIME-Version: 1.0 References: <1853327.1596240391@sss.pgh.pa.us> In-Reply-To: <1853327.1596240391@sss.pgh.pa.us> From: Ashutosh Sharma Date: Mon, 3 Aug 2020 16:00:06 +0530 Message-ID: Subject: Re: ecpg: issue related to preprocessor directives To: Tom Lane Cc: pgsql-interfaces@postgresql.org Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sat, Aug 1, 2020 at 5:36 AM Tom Lane wrote: > > Ashutosh Sharma 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