- Variables that are out of scope, were not removed all the time.
- Make a varchar NULL set everything to 0 when not using indicators.
-/* $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"
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));
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);
-/* $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 */
%{
| 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
/* 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);
/* 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);
/* 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);
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;
};
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)
{
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;
+ }
}
}