From: Boszormenyi Zoltan <zb@cybertec.at>
To: Michael Meskes <meskes@postgresql.org>
Cc: alexsav23@gmail.com
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION
Date: Mon, 25 Nov 2013 14:19:13 +0100
Message-ID: <52934E51.8030000@cybertec.at> (raw)
In-Reply-To: <20131125081838.GA16770@feivel.credativ.lan>
References: <E1VitxU-00034v-I6@wrigleys.postgresql.org>
<20131124115517.GA1658@feivel.credativ.lan>
<5292145C.5000508@cybertec.at>
<20131125081838.GA16770@feivel.credativ.lan>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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.dehttp://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-bugsAttachments: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) downloaddiff --git a/src/interfaces/ecpg/preproc/ecpg.trailer b/src/interfaces/ecpg/preproc/ecpg.trailerindex 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(")"));
}
;
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: zb@cybertec.at, meskes@postgresql.org, alexsav23@gmail.com
Subject: Re: BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION
In-Reply-To: <52934E51.8030000@cybertec.at>
References: <E1VitxU-00034v-I6@wrigleys.postgresql.org> <20131124115517.GA1658@feivel.credativ.lan> <5292145C.5000508@cybertec.at> <20131125081838.GA16770@feivel.credativ.lan> <52934E51.8030000@cybertec.at>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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