General Bug Report: ECPG fails to parse comments correctly

From: Unprivileged user <nobody>
To: pgsql-bugs(at)postgresql(dot)org
Subject: General Bug Report: ECPG fails to parse comments correctly
Date: 1999-05-12 19:04:43
Message-ID: 199905121904.PAA30233@hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


============================================================================
POSTGRESQL BUG REPORT TEMPLATE
============================================================================

Your name : Craig Orsinger
Your email address : orsingerc(at)epg(dot)lewis(dot)army(dot)mil

Category : runtime: front-end: C
Severity : non-critical

Summary: ECPG fails to parse comments correctly

System Configuration
--------------------
Operating System : HPUX 10.20 and Linux 2.0.36

PostgreSQL version : 6.4.2

Compiler used : gcc, HP cc

Hardware:
---------
HP 715/100 workstation, 64MB RAM
NEC Versa LX laptop, 128MB RAM

Versions of other tools:
------------------------
GNU make

--------------------------------------------------------------------------

Problem Description:
--------------------
While trying to compile a function written in
embedded SQL for C, got an error indication of the
form:

test.pgc:30: unbalanced `#endif'

After some trial and error, I discovered that this
message occured if a C preprocessor directive was
placed after the end of a block of code that was
terminated by a comment (see example). Putting the
comment on a separate line cured this difficulty.
The ecpg invocation was of the form:

ecpg test.pgc
gcc -O2 -I$PGDIR/include -c test.c -o test.o

There were no other command line parameters.
"PGDIR" is the root of the PostgreSQL installation.

--------------------------------------------------------------------------

Test Case:
----------
Compile this bit of C source with these commands:

ecpg test.pgc
gcc -O2 -I$PGDIR/include -c test.c -o test.o

/* test.pgc - demonstrate comment-parsing problem */

EXEC SQL INCLUDE sqlca.h ;

int func_we_want( int paramA )
{
EXEC SQL BEGIN DECLARE SECTION ;
int retval ;
EXEC SQL END DECLARE SECTION ;

retval = paramA ;
return( retval ) ;

} /* end of 'func_we_want()' */

#ifdef WE_WANT_THIS_FUNC

int func_we_dont_want( int paramA )
{
EXEC SQL BEGIN DECLARE SECTION ;
int retval ;
EXEC SQL END DECLARE SECTION ;

retval = paramA ;
return( retval ) ;

} /* end of 'func_we_dont_want()' */

#endif

As written, it will fail. To make it compile correctly,
just insert a newline between the '}' and the "end of .."
comments at the end of each function.

--------------------------------------------------------------------------

Solution:
---------
I'd suggest that you ensure that there is always a
newline after the closing bracket of a block of C
source.

--------------------------------------------------------------------------

Browse pgsql-bugs by date

  From Date Subject
Next Message Paul Quirk 1999-05-14 01:06:02 problem with dates.
Previous Message gjerde 1999-05-10 18:08:32 bin/psql compile fails on Redhat 6.0 (glibc 2.1)