Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vkw4l-0000pX-Ld for pgsql-bugs@arkaria.postgresql.org; Mon, 25 Nov 2013 13:19:43 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Vkw4k-0000u3-Nl for pgsql-bugs@arkaria.postgresql.org; Mon, 25 Nov 2013 13:19:42 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vkw4i-0000tu-FX for pgsql-bugs@postgresql.org; Mon, 25 Nov 2013 13:19:40 +0000 Received: from [87.118.86.135] (helo=mail.cybertec.at) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vkw4a-0001HX-9j; Mon, 25 Nov 2013 13:19:39 +0000 Received: from localhost.localdomain (unknown [87.242.12.103]) by mail.cybertec.at (Postfix) with ESMTPSA id 87DFA3900396; Mon, 25 Nov 2013 13:19:13 +0000 (UTC) Message-ID: <52934E51.8030000@cybertec.at> Date: Mon, 25 Nov 2013 14:19:13 +0100 From: Boszormenyi Zoltan User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 MIME-Version: 1.0 To: Michael Meskes CC: alexsav23@gmail.com, pgsql-bugs@postgresql.org Subject: Re: BUG #8608: ECPG: sizeof() in EXEC SQL DECLARE SECTION References: <20131124115517.GA1658@feivel.credativ.lan> <5292145C.5000508@cybertec.at> <20131125081838.GA16770@feivel.credativ.lan> In-Reply-To: <20131125081838.GA16770@feivel.credativ.lan> Content-Type: multipart/mixed; boundary="------------020909040401000809000804" X-Host-Lookup-Failed: Reverse DNS lookup failed for 87.118.86.135 (deferred) X-Pg-Spam-Score: -1.1 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org This is a multi-part message in MIME format. --------------020909040401000809000804 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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 >> >> #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 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/ --------------020909040401000809000804 Content-Type: text/plain; charset=UTF-8; name="array-sizeof.pgc" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="array-sizeof.pgc" I2luY2x1ZGUgPHN0ZGlvLmg+CgpFWEVDIFNRTCBCRUdJTiBERUNMQVJFIFNF Q1R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kZV9zaXplX29mX3ZhcihteXN0cnVjdCldOwoJaW50IHVudXNlZDEyW2hp ZGVfc2l6ZV9vZl92YXJfMihteXN0cnVjdCldOwoKCUVYRUMgU1FMIEVORCBE RUNMQVJFIFNFQ1RJT047CgoJcmV0dXJuIDA7Cn0K --------------020909040401000809000804 Content-Type: text/x-patch; name="array-sizeof-struct-fix.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="array-sizeof-struct-fix.patch" 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(")")); } ; --------------020909040401000809000804 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --------------020909040401000809000804--