pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION
6+ messages / 3 participants
[nested] [flat]

* BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION
@ 2013-11-19 22:39 alexsav23@gmail.com
  2013-11-24 11:55 ` Re: BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION Michael Meskes <meskes@postgresql.org>
  0 siblings, 1 reply; 6+ messages in thread

From: alexsav23@gmail.com @ 2013-11-19 22:39 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      8608
Logged by:          Alexei Savchik
Email address:      alexsav23@gmail.com
PostgreSQL version: 9.3.1
Operating system:   Windows 8 x64
Description:        

void MyFunc( MyClass*unit_address )
{
    EXEC SQL BEGIN DECLARE SECTION;
       unsigned char      var1[sizeof(MyClass)];
    EXEC SQL END DECLARE SECTION;
}


d:\>"c:\Program Files\PostgreSQL\9.3\bin\ecpg.exe"-o 1.c 1.pgc
1.pgc: 4: ERROR: syntax error at or near  "("
error deleting output file "1.c" 


http://stackoverflow.com/questions/20049432/ecpg-sizeof-in-exec-sql-declare-section



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



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

* Re: BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION
  2013-11-19 22:39 BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION alexsav23@gmail.com
@ 2013-11-24 11:55 ` Michael Meskes <meskes@postgresql.org>
  2013-11-24 14:59   ` Re: BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION Boszormenyi Zoltan <zb@cybertec.at>
  0 siblings, 1 reply; 6+ messages in thread

From: Michael Meskes @ 2013-11-24 11:55 UTC (permalink / raw)
  To: alexsav23@gmail.com; +Cc: pgsql-bugs

On Tue, Nov 19, 2013 at 10:39:48PM +0000, alexsav23@gmail.com wrote:
> d:\>"c:\Program Files\PostgreSQL\9.3\bin\ecpg.exe"-o 1.c 1.pgc
> 1.pgc: 4: ERROR: syntax error at or near  "("
> error deleting output file "1.c" 

And another patch to try. Please send me feedback.

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
Jabber: michael.meskes at gmail dot com
VfL Borussia! Força Barça! Go SF 49ers! Use Debian GNU/Linux, PostgreSQL

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

ecpg.sizeof.diff (text/x-diff, 1.0K) download commit 08d1b22b3be2305ad6b83ca275829ff26305f5d7 Author: Michael Meskes <meskes@postgresql.org> Date: Sun Nov 24 12:51:21 2013 +0100 Allow C array definitions to use sizeof(). When parsing C variable definitions ecpg should allow sizeof() operators as array dimensions. diff --git a/src/interfaces/ecpg/preproc/ecpg.trailer b/src/interfaces/ecpg/preproc/ecpg.trailer index 342b7bc..6ef9f1a 100644 --- a/src/interfaces/ecpg/preproc/ecpg.trailer +++ b/src/interfaces/ecpg/preproc/ecpg.trailer @@ -1865,6 +1865,11 @@ Iresult: Iconst { $$ = $1; } | Iresult '%' Iresult { $$ = cat_str(3, $1, mm_strdup("%"), $3); } | ecpg_sconst { $$ = $1; } | ColId { $$ = $1; } + | ColId '(' ColId ')' { if (pg_strcasecmp($1, "sizeof") != 0) + mmerror(PARSE_ERROR, ET_ERROR, "operator not allowed in variable definition"); + else + $$ = cat_str(4,$1, mm_strdup("("), $3, mm_strdup(")")); + } ; execute_rest: /* EMPTY */ { $$ = EMPTY; }
^ permalink raw reply [nested|flat] 6+ messages in thread

* Re: BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION
  2013-11-19 22:39 BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION alexsav23@gmail.com
  2013-11-24 11:55 ` Re: BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION Michael Meskes <meskes@postgresql.org>
@ 2013-11-24 14:59   ` Boszormenyi Zoltan <zb@cybertec.at>
  2013-11-25 08:18     ` Re: BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION Michael Meskes <meskes@postgresql.org>
  0 siblings, 1 reply; 6+ messages in thread

From: Boszormenyi Zoltan @ 2013-11-24 14:59 UTC (permalink / raw)
  To: Michael Meskes <meskes@postgresql.org>; alexsav23@gmail.com; +Cc: pgsql-bugs

2013-11-24 12:55 keltezéssel, Michael Meskes írta:
> On Tue, Nov 19, 2013 at 10:39:48PM +0000, alexsav23@gmail.com wrote:
>> d:\>"c:\Program Files\PostgreSQL\9.3\bin\ecpg.exe"-o 1.c 1.pgc
>> 1.pgc: 4: ERROR: syntax error at or near  "("
>> error deleting output file "1.c"
> And another patch to try. Please send me feedback.

I think it's needlessly narrows the scope of the problem.
Consider this code:

#include <stdio.h>

#define hide_size_of_var sizeof

int main(void) {
     int a[hide_size_of_var(int)];
     int i;

     for (i = 0; i < hide_size_of_var(int); i++) {
         a[i] = i*3;
         printf("i: %d a[i]: %d\n", i, a[i]);
     }

     return 0;
}

It compiles just fine in a C compiler and runs from 0 to 3 as expected.
GCC 4.8.2 doesn't say anything about it with -Wall.

I think you should pass everything through as is inside the '[' and ']' and
let the C compiler fail if the code is not valid.

Best regards,
Zoltán Böszörményi

>
> Michael
>
>


-- 
----------------------------------
Zoltán Böszörményi
Cybertec Schönig & Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
      http://www.postgresql.at/

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

* Re: BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION
  2013-11-19 22:39 BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION alexsav23@gmail.com
  2013-11-24 11:55 ` Re: BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION Michael Meskes <meskes@postgresql.org>
  2013-11-24 14:59   ` Re: BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION Boszormenyi Zoltan <zb@cybertec.at>
@ 2013-11-25 08:18     ` Michael Meskes <meskes@postgresql.org>
  2013-11-25 13:19       ` Re: BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION Boszormenyi Zoltan <zb@cybertec.at>
  0 siblings, 1 reply; 6+ messages in thread

From: Michael Meskes @ 2013-11-25 08:18 UTC (permalink / raw)
  To: Boszormenyi Zoltan <zb@cybertec.at>; +Cc: Michael Meskes <meskes@postgresql.org>; alexsav23@gmail.com; pgsql-bugs

On Sun, Nov 24, 2013 at 03:59:40PM +0100, Boszormenyi Zoltan wrote:
> I think it's needlessly narrows the scope of the problem.
> Consider this code:
> 
> #include <stdio.h>
> 
> #define hide_size_of_var sizeof
> ...

I assume you'd want to put this defined name into a declare section, right?
Well, that's what EXEC SQL DECLARE is for, isn't it?

> I think you should pass everything through as is inside the '[' and ']' and
> let the C compiler fail if the code is not valid.

I prefer catching as much as possible without re-implementing a C-compiler of course.

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
Jabber: michael.meskes at gmail dot com
VfL Borussia! Força Barça! Go SF 49ers! Use Debian GNU/Linux, PostgreSQL


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



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

* Re: BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION
  2013-11-19 22:39 BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION alexsav23@gmail.com
  2013-11-24 11:55 ` Re: BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION Michael Meskes <meskes@postgresql.org>
  2013-11-24 14:59   ` Re: BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION Boszormenyi Zoltan <zb@cybertec.at>
  2013-11-25 08:18     ` Re: BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION Michael Meskes <meskes@postgresql.org>
@ 2013-11-25 13:19       ` Boszormenyi Zoltan <zb@cybertec.at>
  2013-11-25 14:14         ` Re: BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION Michael Meskes <meskes@postgresql.org>
  0 siblings, 1 reply; 6+ messages in thread

From: Boszormenyi Zoltan @ 2013-11-25 13:19 UTC (permalink / raw)
  To: Michael Meskes <meskes@postgresql.org>; +Cc: alexsav23@gmail.com; pgsql-bugs

2013-11-25 09:18 keltezéssel, Michael Meskes írta:
> On Sun, Nov 24, 2013 at 03:59:40PM +0100, Boszormenyi Zoltan wrote:
>> I think it's needlessly narrows the scope of the problem.
>> Consider this code:
>>
>> #include <stdio.h>
>>
>> #define hide_size_of_var sizeof
>> ...
> I assume you'd want to put this defined name into a declare section, right?
> Well, that's what EXEC SQL DECLARE is for, isn't it?

Of course. And of course you meant EXEC SQL DEFINE.

The attached code throws syntax errors over sizeof(int) and
sizeof(struct somestruct). I compiled GIT HEAD which contains your fix:

commit 08d1b22b3be2305ad6b83ca275829ff26305f5d7
Author: Michael Meskes <meskes@postgresql.org>
Date:   Sun Nov 24 12:51:21 2013 +0100

     Allow C array definitions to use sizeof().

     When parsing C variable definitions ecpg should allow sizeof() operators as array 
dimensions.

So it seems it's not enough, try these with the attached code:

Succeeds:
$ ecpg array-sizeof.pgc

These fail:
$ ecpg -D TRY_INT array-sizeof.pgc
array-sizeof.pgc:24: ERROR: syntax error at or near "int"

$ ecpg -D TRY_STRUCT array-sizeof.pgc
array-sizeof.pgc:30: ERROR: syntax error at or near "struct"

The attached patch fixes "sizeof(struct something)" but the
"simple_type" variant that should also accept
[signed|unsigned]{char|short|int|long|long long}
causes 2 shift/reduce problems when processing preproc.y.

Best regards,
Zoltán Böszörményi

>
>> I think you should pass everything through as is inside the '[' and ']' and
>> let the C compiler fail if the code is not valid.
> I prefer catching as much as possible without re-implementing a C-compiler of course.
>
> Michael


-- 
----------------------------------
Zoltán Böszörményi
Cybertec Schönig & Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
      http://www.postgresql.at/

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

array-sizeof.pgc (text/plain, 975B) download #include <stdio.h> EXEC SQL BEGIN DECLARE SECTION; EXEC SQL DEFINE hide_size_of_var_2 hide_size_of_var; EXEC SQL DEFINE hide_size_of_var sizeof; typedef int myint; struct named_struct { int a; int b; }; typedef struct named_struct mystruct; EXEC SQL END DECLARE SECTION; int main(void) { EXEC SQL BEGIN DECLARE SECTION; /* Parsed successfully */ int unused1[sizeof(myint)]; int unused2[hide_size_of_var(myint)]; int unused3[hide_size_of_var_2(myint)]; EXEC SQL IFDEF TRY_INT; int unused4[sizeof(int)]; int unused5[hide_size_of_var(int)]; int unused6[hide_size_of_var_2(int)]; EXEC SQL ENDIF; EXEC SQL IFDEF TRY_STRUCT; int unused7[sizeof(struct named_struct)]; int unused8[hide_size_of_var(struct named_struct)]; int unused9[hide_size_of_var_2(struct named_struct)]; EXEC SQL ENDIF; int unused10[sizeof(mystruct)]; int unused11[hide_size_of_var(mystruct)]; int unused12[hide_size_of_var_2(mystruct)]; EXEC SQL END DECLARE SECTION; return 0; }
array-sizeof-struct-fix.patch (text/x-patch, 1.2K) download diff --git a/src/interfaces/ecpg/preproc/ecpg.trailer b/src/interfaces/ecpg/preproc/ecpg.trailer index 6ef9f1a..3a7dbed 100644 --- a/src/interfaces/ecpg/preproc/ecpg.trailer +++ b/src/interfaces/ecpg/preproc/ecpg.trailer @@ -1867,8 +1867,22 @@ Iresult: Iconst { $$ = $1; } | ColId { $$ = $1; } | ColId '(' ColId ')' { if (pg_strcasecmp($1, "sizeof") != 0) mmerror(PARSE_ERROR, ET_ERROR, "operator not allowed in variable definition"); - else - $$ = cat_str(4,$1, mm_strdup("("), $3, mm_strdup(")")); + else + $$ = cat_str(4, $1, mm_strdup("("), $3, mm_strdup(")")); + } +/* + | ColId '(' simple_type ')' + { if (pg_strcasecmp($1, "sizeof") != 0) + mmerror(PARSE_ERROR, ET_ERROR, "operator not allowed in variable definition"); + else + $$ = cat_str(4, $1, mm_strdup("("), $3, mm_strdup(")")); + } +*/ + | ColId '(' s_struct_union ColId ')' + { if (pg_strcasecmp($1, "sizeof") != 0) + mmerror(PARSE_ERROR, ET_ERROR, "operator not allowed in variable definition"); + else + $$ = cat_str(5, $1, mm_strdup("("), $3, $4, mm_strdup(")")); } ;
^ permalink raw reply [nested|flat] 6+ messages in thread

* Re: BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION
  2013-11-19 22:39 BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION alexsav23@gmail.com
  2013-11-24 11:55 ` Re: BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION Michael Meskes <meskes@postgresql.org>
  2013-11-24 14:59   ` Re: BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION Boszormenyi Zoltan <zb@cybertec.at>
  2013-11-25 08:18     ` Re: BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION Michael Meskes <meskes@postgresql.org>
  2013-11-25 13:19       ` Re: BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION Boszormenyi Zoltan <zb@cybertec.at>
@ 2013-11-25 14:14         ` Michael Meskes <meskes@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Michael Meskes @ 2013-11-25 14:14 UTC (permalink / raw)
  To: Boszormenyi Zoltan <zb@cybertec.at>; +Cc: Michael Meskes <meskes@postgresql.org>; alexsav23@gmail.com; pgsql-bugs

On Mon, Nov 25, 2013 at 02:19:13PM +0100, Boszormenyi Zoltan wrote:
> Of course. And of course you meant EXEC SQL DEFINE.

Yes. :)

> The attached code throws syntax errors over sizeof(int) and
> sizeof(struct somestruct). I compiled GIT HEAD which contains your fix:

Thanks for spotting this. Using ColId as type name was pretty stupid of me, in particular when a non-terminal var_type already exists.

> The attached patch fixes "sizeof(struct something)" but the
> "simple_type" variant that should also accept
> [signed|unsigned]{char|short|int|long|long long}
> causes 2 shift/reduce problems when processing preproc.y.

That's because with the additional rules we add CHAR and DOUBLE twice. Should be fixed now.

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
Jabber: michael.meskes at gmail dot com
VfL Borussia! Força Barça! Go SF 49ers! Use Debian GNU/Linux, PostgreSQL


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



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


end of thread, other threads:[~2013-11-25 14:14 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-11-19 22:39 BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION alexsav23@gmail.com
2013-11-24 11:55 ` Michael Meskes <meskes@postgresql.org>
2013-11-24 14:59   ` Boszormenyi Zoltan <zb@cybertec.at>
2013-11-25 08:18     ` Michael Meskes <meskes@postgresql.org>
2013-11-25 13:19       ` Boszormenyi Zoltan <zb@cybertec.at>
2013-11-25 14:14         ` 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