- Only use typedefs inside their scope.
authorMichael Meskes <meskes@postgresql.org>
Sun, 27 Jun 2004 12:32:47 +0000 (12:32 +0000)
committerMichael Meskes <meskes@postgresql.org>
Sun, 27 Jun 2004 12:32:47 +0000 (12:32 +0000)
- Variables that are out of scope, were not removed all the time.
- Make a varchar NULL set everything to 0 when not using indicators.

src/interfaces/ecpg/ecpglib/misc.c
src/interfaces/ecpg/preproc/extern.h
src/interfaces/ecpg/preproc/preproc.y
src/interfaces/ecpg/preproc/type.h
src/interfaces/ecpg/preproc/variable.c

index defc8105f4cf38e08157207a34341892010233b3..402b93ef63b08c5b66248bd2a77531c3ee553377 100644 (file)
@@ -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));
index 3383682fc46620f1499f4ac7f2259f590b6d34c0..3d1088a20715ef57002cda9bbdecc0b2f4d6e481 100644 (file)
@@ -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);
index 51fa961b0d0546e6cee6cd57dd1eb2abf548dc50..7f699a055ac17c1bb06c0ecaebe547ec7b31328c 100644 (file)
@@ -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);
index 2dd511ff854f284399082fc024e5f1b042e68382..4091a562ab42ffb06bdab96dbc8a93f1c4125cc7 100644 (file)
@@ -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;
 };
 
index 9663e29ef03efbf353e2a80404f54ad57694437e..f13f7375cb0f0a84e14d4f3692e8535e1d8092de 100644 (file)
@@ -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;
+       }
    }
 }