From: Michael Meskes Date: Sun, 27 Jun 2004 12:32:47 +0000 (+0000) Subject: - Only use typedefs inside their scope. X-Git-Tag: REL7_4_4~25 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a3c695d0c2fc4aa09babaa0993caf00caabcd8c4;p=thirdparty%2Fpostgresql.git - Only use typedefs inside their scope. - Variables that are out of scope, were not removed all the time. - Make a varchar NULL set everything to 0 when not using indicators. --- diff --git a/src/interfaces/ecpg/ecpglib/misc.c b/src/interfaces/ecpg/ecpglib/misc.c index defc8105f4c..402b93ef63b 100644 --- a/src/interfaces/ecpg/ecpglib/misc.c +++ b/src/interfaces/ecpg/ecpglib/misc.c @@ -1,4 +1,4 @@ -/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.16.2.1 2003/11/24 13:11:27 petere Exp $ */ +/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.16.2.2 2004/06/27 12:32:45 meskes Exp $ */ #define POSTGRES_ECPG_INTERNAL #include "postgres_fe.h" @@ -296,6 +296,7 @@ ECPGset_informix_null(enum ECPGttype type, void *ptr) break; case ECPGt_varchar: *(((struct ECPGgeneric_varchar *) ptr)->arr) = 0x00; + ((struct ECPGgeneric_varchar *) ptr)->len = 0; break; case ECPGt_decimal: memset((char *) ptr, 0, sizeof(decimal)); diff --git a/src/interfaces/ecpg/preproc/extern.h b/src/interfaces/ecpg/preproc/extern.h index 3383682fc46..3d1088a2071 100644 --- a/src/interfaces/ecpg/preproc/extern.h +++ b/src/interfaces/ecpg/preproc/extern.h @@ -82,6 +82,7 @@ extern struct typedefs *get_typedef(char *); 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_typedefs(int); extern void remove_variables(int); extern struct variable *new_variable(const char *, struct ECPGtype *, int); extern ScanKeyword *ScanKeywordLookup(char *text); diff --git a/src/interfaces/ecpg/preproc/preproc.y b/src/interfaces/ecpg/preproc/preproc.y index 51fa961b0d0..7f699a055ac 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.16 2004/06/17 11:52:59 meskes Exp $ */ +/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.263.2.17 2004/06/27 12:32:47 meskes Exp $ */ /* Copyright comment */ %{ @@ -575,7 +575,7 @@ statement: ecpgstart opt_at stmt ';' { connection = NULL; } | c_thing { fprintf(yyout, "%s", $1); free($1); } | CPP_LINE { fprintf(yyout, "%s", $1); free($1); } | '{' { braces_open++; fputs("{", yyout); } - | '}' { remove_variables(braces_open--); fputs("}", yyout); } + | '}' { remove_typedefs(braces_open); remove_variables(braces_open--); fputs("}", yyout); } ; opt_at: AT connection_target @@ -4656,6 +4656,7 @@ type_declaration: S_TYPEDEF /* initial definition */ this->next = types; this->name = $5; + this->brace_level = braces_open; this->type = (struct this_type *) mm_alloc(sizeof(struct this_type)); this->type->type_enum = $3.type_enum; this->type->type_str = mm_strdup($5); @@ -4974,6 +4975,7 @@ struct_union_type_with_symbol: s_struct_union_symbol /* initial definition */ this->next = types; this->name = mm_strdup(su_type.type_str); + this->brace_level = braces_open; this->type = (struct this_type *) mm_alloc(sizeof(struct this_type)); this->type->type_enum = su_type.type_enum; this->type->type_str = mm_strdup(su_type.type_str); @@ -5493,6 +5495,7 @@ ECPGTypedef: TYPE_P /* initial definition */ this->next = types; this->name = $3; + this->brace_level = braces_open; this->type = (struct this_type *) mm_alloc(sizeof(struct this_type)); this->type->type_enum = $5.type_enum; this->type->type_str = mm_strdup($3); diff --git a/src/interfaces/ecpg/preproc/type.h b/src/interfaces/ecpg/preproc/type.h index 2dd511ff854..4091a562ab4 100644 --- a/src/interfaces/ecpg/preproc/type.h +++ b/src/interfaces/ecpg/preproc/type.h @@ -122,26 +122,27 @@ struct cursor struct typedefs { - char *name; - struct this_type *type; - struct ECPGstruct_member *struct_member_list; - struct typedefs *next; + char *name; + struct this_type *type; + struct ECPGstruct_member *struct_member_list; + int brace_level; + struct typedefs *next; }; struct _defines { - char *old; - char *new; - int pertinent; + char *old; + char *new; + int pertinent; struct _defines *next; }; /* This is a linked list of the variable names and types. */ struct variable { - char *name; + char *name; struct ECPGtype *type; - int brace_level; + int brace_level; struct variable *next; }; diff --git a/src/interfaces/ecpg/preproc/variable.c b/src/interfaces/ecpg/preproc/variable.c index 9663e29ef03..f13f7375cb0 100644 --- a/src/interfaces/ecpg/preproc/variable.c +++ b/src/interfaces/ecpg/preproc/variable.c @@ -275,13 +275,47 @@ find_variable(char *name) return (p); } +void +remove_typedefs(int brace_level) +{ + struct typedefs *p, + *prev; + + for (p = prev = types; p;) + { + if (p->brace_level >= brace_level) + { + /* remove it */ + if (p == types) + prev = types = p->next; + else + prev->next = p->next; + + if (p->type->type_enum == ECPGt_struct || p->type->type_enum == ECPGt_union) + free(p->struct_member_list); + free(p->type); + free(p->name); + free(p); + if (prev == types) + p = types; + else + p = prev ? prev->next : NULL; + } + else + { + prev = p; + p = prev->next; + } + } +} + void remove_variables(int brace_level) { struct variable *p, *prev; - for (p = prev = allvariables; p; p = p ? p->next : NULL) + for (p = prev = allvariables; p;) { if (p->brace_level >= brace_level) { @@ -326,10 +360,16 @@ remove_variables(int brace_level) ECPGfree_type(p->type); free(p->name); free(p); - p = prev; + if (prev == allvariables) + p = allvariables; + else + p = prev ? prev->next : NULL; } else + { prev = p; + p = prev->next; + } } }