From: Bruce Momjian Date: Fri, 5 Apr 2002 11:39:47 +0000 (+0000) Subject: When a macro is replaced by the preprocessor, pgc.l reaches a end of X-Git-Tag: REL7_3~1776 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=811f7df27454577d723e7f59dd840b09c5286913;p=postgresql When a macro is replaced by the preprocessor, pgc.l reaches a end of file, which is not the actual end of the file. One side effect of that is that if you are i n a ifdef block, you get a wrong error telling you that a endif is missing. This patch corrects pgc.l and also adds a test of this problem to test1.pgc. To convince you apply the patch to test1.pgc first then try to compile the test the n apply the patch to pgc.l. The patch moves the test of the scope of an ifdef block to the end of the file b eeing parsed, including all includes files, ... . Nicolas Bazin --- diff --git a/src/interfaces/ecpg/preproc/pgc.l b/src/interfaces/ecpg/preproc/pgc.l index 5341d09301..27ba1c9375 100644 --- a/src/interfaces/ecpg/preproc/pgc.l +++ b/src/interfaces/ecpg/preproc/pgc.l @@ -12,7 +12,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.89 2002/03/24 18:22:21 tgl Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.90 2002/04/05 11:39:45 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -837,14 +837,14 @@ cppline {space}*#(.*\\{space})*.* } <> { + if (yy_buffer == NULL) { if ( preproc_tos > 0 ) { preproc_tos = 0; mmerror(PARSE_ERROR, ET_FATAL, "Missing 'EXEC SQL ENDIF;'"); } - - if (yy_buffer == NULL) yyterminate(); + } else { struct _yy_buffer *yb = yy_buffer; diff --git a/src/interfaces/ecpg/test/test1.pgc b/src/interfaces/ecpg/test/test1.pgc index 0c23f240f6..8eb27c3a27 100644 --- a/src/interfaces/ecpg/test/test1.pgc +++ b/src/interfaces/ecpg/test/test1.pgc @@ -17,9 +17,9 @@ static void warn(void) /* comment */ exec sql define AMOUNT 6; +exec sql define NAMELEN 8; exec sql type intarray is int[AMOUNT]; -exec sql type string is char(8); typedef int intarray[AMOUNT]; @@ -27,16 +27,19 @@ int main () { exec sql begin declare section; +exec sql ifdef NAMELEN; + typedef char string[NAMELEN]; intarray amount; int increment=100; - char name[AMOUNT][8]; + char name[AMOUNT][NAMELEN]; char letter[AMOUNT][1]; struct name_letter_struct { - char name[8]; + char name[NAMELEN]; int amount; char letter; } name_letter[AMOUNT]; +exec sql endif; struct ind_struct { short a; @@ -62,8 +65,8 @@ exec sql end declare section; exec sql connect to pm; strcpy(msg, "create"); - exec sql at main create table "Test" (name char(8), amount int, letter char(1)); - exec sql create table "Test" (name char(8), amount int, letter char(1)); + exec sql at main create table "Test" (name char(NAMELEN), amount int, letter char(1)); + exec sql create table "Test" (name char(NAMELEN), amount int, letter char(1)); strcpy(msg, "commit"); exec sql at main commit; @@ -115,7 +118,7 @@ exec sql end declare section; int a = amount[i]; exec sql end declare section; - strncpy(n, name[i], 8); + strncpy(n, name[i], NAMELEN); printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l); amount[i]+=1000;