Commit 6f155e4b authored by Michael Meeks's avatar Michael Meeks

symbol / function removal for Pista's plugins.

parent a0b33bfc
2000-01-03 Michael Meeks <mmeeks@gnu.org>
* src/func.c (function_remove, function_is_unused): implement.
* src/symbol.c (symbol_is_unused, symbol_remove): implement.
2000-01-03 Gregory McLean <gregm@gnu.org>
* gnumeric.spec.in: Synced with my spec tree. This is in sync with
......
2000-01-03 Michael Meeks <mmeeks@gnu.org>
* src/func.c (function_remove, function_is_unused): implement.
* src/symbol.c (symbol_is_unused, symbol_remove): implement.
2000-01-03 Gregory McLean <gregm@gnu.org>
* gnumeric.spec.in: Synced with my spec tree. This is in sync with
......
......@@ -789,3 +789,40 @@ function_dump_defs (const char *filename)
fclose (output_file);
}
gboolean
function_is_unused (FunctionDefinition *fndef)
{
Symbol *sym;
g_return_val_if_fail (fndef != NULL, FALSE);
g_return_val_if_fail (fndef->name != NULL, FALSE);
sym = symbol_lookup (global_symbol_table, fndef->name);
if (!sym)
return FALSE;
return symbol_is_unused (sym);
}
void
function_remove (FunctionCategory *parent,
FunctionDefinition *fndef)
{
Symbol *sym;
g_return_if_fail (fndef != NULL);
g_return_if_fail (parent != NULL);
g_return_if_fail (function_is_unused (fndef));
sym = symbol_lookup (global_symbol_table, fndef->name);
g_return_if_fail (sym != NULL);
symbol_remove (global_symbol_table, sym);
parent->functions = g_list_remove (parent->functions, fndef);
fndef->fn_type = -1;
g_free (fndef);
}
......@@ -121,6 +121,10 @@ FunctionDefinition *function_add_nodes (FunctionCategory *parent,
char **help,
FunctionNodes *fn);
gboolean function_is_unused (FunctionDefinition *fndef);
void function_remove (FunctionCategory *parent,
FunctionDefinition *fndef);
gpointer function_def_get_fn (FunctionDefinition *fndef);
void function_def_set_user_data (FunctionDefinition *fndef,
gpointer user_data);
......
......@@ -67,7 +67,7 @@ symbol_install (SymbolTable *st, const char *str, SymbolType type, void *data)
g_return_val_if_fail (st != NULL, NULL);
sym = (Symbol *) g_hash_table_lookup (st->hash, str);
if (sym) printf ("Symbol [%s] redefined.\n", str);
if (sym) printf ("(leak) Symbol [%s] redefined.\n", str);
sym = g_new (Symbol, 1);
sym->ref_count = 1;
......@@ -81,6 +81,38 @@ symbol_install (SymbolTable *st, const char *str, SymbolType type, void *data)
return sym;
}
gboolean
symbol_is_unused (Symbol *sym)
{
g_return_val_if_fail (sym != NULL, FALSE);
g_return_val_if_fail (sym->ref_count < 0, FALSE);
return sym->ref_count <= 1;
}
void
symbol_remove (SymbolTable *st, Symbol *sym)
{
g_return_if_fail (st != NULL);
g_return_if_fail (sym != NULL);
g_return_if_fail (st->hash != NULL);
g_return_if_fail (sym->ref_count < 0);
g_return_if_fail (symbol_is_unused (sym));
g_hash_table_remove (st->hash, sym);
if (sym->str)
g_free (sym->str);
sym->str = NULL;
sym->data = NULL;
sym->type = 0;
sym->ref_count = -1;
sym->st = NULL;
g_free (sym);
}
/**
* symbol_ref:
* @sym: The symbol to reference
......
......@@ -26,6 +26,8 @@ Symbol *symbol_lookup (SymbolTable *st, const char *str);
Symbol *symbol_lookup_substr (SymbolTable *st, const char *buffer, int len);
Symbol *symbol_install (SymbolTable *st, const char *str,
SymbolType type, void *data);
void symbol_remove (SymbolTable *st, Symbol *);
gboolean symbol_is_unused (Symbol *);
void symbol_ref (Symbol *);
void symbol_unref (Symbol *);
......
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