Commit 3cb595ac by Mikael Morin

gfortran.h (gfc_release_symbol): New prototype.

2010-07-30  Mikael Morin  <mikael@gcc.gnu.org>

	* gfortran.h (gfc_release_symbol): New prototype.
	* symbol.c (gfc_release_symbol): New. Code taken from free_sym_tree.
	(gfc_undo_symbols, free_sym_tree, gfc_free_finalizer):
	Use gfc_release_symbol.
	* parse.c (gfc_fixup_sibling_symbols): Ditto.
	* resolve.c (resolve_symbol): Ditto.

From-SVN: r162719
parent 2d5bfc67
2010-07-30 Mikael Morin <mikael@gcc.gnu.org>
* gfortran.h (gfc_release_symbol): New prototype.
* symbol.c (gfc_release_symbol): New. Code taken from free_sym_tree.
(gfc_undo_symbols, free_sym_tree, gfc_free_finalizer):
Use gfc_release_symbol.
* parse.c (gfc_fixup_sibling_symbols): Ditto.
* resolve.c (resolve_symbol): Ditto.
2010-07-29 Tobias Burnus <burnus@net-b.de>
PR fortran/45087
......
......@@ -2523,6 +2523,7 @@ gfc_symtree *gfc_get_unique_symtree (gfc_namespace *);
gfc_user_op *gfc_get_uop (const char *);
gfc_user_op *gfc_find_uop (const char *, gfc_namespace *);
void gfc_free_symbol (gfc_symbol *);
void gfc_release_symbol (gfc_symbol *);
gfc_symbol *gfc_new_symbol (const char *, gfc_namespace *);
gfc_symtree* gfc_find_symtree_in_proc (const char *, gfc_namespace *);
int gfc_find_symbol (const char *, gfc_namespace *, int, gfc_symbol **);
......
......@@ -3792,10 +3792,7 @@ gfc_fixup_sibling_symbols (gfc_symbol *sym, gfc_namespace *siblings)
st->n.sym = sym;
sym->refs++;
/* Free the old (local) symbol. */
old_sym->refs--;
if (old_sym->refs == 0)
gfc_free_symbol (old_sym);
gfc_release_symbol (old_sym);
}
fixup_contained:
......
......@@ -11382,9 +11382,7 @@ resolve_symbol (gfc_symbol *sym)
{
this_symtree = gfc_find_symtree (gfc_current_ns->sym_root,
sym->name);
sym->refs--;
if (!sym->refs)
gfc_free_symbol (sym);
gfc_release_symbol (sym);
symtree->n.sym->refs++;
this_symtree->n.sym = symtree->n.sym;
return;
......
......@@ -2502,6 +2502,31 @@ gfc_free_symbol (gfc_symbol *sym)
}
/* Decrease the reference counter and free memory when we reach zero. */
void
gfc_release_symbol (gfc_symbol *sym)
{
if (sym == NULL)
return;
if (sym->formal_ns != NULL && sym->refs == 2)
{
/* As formal_ns contains a reference to sym, delete formal_ns just
before the deletion of sym. */
gfc_namespace *ns = sym->formal_ns;
sym->formal_ns = NULL;
gfc_free_namespace (ns);
}
sym->refs--;
if (sym->refs > 0)
return;
gcc_assert (sym->refs == 0);
gfc_free_symbol (sym);
}
/* Allocate and initialize a new symbol node. */
gfc_symbol *
......@@ -2893,11 +2918,7 @@ gfc_undo_symbols (void)
gfc_delete_symtree (&p->ns->sym_root, p->name);
p->refs--;
if (p->refs < 0)
gfc_internal_error ("gfc_undo_symbols(): Negative refs");
if (p->refs == 0)
gfc_free_symbol (p);
gfc_release_symbol (p);
continue;
}
......@@ -3107,35 +3128,13 @@ free_uop_tree (gfc_symtree *uop_tree)
static void
free_sym_tree (gfc_symtree *sym_tree)
{
gfc_namespace *ns;
gfc_symbol *sym;
if (sym_tree == NULL)
return;
free_sym_tree (sym_tree->left);
free_sym_tree (sym_tree->right);
sym = sym_tree->n.sym;
sym->refs--;
if (sym->refs < 0)
gfc_internal_error ("free_sym_tree(): Negative refs");
if (sym->formal_ns != NULL && sym->refs == 1)
{
/* As formal_ns contains a reference to sym, delete formal_ns just
before the deletion of sym. */
ns = sym->formal_ns;
sym->formal_ns = NULL;
gfc_free_namespace (ns);
}
else if (sym->refs == 0)
{
/* Go ahead and delete the symbol. */
gfc_free_symbol (sym);
}
gfc_release_symbol (sym_tree->n.sym);
gfc_free (sym_tree);
}
......@@ -3189,13 +3188,7 @@ gfc_free_finalizer (gfc_finalizer* el)
{
if (el)
{
if (el->proc_sym)
{
--el->proc_sym->refs;
if (!el->proc_sym->refs)
gfc_free_symbol (el->proc_sym);
}
gfc_release_symbol (el->proc_sym);
gfc_free (el);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment