From: Michael Meskes Date: Fri, 7 May 2004 13:43:29 +0000 (+0000) Subject: - Fixed bug that reversed string length in typedefs. X-Git-Tag: REL7_4_3~33 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=86ac85b6ae3f6c85be5a4810c35443b4f260007b;p=postgresql - Fixed bug that reversed string length in typedefs. --- diff --git a/src/interfaces/ecpg/preproc/extern.h b/src/interfaces/ecpg/preproc/extern.h index 4ff8298e71..3383682fc4 100644 --- a/src/interfaces/ecpg/preproc/extern.h +++ b/src/interfaces/ecpg/preproc/extern.h @@ -79,7 +79,7 @@ extern void add_variable_to_head(struct arguments **, struct variable *, struct extern void add_variable_to_tail(struct arguments **, struct variable *, struct variable *); extern void dump_variables(struct arguments *, int); extern struct typedefs *get_typedef(char *); -extern void adjust_array(enum ECPGttype, char **, char **, char *, char *, int); +extern void adjust_array(enum ECPGttype, char **, char **, char *, char *, int, bool); extern void reset_variables(void); extern void check_indicator(struct ECPGtype *); extern void remove_variables(int); diff --git a/src/interfaces/ecpg/preproc/preproc.y b/src/interfaces/ecpg/preproc/preproc.y index 85ba9473e6..51a6824a79 100644 --- a/src/interfaces/ecpg/preproc/preproc.y +++ b/src/interfaces/ecpg/preproc/preproc.y @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.263.2.11 2004/05/05 15:06:21 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.263.2.12 2004/05/07 13:43:29 meskes Exp $ */ /* Copyright comment */ %{ @@ -4649,8 +4649,7 @@ type_declaration: S_TYPEDEF mmerror(PARSE_ERROR, ET_ERROR, errortext); } } - - adjust_array($3.type_enum, &dimension, &length, $3.type_dimension, $3.type_index, *$4?1:0); + adjust_array($3.type_enum, &dimension, &length, $3.type_dimension, $3.type_index, *$4?1:0, true); this = (struct typedefs *) mm_alloc(sizeof(struct typedefs)); @@ -5098,7 +5097,7 @@ variable: opt_pointer ECPGColLabelCommon opt_array_bounds opt_initializer char *length = $3.index2; /* length of string */ char dim[14L]; - adjust_array(actual_type[struct_level].type_enum, &dimension, &length, actual_type[struct_level].type_dimension, actual_type[struct_level].type_index, strlen($1)); + adjust_array(actual_type[struct_level].type_enum, &dimension, &length, actual_type[struct_level].type_dimension, actual_type[struct_level].type_index, strlen($1), false); switch (actual_type[struct_level].type_enum) { @@ -5488,7 +5487,7 @@ ECPGTypedef: TYPE_P } } - adjust_array($5.type_enum, &dimension, &length, $5.type_dimension, $5.type_index, *$7?1:0); + adjust_array($5.type_enum, &dimension, &length, $5.type_dimension, $5.type_index, *$7?1:0, false); this = (struct typedefs *) mm_alloc(sizeof(struct typedefs)); @@ -5546,7 +5545,7 @@ ECPGVar: SQL_VAR mmerror(PARSE_ERROR, ET_ERROR, "Initializer not allowed in EXEC SQL VAR command"); else { - adjust_array($5.type_enum, &dimension, &length, $5.type_dimension, $5.type_index, *$7?1:0); + adjust_array($5.type_enum, &dimension, &length, $5.type_dimension, $5.type_index, *$7?1:0, false); switch ($5.type_enum) { diff --git a/src/interfaces/ecpg/preproc/variable.c b/src/interfaces/ecpg/preproc/variable.c index c4dfbb0f18..9663e29ef0 100644 --- a/src/interfaces/ecpg/preproc/variable.c +++ b/src/interfaces/ecpg/preproc/variable.c @@ -459,7 +459,7 @@ get_typedef(char *name) } void -adjust_array(enum ECPGttype type_enum, char **dimension, char **length, char *type_dimension, char *type_index, int pointer_len) +adjust_array(enum ECPGttype type_enum, char **dimension, char **length, char *type_dimension, char *type_index, int pointer_len, bool type_definition) { if (atoi(type_index) >= 0) { @@ -484,7 +484,6 @@ adjust_array(enum ECPGttype type_enum, char **dimension, char **length, char *ty { snprintf(errortext, sizeof(errortext), "No multilevel (more than 2) pointer supported %d", pointer_len); mmerror(PARSE_ERROR, ET_FATAL, errortext); -/* mmerror(PARSE_ERROR, ET_FATAL, "No multilevel (more than 2) pointer supported %d",pointer_len);*/ } if (pointer_len > 1 && type_enum != ECPGt_char && type_enum != ECPGt_unsigned_char) @@ -544,7 +543,11 @@ adjust_array(enum ECPGttype type_enum, char **dimension, char **length, char *ty * make sure we return length = -1 for arrays without * given bounds */ - if (atoi(*dimension) < 0) + if (atoi(*dimension) < 0 && !type_definition) + /* + * do not change this for typedefs + * since it will be changed later on when the variable is defined + */ *length = make_str("1"); else if (atoi(*dimension) == 0) *length = make_str("-1");