ECPG preprocessor for PostgreSQL 7.4.1, 7.4.2 doubles const,
volatile, static, and register keywords before variables,
declared as VARCHAR.

I attach to this mail example for this, and patch for PostgreSQL
7.4.1, that solves this problem (this patch also applicable to
PostgreSQL 7.4.2 too)

-- 
Sergey N. Yatskevich <[EMAIL PROTECTED]>
GosNIIAS

Attachment: start.sh
Description: application/shellscript

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ecpgtype.h>
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <math.h>


EXEC SQL INCLUDE sqlca;   
EXEC SQL BEGIN DECLARE SECTION;
  int n;
  extern int i, y;
  VARCHAR vc1[128];
  extern VARCHAR vc2[128];
  volatile VARCHAR vc3[128];
  const VARCHAR vc4[128] = {10, "0123456789"};

  unsigned char bt1[128];
  extern unsigned char bt2[128];

  unsigned char btout1[128];
  extern unsigned char btout2[128];
  unsigned int lbt, lbt1, lbt2;
  int cint;
  extern double cdouble;
EXEC SQL END DECLARE SECTION; 

///////////////////////////////////////////////////////////////////////////////////////////////////////
int  main ( int argc, char *argv[] )
///////////////////////////////////////////////////////////////////////////////////////////////////////
{        
 sprintf(vc1.arr,"varchar1");
 printf("TEST: %s %s\n",vc1.arr,vc4.arr);
}
Index: src/interfaces/ecpg/preproc/preproc.y
===================================================================
RCS file: /mnt/disk/cvsroot/pgsql/src/interfaces/ecpg/preproc/preproc.y,v
retrieving revision 1.1.1.3
diff -u -r1.1.1.3 preproc.y
--- src/interfaces/ecpg/preproc/preproc.y	25 Dec 2003 10:58:24 -0000	1.1.1.3
+++ src/interfaces/ecpg/preproc/preproc.y	24 May 2004 14:13:42 -0000
@@ -19,7 +19,6 @@
 static int	QueryIsRule = 0, FoundInto = 0;
 static int	initializer = 0;
 static struct this_type actual_type[STRUCT_DEPTH];
-static char *actual_storage[STRUCT_DEPTH];
 static char *actual_startline[STRUCT_DEPTH];
 
 /* temporarily store struct members while creating the data structure */
@@ -4419,6 +4418,8 @@
 			actual_type[struct_level].type_dimension = $2.type_dimension;
 			actual_type[struct_level].type_index = $2.type_index;
 			actual_type[struct_level].type_sizeof = $2.type_sizeof;
+
+			actual_startline[struct_level] = hashline_number();
 		}
 		variable_list ';'
 		{
@@ -4430,7 +4431,6 @@
 			actual_type[struct_level].type_dimension = $1.type_dimension;
 			actual_type[struct_level].type_index = $1.type_index;
 			actual_type[struct_level].type_sizeof = $1.type_sizeof;
-			actual_storage[struct_level] = EMPTY;
 
 			actual_startline[struct_level] = hashline_number();
 		}
@@ -4687,6 +4687,8 @@
 			actual_type[struct_level].type_dimension = $2.type_dimension;
 			actual_type[struct_level].type_index = $2.type_index;
 			actual_type[struct_level].type_sizeof = $2.type_sizeof;
+
+			actual_startline[struct_level] = hashline_number();
 		}
 		variable_list ';'
 		{
@@ -4698,7 +4700,6 @@
 			actual_type[struct_level].type_dimension = $1.type_dimension;
 			actual_type[struct_level].type_index = $1.type_index;
 			actual_type[struct_level].type_sizeof = $1.type_sizeof;
-			actual_storage[struct_level] = EMPTY;
 			
 			actual_startline[struct_level] = hashline_number();
 		}
@@ -4714,18 +4715,15 @@
 
 storage_declaration: storage_clause storage_modifier
 		{
-			actual_storage[struct_level] = cat2_str(mm_strdup($1), mm_strdup($2));
-			actual_startline[struct_level] = hashline_number();
+			$$ = cat2_str ($1, $2);
 		}
 		| storage_clause
 		{
-			actual_storage[struct_level] = mm_strdup($1);
-			actual_startline[struct_level] = hashline_number();
+			$$ = $1;
 		}
 		| storage_modifier
 		{
-			actual_storage[struct_level] = mm_strdup($1);
-			actual_startline[struct_level] = hashline_number();
+			$$ = $1;
 		}
 		;
 
@@ -4951,7 +4949,7 @@
 			
 			ECPGfree_struct_member(struct_member_list[struct_level]);
 			struct_member_list[struct_level] = NULL;
-			free(actual_storage[struct_level--]);
+			struct_level--;
 			if (strncmp($1.su, "struct", sizeof("struct")-1) == 0)
 				su_type.type_enum = ECPGt_struct;
 			else
@@ -5001,7 +4999,7 @@
 		{
 			ECPGfree_struct_member(struct_member_list[struct_level]);
 			struct_member_list[struct_level] = NULL;
-			free(actual_storage[struct_level--]);
+			struct_level--;
 			$$ = cat_str(4, $1, make_str("{"), $4, make_str("}"));
 		}
 		;
@@ -5126,9 +5124,9 @@
 						mmerror(PARSE_ERROR, ET_ERROR, "pointer to varchar are not implemented");
 
 					if (strcmp(dimension, "0") == 0)
-						$$ = cat_str(7, mm_strdup(actual_storage[struct_level]), make2_str(make_str(" struct varchar_"), mm_strdup($2)), make_str(" { int len; char arr["), mm_strdup(length), make_str("]; } *"), mm_strdup($2), $4);
+						$$ = cat_str(6, make2_str(make_str(" struct varchar_"), mm_strdup($2)), make_str(" { int len; char arr["), mm_strdup(length), make_str("]; } *"), mm_strdup($2), $4);
 					else
-					   $$ = cat_str(8, mm_strdup(actual_storage[struct_level]), make2_str(make_str(" struct varchar_"), mm_strdup($2)), make_str(" { int len; char arr["), mm_strdup(length), make_str("]; } "), mm_strdup($2), mm_strdup(dim), $4);
+						$$ = cat_str(7, make2_str(make_str(" struct varchar_"), mm_strdup($2)), make_str(" { int len; char arr["), mm_strdup(length), make_str("]; } "), mm_strdup($2), mm_strdup(dim), $4);
 					break;
 
 				case ECPGt_char:
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faqs/FAQ.html

Reply via email to