pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
ECPG Segfault and variable usage question.
7+ messages / 4 participants
[nested] [flat]

* ECPG Segfault and variable usage question.
@ 2004-02-12 19:00  Jürgen Cappel <email@juergen-cappel.de>
  0 siblings, 2 replies; 7+ messages in thread

From: Jürgen Cappel @ 2004-02-12 19:00 UTC (permalink / raw)
  To: pgsql-interfaces

Hello,

this is a code snippet that causes ECPG to segfault. It's quite tricky
to produce, as changing the variable name from 'var' to 'myvar' already
causes things to compile fine ...


#define CHAR_LENGTH 25
myfunction ()
{
    EXEC SQL BEGIN DECLARE SECTION;
    char   var[2*CHAR_LENGTH];
    EXEC SQL END DECLARE SECTION;

    EXEC SQL DECLARE mycursor CURSOR FOR
	 SELECT att1, att2
	 FROM mytable
	 WHERE att1 LIKE :var ESCAPE '\\';
    EXEC SQL OPEN mycursor;
}

Stack trace was obtained using a snapshot from about 2 weeks ago, ECPG from
the 7.4.1 release segfaults also.

#0  0x4015fdcb in chunk_free () from /lib/libc.so.6
#1  0x4015fc53 in free () from /lib/libc.so.6
#2  0x080685b7 in dump_variables (list=0x80c1408, mode=1) at variable.c:405
#3  0x08066d56 in output_statement (
    stmt=0x80c14f8 "declare mycursor  cursor  for select  att1  , att2
from mytable where att1  like  ? escape '\\\\'  ", mode=0, con=0x0) at
output.c:126
#4  0x0804af02 in yyparse () at preproc.y:780
#5  0x0806671d in main (argc=8, argv=0xbffff264) at ecpg.c:409
#6  0x401089ed in __libc_start_main () from /lib/libc.so.6


Another problem that's giving me headaches trying to find a workaround for
is the following use of variables as data sources in INSERT/UPDATE
statements:

	:myarray[index[10]]

Any comments, suggestions, hints ?   Thanks a lot,

Jürgen




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: ECPG Segfault and variable usage question.
@ 2004-02-13 16:07  Edmund Bacon <ebacon@onesystem.com>
  parent: Jürgen Cappel <email@juergen-cappel.de>
  1 sibling, 1 reply; 7+ messages in thread

From: Edmund Bacon @ 2004-02-13 16:07 UTC (permalink / raw)
  To: pgsql-interfaces; +Cc: Jürgen Cappel <email@juergen-cappel.de>

An added data point for this bug

I have seen a similar problem, although it seems to only manifest itself
in long (1000+ line) source files.   It seems to have something to do
with using macros rather than explicit constants to define array
dimensions.  I'd be willing to bet that the below code example would
compile by adding

#define CL_2   (2*CHAR_LENGTH)
...
   char var[CL_2];
...

There seem to be 2 work arounds: either use a shorter macro name, or
break long files into smaller pieces.

On Thu, 2004-02-12 at 12:00, Jürgen Cappel wrote:

> Hello,
> 
> this is a code snippet that causes ECPG to segfault. It's quite tricky
> to produce, as changing the variable name from 'var' to 'myvar' already
> causes things to compile fine ...
> 
> 
> #define CHAR_LENGTH 25
> myfunction ()
> {
>     EXEC SQL BEGIN DECLARE SECTION;
>     char   var[2*CHAR_LENGTH];
>     EXEC SQL END DECLARE SECTION;
> 
>     EXEC SQL DECLARE mycursor CURSOR FOR
> 	 SELECT att1, att2
> 	 FROM mytable
> 	 WHERE att1 LIKE :var ESCAPE '\\';
>     EXEC SQL OPEN mycursor;
> }
> 
> Stack trace was obtained using a snapshot from about 2 weeks ago, ECPG from
> the 7.4.1 release segfaults also.
> 
> #0  0x4015fdcb in chunk_free () from /lib/libc.so.6
> #1  0x4015fc53 in free () from /lib/libc.so.6
> #2  0x080685b7 in dump_variables (list=0x80c1408, mode=1) at variable.c:405
> #3  0x08066d56 in output_statement (
>     stmt=0x80c14f8 "declare mycursor  cursor  for select  att1  , att2
> from mytable where att1  like  ? escape '\\\\'  ", mode=0, con=0x0) at
> output.c:126
> #4  0x0804af02 in yyparse () at preproc.y:780
> #5  0x0806671d in main (argc=8, argv=0xbffff264) at ecpg.c:409
> #6  0x401089ed in __libc_start_main () from /lib/libc.so.6
> 
> 
> Another problem that's giving me headaches trying to find a workaround for
> is the following use of variables as data sources in INSERT/UPDATE
> statements:
> 
> 	:myarray[index[10]]
> 
> Any comments, suggestions, hints ?   Thanks a lot,
> 
> Jürgen
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend

-- 
Edmund Bacon <ebacon@onesystem.com>

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: ECPG Segfault and variable usage question.
@ 2004-02-15 13:42  Michael Meskes <meskes@postgresql.org>
  parent: Jürgen Cappel <email@juergen-cappel.de>
  1 sibling, 0 replies; 7+ messages in thread

From: Michael Meskes @ 2004-02-15 13:42 UTC (permalink / raw)
  To: Jürgen Cappel <email@juergen-cappel.de>; +Cc: pgsql-interfaces

On Thu, Feb 12, 2004 at 08:00:12PM +0100, Jürgen Cappel wrote:
> this is a code snippet that causes ECPG to segfault. It's quite tricky

I took this code as a.pgc and ran 'ecpg a.pgc' without any problem. Do
you use any special options for ecpg?

> Stack trace was obtained using a snapshot from about 2 weeks ago, ECPG from
> the 7.4.1 release segfaults also.

Hmm, my 7.4.1 version also compiles this snippet cleanly.

> Another problem that's giving me headaches trying to find a workaround for
> is the following use of variables as data sources in INSERT/UPDATE
> statements:
> 
> 	:myarray[index[10]]
> 
> Any comments, suggestions, hints ?   Thanks a lot,

Could you please try if the following patch helps you?

--- /home/postgres/pgsql-ecpg/preproc/pgc.l	2003-12-29 14:53:04.000000000 +0100
+++ pgc.l	2004-02-15 14:38:43.000000000 +0100
@@ -183,7 +183,7 @@
 
 identifier		{ident_start}{ident_cont}*
 
-array			({ident_cont}|{whitespace}|[\+\-\*\%\/\(\)])*
+array			({ident_cont}|{whitespace}|[\[\]\+\-\*\%\/\(\)])*
 typecast		"::"
 
 /*

This will make it into CVS soon.

Michael
-- 
Michael Meskes
Email: Michael at Fam-Meskes dot De
ICQ: 179140304, AIM/Yahoo: michaelmeskes, Jabber: meskes@jabber.org
Go SF 49ers! Go Rhein Fire! Use Debian GNU/Linux! Use PostgreSQL!



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: ECPG Segfault and variable usage question.
@ 2004-02-15 13:43  Michael Meskes <meskes@postgresql.org>
  parent: Edmund Bacon <ebacon@onesystem.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Michael Meskes @ 2004-02-15 13:43 UTC (permalink / raw)
  To: Edmund Bacon <ebacon@onesystem.com>; +Cc: pgsql-interfaces

On Fri, Feb 13, 2004 at 09:07:34AM -0700, Edmund Bacon wrote:
> I have seen a similar problem, although it seems to only manifest itself
> in long (1000+ line) source files.   It seems to have something to do

Do you have such a file for me to test with? I'd like to find out what's
going wrong here.

Michael
-- 
Michael Meskes
Email: Michael at Fam-Meskes dot De
ICQ: 179140304, AIM/Yahoo: michaelmeskes, Jabber: meskes@jabber.org
Go SF 49ers! Go Rhein Fire! Use Debian GNU/Linux! Use PostgreSQL!



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: ECPG Segfault and variable usage question.
@ 2004-02-17 20:15  Jürgen Cappel <email@juergen-cappel.de>
  0 siblings, 2 replies; 7+ messages in thread

From: Jürgen Cappel @ 2004-02-17 20:15 UTC (permalink / raw)
  To: pgsql-interfaces

Hello Michael,

some more info: the segmentation fault still occurs under Linux (SuSE 8.0)
with today's snapshot. No options used, just the filename as the only arg.
I tried it on Solaris 8 today where it compiles fine. It works on Linux
when I change the variable name from "var" to "myvar" or add a variable in
the DECLARE section, but that can't be the solution. Any idea on how to
find the problem ?

Oh, BTW: the expression   :myarray[index[10]]   compiles OK as of
pgc.l version 1.125 2004/02/15  Thanks for your help !

Jürgen



-----Ursprüngliche Nachricht-----
Von: pgsql-interfaces-owner@postgresql.org
[mailto:pgsql-interfaces-owner@postgresql.org]Im Auftrag von Michael
Meskes
Gesendet: Sonntag, 15. Februar 2004 14:42
An: Jürgen Cappel
Cc: pgsql-interfaces
Betreff: Re: [INTERFACES] ECPG Segfault and variable usage question.


On Thu, Feb 12, 2004 at 08:00:12PM +0100, Jürgen Cappel wrote:
> this is a code snippet that causes ECPG to segfault. It's quite tricky

I took this code as a.pgc and ran 'ecpg a.pgc' without any problem. Do
you use any special options for ecpg?

> Stack trace was obtained using a snapshot from about 2 weeks ago, ECPG
from
> the 7.4.1 release segfaults also.

Hmm, my 7.4.1 version also compiles this snippet cleanly.

> Another problem that's giving me headaches trying to find a workaround for
> is the following use of variables as data sources in INSERT/UPDATE
> statements:
>
> 	:myarray[index[10]]
>
> Any comments, suggestions, hints ?   Thanks a lot,

Could you please try if the following patch helps you?

--- /home/postgres/pgsql-ecpg/preproc/pgc.l	2003-12-29 14:53:04.000000000
+0100
+++ pgc.l	2004-02-15 14:38:43.000000000 +0100
@@ -183,7 +183,7 @@

 identifier		{ident_start}{ident_cont}*

-array			({ident_cont}|{whitespace}|[\+\-\*\%\/\(\)])*
+array			({ident_cont}|{whitespace}|[\[\]\+\-\*\%\/\(\)])*
 typecast		"::"

 /*

This will make it into CVS soon.

Michael
--
Michael Meskes
Email: Michael at Fam-Meskes dot De
ICQ: 179140304, AIM/Yahoo: michaelmeskes, Jabber: meskes@jabber.org
Go SF 49ers! Go Rhein Fire! Use Debian GNU/Linux! Use PostgreSQL!

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: ECPG Segfault and variable usage question.
@ 2004-02-18 16:24  Lee Kindness <lkindness@csl.co.uk>
  parent: Jürgen Cappel <email@juergen-cappel.de>
  1 sibling, 0 replies; 7+ messages in thread

From: Lee Kindness @ 2004-02-18 16:24 UTC (permalink / raw)
  To: Jürgen Cappel <email@juergen-cappel.de>; +Cc: pgsql-interfaces; Lee Kindness <lkindness@csl.co.uk>

Try running your app under Valgrind:

 http://valgrind.kde.org/
 http://developer.kde.org/~sewardj/valgrind-2.1.0.tar.bz2

it'll point out exactly where the seg fault is happening and
why. Remember to compile your app, and libecpg, with debugging
symbols.

L.

Jürgen Cappel writes:
 > Hello Michael,
 > 
 > some more info: the segmentation fault still occurs under Linux (SuSE 8.0)
 > with today's snapshot. No options used, just the filename as the only arg.
 > I tried it on Solaris 8 today where it compiles fine. It works on Linux
 > when I change the variable name from "var" to "myvar" or add a variable in
 > the DECLARE section, but that can't be the solution. Any idea on how to
 > find the problem ?
 > 
 > Oh, BTW: the expression   :myarray[index[10]]   compiles OK as of
 > pgc.l version 1.125 2004/02/15  Thanks for your help !
 > 
 > Jürgen
 > 
 > 
 > 
 > -----Ursprüngliche Nachricht-----
 > Von: pgsql-interfaces-owner@postgresql.org
 > [mailto:pgsql-interfaces-owner@postgresql.org]Im Auftrag von Michael
 > Meskes
 > Gesendet: Sonntag, 15. Februar 2004 14:42
 > An: Jürgen Cappel
 > Cc: pgsql-interfaces
 > Betreff: Re: [INTERFACES] ECPG Segfault and variable usage question.
 > 
 > 
 > On Thu, Feb 12, 2004 at 08:00:12PM +0100, Jürgen Cappel wrote:
 > > this is a code snippet that causes ECPG to segfault. It's quite tricky
 > 
 > I took this code as a.pgc and ran 'ecpg a.pgc' without any problem. Do
 > you use any special options for ecpg?
 > 
 > > Stack trace was obtained using a snapshot from about 2 weeks ago, ECPG
 > from
 > > the 7.4.1 release segfaults also.
 > 
 > Hmm, my 7.4.1 version also compiles this snippet cleanly.
 > 
 > > Another problem that's giving me headaches trying to find a workaround for
 > > is the following use of variables as data sources in INSERT/UPDATE
 > > statements:
 > >
 > > 	:myarray[index[10]]
 > >
 > > Any comments, suggestions, hints ?   Thanks a lot,
 > 
 > Could you please try if the following patch helps you?
 > 
 > --- /home/postgres/pgsql-ecpg/preproc/pgc.l	2003-12-29 14:53:04.000000000
 > +0100
 > +++ pgc.l	2004-02-15 14:38:43.000000000 +0100
 > @@ -183,7 +183,7 @@
 > 
 >  identifier		{ident_start}{ident_cont}*
 > 
 > -array			({ident_cont}|{whitespace}|[\+\-\*\%\/\(\)])*
 > +array			({ident_cont}|{whitespace}|[\[\]\+\-\*\%\/\(\)])*
 >  typecast		"::"
 > 
 >  /*
 > 
 > This will make it into CVS soon.
 > 
 > Michael
 > --
 > Michael Meskes
 > Email: Michael at Fam-Meskes dot De
 > ICQ: 179140304, AIM/Yahoo: michaelmeskes, Jabber: meskes@jabber.org
 > Go SF 49ers! Go Rhein Fire! Use Debian GNU/Linux! Use PostgreSQL!
 > 
 > ---------------------------(end of broadcast)---------------------------
 > TIP 8: explain analyze is your friend
 > 



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: ECPG Segfault and variable usage question.
@ 2004-02-24 10:30  Michael Meskes <meskes@postgresql.org>
  parent: Jürgen Cappel <email@juergen-cappel.de>
  1 sibling, 0 replies; 7+ messages in thread

From: Michael Meskes @ 2004-02-24 10:30 UTC (permalink / raw)
  To: Jürgen Cappel <email@juergen-cappel.de>; +Cc: pgsql-interfaces

On Tue, Feb 17, 2004 at 09:15:20PM +0100, Jürgen Cappel wrote:
> some more info: the segmentation fault still occurs under Linux (SuSE 8.0)
> with today's snapshot. No options used, just the filename as the only arg.
> I tried it on Solaris 8 today where it compiles fine. It works on Linux
> when I change the variable name from "var" to "myvar" or add a variable in
> the DECLARE section, but that can't be the solution. Any idea on how to
> find the problem ?

Run it under an malloc debugger to see where the problem arises. Or
would it be possible to give me a temporary account on that machine so I
can test myself?

Michael
-- 
Michael Meskes
Email: Michael at Fam-Meskes dot De
ICQ: 179140304, AIM/Yahoo: michaelmeskes, Jabber: meskes@jabber.org
Go SF 49ers! Go Rhein Fire! Use Debian GNU/Linux! Use PostgreSQL!



^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2004-02-24 10:30 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-02-12 19:00 ECPG Segfault and variable usage question. Jürgen Cappel <email@juergen-cappel.de>
2004-02-13 16:07 ` Edmund Bacon <ebacon@onesystem.com>
2004-02-15 13:43   ` Michael Meskes <meskes@postgresql.org>
2004-02-15 13:42 ` Michael Meskes <meskes@postgresql.org>
2004-02-17 20:15 Re: ECPG Segfault and variable usage question. Jürgen Cappel <email@juergen-cappel.de>
2004-02-18 16:24 ` Lee Kindness <lkindness@csl.co.uk>
2004-02-24 10:30 ` Michael Meskes <meskes@postgresql.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox