Re: ECPG support for struct in INTO list - Mailing list pgsql-hackers
From | Boszormenyi Zoltan |
---|---|
Subject | Re: ECPG support for struct in INTO list |
Date | |
Msg-id | 4A794C0A.6020500@cybertec.at Whole thread Raw |
In response to | Re: ECPG support for struct in INTO list (Michael Meskes <meskes@postgresql.org>) |
Responses |
Re: ECPG support for struct in INTO list
|
List | pgsql-hackers |
Michael Meskes írta: > On Fri, Jul 31, 2009 at 11:42:33AM +0200, Boszormenyi Zoltan wrote: > >> made me look around more. Find the attached patch I came up with. >> Now my previous test code works and produces similar C code >> as without "-C INFORMIX". Can it be this simple? >> > > Unfortunately it is not. > > >> Can you see anything wrong with this approach? >> > > Yes, please look at the slightly changed test version that is attached to this email. > I have looked at it. The code seems to be invalid. get_var(void) {EXEC SQL BEGIN DECLARE SECTION;MYTYPE myvar;EXEC SQL END DECLARE SECTION; EXEC SQL DECLARE mycur CURSOR FOR SELECT * INTO :myvar FROM a1 WHERE id = 1; } "myvar" is lost as soon as the function returns and is not visible to calling functions. I tried to compile your code (with my previous "fix" in place, so at least :myvar is processed and C code is output): $ make test28 ecpg -C INFORMIX test28.pgc cc -g -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -g -I/home/zozo/pgc84pre/include -I/home/zozo/pgc84pre/include/postgresql/internal -c -o test28.o test28.c test28.pgc:15: warning: return type defaults to ‘int’ test28.pgc:14: warning: no previous prototype for ‘get_var’ test28.pgc: In function ‘get_var’: test28.pgc:17: warning: unused variable ‘myvar’ test28.pgc: In function ‘main’: test28.pgc:45: error: ‘myvar’ undeclared (first use in this function) test28.pgc:45: error: (Each undeclared identifier is reported only once test28.pgc:45: error: for each function it appears in.) make: *** [test28.o] Error 1 rm test28.c Line 45 in the modified code sent by you is: printf("c = '%s'\n", myvar.c); and the compiler correctly complains. > If you use e.g. int instead of MYTYPE, it works nicely, but not with MYTYPE. > I modified getvar this way: get_var(void) { EXEC SQL BEGIN DECLARE SECTION; int myid; EXEC SQL END DECLARE SECTION; EXEC SQL DECLARE mycur CURSOR FOR SELECT id INTO :myid FROM a1 WHERE id = 1; } And the preprocessed code via "ecpg -C INFORMIX" is: get_var(void) { /* exec sql begin declare section */ #line 17 "test28.pgc" int myid ; /* exec sql end declare section */ #line 18 "test28.pgc" ECPG_informix_set_var( 0, &( myid ), __LINE__);\ /* declare mycur cursor for select id from a1 where id = 1 */ #line 20 "test28.pgc" } Some systems (stack-protector extensions to GCC, etc) make the code segfault immediately as soon as the first FETCH statement tries to touch the lost memory area. Just because ECPG does some tricks with ECPG_informix_set_var() and ECPG_informix_get_var() converting variable reference to runtime pointer values, the code wouldn't get magically valid. > Please see the comments in adjust_informix to see what this function is > supposed to do. > I did and I don't understand. I think it's just a bug in ESQL/C to accept such constructs. > Michael > Best regards, Zoltán Böszörményi -- Bible has answers for everything. Proof: "But let your communication be, Yea, yea; Nay, nay: for whatsoever is more than these cometh of evil." (Matthew 5:37) - basics of digital technology. "May your kingdom come" - superficial description of plate tectonics ---------------------------------- Zoltán Böszörményi Cybertec Schönig & Schönig GmbH http://www.postgresql.at/
pgsql-hackers by date: