please apply patch
----- Original Message -----
From: Nicolas Bazin
To: PostgreSQL-development
Cc: Tom Lane ; Bruce Momjian ; Michael Meskes
Sent: Thursday, March 28, 2002 9:30 AM
Subject: Always the same ecpg bug - please (re)apply patch
Here is the description:
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 in 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 then apply the patch to pgc.l.
The patch moves the test of the scope of an ifdef block to the end of the file beeing parsed, including all includes files, ... .
For the record, this patch was applied a first time by bruce then overwritten by Micheal and reapplied by him. But the big mystery is that there is no trace of that in CVS ????
Nicolas
Attachments:
ecpg.patchapplication/octet-stream; name=ecpg.patchDownload
*** postgresql-7.2.1/src/interfaces/ecpg/preproc/pgc.l Thu Mar 28 10:03:48 2002
--- postgresql/src/interfaces/ecpg/preproc/pgc.l Thu Mar 28 10:05:26 2002
***************
*** 837,842 ****
}
<<EOF>> {
if ( preproc_tos > 0 )
{
preproc_tos = 0;
--- 837,843 ----
}
<<EOF>> {
+ if (yy_buffer == NULL) {
if ( preproc_tos > 0 )
{
preproc_tos = 0;
***************
*** 842,849 ****
preproc_tos = 0;
mmerror(PARSE_ERROR, ET_FATAL, "Missing 'EXEC SQL ENDIF;'");
}
-
- if (yy_buffer == NULL)
yyterminate();
else
{
--- 843,848 ----
preproc_tos = 0;
mmerror(PARSE_ERROR, ET_FATAL, "Missing 'EXEC SQL ENDIF;'");
}
yyterminate();
}
else
***************
*** 845,850 ****
if (yy_buffer == NULL)
yyterminate();
else
{
struct _yy_buffer *yb = yy_buffer;
--- 844,850 ----
mmerror(PARSE_ERROR, ET_FATAL, "Missing 'EXEC SQL ENDIF;'");
}
yyterminate();
+ }
else
{
struct _yy_buffer *yb = yy_buffer;
*** postgresql-7.2.1/src/interfaces/ecpg/test/test1.pgc Sun Jan 13 08:52:09 2002
--- postgresql/src/interfaces/ecpg/test/test1.pgc Thu Mar 28 09:58:25 2002
***************
*** 17,22 ****
/* comment */
exec sql define AMOUNT 6;
exec sql type intarray is int[AMOUNT];
exec sql type string is char(8);
--- 17,23 ----
/* comment */
exec sql define AMOUNT 6;
+ exec sql define NAMELEN 8;
exec sql type intarray is int[AMOUNT];
***************
*** 19,25 ****
exec sql define AMOUNT 6;
exec sql type intarray is int[AMOUNT];
- exec sql type string is char(8);
typedef int intarray[AMOUNT];
--- 20,25 ----
exec sql define NAMELEN 8;
exec sql type intarray is int[AMOUNT];
typedef int intarray[AMOUNT];
***************
*** 27,32 ****
main ()
{
exec sql begin declare section;
intarray amount;
int increment=100;
char name[AMOUNT][8];
--- 27,34 ----
main ()
{
exec sql begin declare section;
+ exec sql ifdef NAMELEN;
+ typedef char string[NAMELEN];
intarray amount;
int increment=100;
char name[AMOUNT][NAMELEN];
***************
*** 29,35 ****
exec sql begin declare section;
intarray amount;
int increment=100;
! char name[AMOUNT][8];
char letter[AMOUNT][1];
struct name_letter_struct
{
--- 31,37 ----
typedef char string[NAMELEN];
intarray amount;
int increment=100;
! char name[AMOUNT][NAMELEN];
char letter[AMOUNT][1];
struct name_letter_struct
{
***************
*** 33,39 ****
char letter[AMOUNT][1];
struct name_letter_struct
{
! char name[8];
int amount;
char letter;
} name_letter[AMOUNT];
--- 35,41 ----
char letter[AMOUNT][1];
struct name_letter_struct
{
! char name[NAMELEN];
int amount;
char letter;
} name_letter[AMOUNT];
***************
*** 37,42 ****
int amount;
char letter;
} name_letter[AMOUNT];
struct ind_struct
{
short a;
--- 39,45 ----
int amount;
char letter;
} name_letter[AMOUNT];
+ exec sql endif;
struct ind_struct
{
short a;
***************
*** 61,68 ****
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));
strcpy(msg, "commit");
exec sql at main commit;
--- 64,71 ----
exec sql connect to pm;
strcpy(msg, "create");
! 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;
***************
*** 114,120 ****
int a = amount[i];
exec sql end declare section;
! strncpy(n, name[i], 8);
printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
amount[i]+=1000;
--- 117,123 ----
int a = amount[i];
exec sql end declare section;
! 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;