Thread: BUG #4549: ecpg produces code that don't compile

BUG #4549: ecpg produces code that don't compile

From
"Clemens Fischer"
Date:
The following bug has been logged online:

Bug reference:      4549
Logged by:          Clemens Fischer
Email address:      cfi@mbs-software.de
PostgreSQL version: 8.3.5
Operating system:   QNX 6.3
Description:        ecpg produces code that don't compile
Details:

Hello List,

Don't know whether anyone here can help but...
We have some code that has compiled and ran just fine from postgresql 7.4.x
thru 8.2.9. It uses embedded sql. With the new port - 8.3.5 - this code will
no longer compile. Below is a standalone code, which shows you the  details.
Any help or ideas would be appreciated.

-- snip ecpgtest-multidim.pgc begin --
#include <stdio.h>
#include <stdlib.h>

EXEC SQL include sqlca;
EXEC SQL WHENEVER SQLERROR   sqlprint;
EXEC SQL WHENEVER SQLWARNING sqlprint;
EXEC SQL WHENEVER NOT FOUND  continue;

int main( void )
{
    EXEC SQL begin declare section;
    char    multidim_char[4][50];    // works
    VARCHAR multidim_varchar[4][50]; // failed
    EXEC SQL end declare section;

    ECPGdebug(1, stderr);
    EXEC SQL connect to postgres user postgres using postgres;

    EXEC SQL DROP TABLE IF EXISTS ecpgtest;
    EXEC SQL CREATE TABLE ecpgtest (no   INTEGER     PRIMARY KEY,
                                    name VARCHAR(30) NOT NULL);
    EXEC SQL INSERT INTO ecpgtest VALUES (1, 'first');
    EXEC SQL INSERT INTO ecpgtest VALUES (2, 'second');
    EXEC SQL INSERT INTO ecpgtest VALUES (3, 'third');

    // test 1
    EXEC SQL SELECT name INTO :multidim_char[0] FROM ecpgtest WHERE no = 1;
    // test 2
    EXEC SQL SELECT name INTO :multidim_varchar[0] FROM ecpgtest WHERE no =
1;

    EXEC SQL DISCONNECT ALL;
    ECPGdebug(0, stderr);

    return( EXIT_SUCCESS );
}
-- snip ecpgtest-multidim.pgc end --

Using ecpg and gcc generates the following output:
ecpg -t -o ecpgtest-multidim.c ecpgtest-multidim.pgc
cc -c -I/usr/local/pgsql/include ecpgtest-multidim.c
ecpgtest-multidim.pgc: In function `main':
ecpgtest-multidim.pgc:30: parse error before `_13'
cc: /usr/qnx630/host/qnx6/x86/usr/lib/gcc-lib/ntox86/2.95.3/cc1 error 33
make: *** [ecpgtest-multidim.o] Error 1

-- snip ecpgtest-multidim.c code fragment 1 begin --
int main( void )
{
    /* exec sql begin declare section */
            // works
      // failed

#line 12 "ecpgtest-multidim.pgc"
 char  multidim_char [ 4 ] [ 50 ]    ;

#line 13 "ecpgtest-multidim.pgc"
   struct varchar_multidim_varchar_13  { int len; char arr[ 50 ]; }
multidim_va rchar [4]   ;
/* exec sql end declare section */
#line 14 "ecpgtest-multidim.pgc"


    ECPGdebug(1, stderr);
-- snip ecpgtest-multidim.c code fragment 1 end --

You see in "#line 13" the definition of the varchar.

-- snip ecpgtest-multidim.c code fragment 2 begin --
    // test 1
    { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select  name  from
ecpgtest where no = 1  ", ECPGt_EOIT,
        ECPGt_char,(multidim_char[0]),(long)50,(long)1,(50)*sizeof(char),
        ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
#line 27 "ecpgtest-multidim.pgc"

if (sqlca.sqlwarn[0] == 'W') sqlprint();
#line 27 "ecpgtest-multidim.pgc"

if (sqlca.sqlcode < 0) sqlprint();}
#line 27 "ecpgtest-multidim.pgc"

    // test 2
    { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select  name  from
ecpgtest where no = 1  ", ECPGt_EOIT,
        ECPGt_varchar,&(multidim_varchar[0]),(long)50,(long)1,sizeof(struct
varchar_multidim_varchar[0]_13),
        ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
#line 29 "ecpgtest-multidim.pgc"

-- snip ecpgtest-multidim.c fragment 2 end --

In the second fragment you see the wrong sizeof-call:
varchar_multidim_varchar[0]_13
one solution is:
varchar_multidim_varchar_13[0]

Can you fix this, please?
Thank you
Clemens Fischer

Re: BUG #4549: ecpg produces code that don't compile

From
Michael Meskes
Date:
On Tue, Nov 25, 2008 at 10:44:32AM +0000, Clemens Fischer wrote:
> Using ecpg and gcc generates the following output:
> ecpg -t -o ecpgtest-multidim.c ecpgtest-multidim.pgc
> cc -c -I/usr/local/pgsql/include ecpgtest-multidim.c
> ecpgtest-multidim.pgc: In function `main':
> ecpgtest-multidim.pgc:30: parse error before `_13'
> cc: /usr/qnx630/host/qnx6/x86/usr/lib/gcc-lib/ntox86/2.95.3/cc1 error 33
> make: *** [ecpgtest-multidim.o] Error 1

Thanks for reporting. Fixed in CVS HEAD and 8.3.

Patch is attached, it was just a small oversight that happened when the new
varchar naming was introduced.

Michael
--
Michael Meskes
Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org)
Michael at BorussiaFan dot De, Meskes at (Debian|Postgresql) dot Org
ICQ: 179140304, AIM/Yahoo: michaelmeskes, Jabber: meskes@jabber.org
Go VfL Borussia! Go SF 49ers! Use Debian GNU/Linux! Use PostgreSQL!

Attachment

Re: BUG #4549: ecpg produces code that don't compile

From
"Clemens A. Fischer"
Date:
Hallo Michael,

thanks for the patch, but ...
compiling ecpg fails:
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Winline
-fno-strict-aliasing -Wno-error  -I../include
-I../../../../src/interfaces/ecpg/include -I. -DMAJOR_VERSION=4
-DMINOR_VERSION=4 -DPATCHLEVEL=1 -I../../../../src/include -D_GNU_SOURCE
-I/opt/include   -c -o type.o type.c
type.c: In function `ECPGdump_a_simple':
type.c:356: warning: implicit declaration of function `strchrnul'
type.c:356: invalid type argument of `unary *'
make: *** [type.o] Error 1

Is it possible to expand 'strchrnul' to
if(var_name != NULL) *(strchr( ...
or something like that?

Clemens

Am Mittwoch, den 26.11.2008, 14:20 +0100 schrieb Michael Meskes:
> On Tue, Nov 25, 2008 at 10:44:32AM +0000, Clemens Fischer wrote:
> > Using ecpg and gcc generates the following output:
> > ecpg -t -o ecpgtest-multidim.c ecpgtest-multidim.pgc
> > cc -c -I/usr/local/pgsql/include ecpgtest-multidim.c
> > ecpgtest-multidim.pgc: In function `main':
> > ecpgtest-multidim.pgc:30: parse error before `_13'
> > cc: /usr/qnx630/host/qnx6/x86/usr/lib/gcc-lib/ntox86/2.95.3/cc1 error 33
> > make: *** [ecpgtest-multidim.o] Error 1
>
> Thanks for reporting. Fixed in CVS HEAD and 8.3.
>
> Patch is attached, it was just a small oversight that happened when the new
> varchar naming was introduced.
>
> Michael

Re: BUG #4549: ecpg produces code that don't compile

From
Tom Lane
Date:
"Clemens A. Fischer" <clemens.fischer@mbs-software.de> writes:
> Hallo Michael,
> thanks for the patch, but ...
> compiling ecpg fails:
> type.c: In function `ECPGdump_a_simple':
> type.c:356: warning: implicit declaration of function `strchrnul'
> type.c:356: invalid type argument of `unary *'

Whatever strchrnul is, it isn't very portable --- the buildfarm is
breaking out in red too.  Please change that.

            regards, tom lane

Re: BUG #4549: ecpg produces code that don't compile

From
John R Pierce
Date:
Tom Lane wrote:
> Whatever strchrnul is, it isn't very portable --- the buildfarm is
> breaking out in red too.  Please change that.
>=20=20=20


sigh, more gnuish code....



=97 Function: char * *strchrnul* (const char *string, int c)

    |strchrnul| is the same as |strchr| except that if it does not find
    the character, it returns a pointer to string's terminating null
    character rather than a null pointer.

    This function is a GNU extension.

Re: BUG #4549: ecpg produces code that don't compile

From
Michael Meskes
Date:
On Wed, Nov 26, 2008 at 06:44:11AM -0800, John R Pierce wrote:
> Tom Lane wrote:
>> Whatever strchrnul is, it isn't very portable --- the buildfarm is
>> breaking out in red too.  Please change that.
>
> sigh, more gnuish code....

Fixed. Sorry, didn't notice that it still is a GNU extension as GNU has for
quite a long time.

Michael

--
Michael Meskes
Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org)
Michael at BorussiaFan dot De, Meskes at (Debian|Postgresql) dot Org
ICQ: 179140304, AIM/Yahoo: michaelmeskes, Jabber: meskes@jabber.org
Go VfL Borussia! Go SF 49ers! Use Debian GNU/Linux! Use PostgreSQL!