Commit b09ae39f authored by Miguel de Icaza's avatar Miguel de Icaza Committed by Arturo Espinosa

New routine used to release exprtrees that we discard during parsing.

2000-01-02  Miguel de Icaza  <miguel@gnu.org>

	* src/parser.y (release_const_tree): New routine used to release
	exprtrees that we discard during parsing.

	array_expressions: The various NUMBERS used in this rule are
	never actually linked into the ExprTree, we are only interested in
	them to pull a couple of integers from it.  We now release them
	after we construct the formula.  This fixes the leaks reported by
	Morten.
parent 637064d7
......@@ -1373,9 +1373,9 @@ enum CellRefRelocate {
};
static enum CellRefRelocate
cellref_relocate (CellRef * const ref,
EvalPosition const * const pos,
struct expr_relocate_info const * const rinfo)
cellref_relocate (const CellRef * ref,
const EvalPosition * const pos,
const struct expr_relocate_info * const rinfo)
{
/* For row or column refs
* Ref From To
......@@ -1475,9 +1475,9 @@ cellref_relocate (CellRef * const ref,
* the move.
*/
ExprTree *
expr_relocate (ExprTree const *expr,
EvalPosition const *pos,
struct expr_relocate_info const *rinfo)
expr_relocate (const ExprTree *expr,
const EvalPosition *pos,
const struct expr_relocate_info *rinfo)
{
g_return_val_if_fail (expr != NULL, NULL);
......
......@@ -180,9 +180,9 @@ struct expr_relocate_info {
int col_offset, row_offset;/* and offset by this amount */
};
ExprTree * expr_relocate (ExprTree const *expr,
EvalPosition const *pos,
struct expr_relocate_info const *info);
ExprTree *expr_relocate (const ExprTree *expr,
const EvalPosition *pos,
const struct expr_relocate_info *info);
int expr_tree_get_const_int (ExprTree const *const expr);
char const * expr_tree_get_const_str (ExprTree const *const expr);
......
......@@ -27,6 +27,7 @@ static void alloc_glist (GList *l);
static void forget_glist (GList *list);
static void forget_array (GList *array);
static void forget_tree (ExprTree *tree);
static void release_const_tree (ExprTree *tree);
static void alloc_list_free (void);
static Value*v_new (void);
static void v_forget (Value *v);
......@@ -100,19 +101,23 @@ build_binop (ExprTree *l, Operation op, ExprTree *r)
}
static ExprTree *
build_array_formula (ExprTree *func,
ExprTree *expr_num_cols, ExprTree *expr_num_rows,
ExprTree *expr_x, ExprTree *expr_y)
build_array_formula (ExprTree *func, int cols, int rows, int x, int y)
{
int const num_cols = expr_tree_get_const_int (expr_num_cols);
int const num_rows = expr_tree_get_const_int (expr_num_rows);
int const x = expr_tree_get_const_int (expr_x);
int const y = expr_tree_get_const_int (expr_y);
ExprTree * res = expr_tree_array_formula (x, y, num_rows, num_cols);
ExprTree *res = expr_tree_array_formula (x, y, rows, cols);
res->u.array.corner.func.expr = func;
return res;
}
static void
release_const_tree (ExprTree *tree)
{
g_assert (tree->oper == OPER_CONSTANT);
g_free (tree->u.constant);
g_free (tree);
}
static ExprTree *
build_array (GList *cols)
{
......@@ -146,7 +151,8 @@ build_array (GList *cols)
value_array_set (array, x, y, v);
v_forget (v);
g_free (expr);
x++;
row = g_list_next (row);
}
......@@ -195,7 +201,21 @@ int yyparse(void);
line: exp { *parser_result = $1; }
| '{' exp '}' '(' NUMBER SEPARATOR NUMBER ')' '[' NUMBER ']' '[' NUMBER ']' {
*parser_result = build_array_formula ($2, $7, $5, $13, $10) ;
const int num_cols = expr_tree_get_const_int ($7);
const int num_rows = expr_tree_get_const_int ($5);
const int x = expr_tree_get_const_int ($13);
const int y = expr_tree_get_const_int ($10);
*parser_result = build_array_formula ($2, num_cols, num_rows, x, y);
/*
* Notice that we have no use for the ExprTrees for the NUMBERS,
* so we deallocate them.
*/
release_const_tree ($7);
release_const_tree ($5);
release_const_tree ($13);
release_const_tree ($10);
}
| error { parser_error = PARSE_ERR_SYNTAX; }
......@@ -389,18 +409,20 @@ make_string_return (char const *string, gboolean const possible_number)
static int
return_symbol (Symbol *sym)
{
ExprTree *e = p_new (ExprTree);
ExprTree *e = NULL;
int type = STRING;
e->ref_count = 1;
symbol_ref (sym);
switch (sym->type){
case SYMBOL_FUNCTION:
e = p_new (ExprTree);
e->ref_count = 1;
e->oper = OPER_FUNCALL;
type = FUNCALL;
e->u.function.symbol = sym;
e->u.function.arg_list = NULL;
printf ("%p -> %s\n", e, sym->str);
break;
case SYMBOL_VALUE:
......@@ -412,6 +434,8 @@ return_symbol (Symbol *sym)
v = v_new ();
value_copy_to (v, dv);
e = p_new (ExprTree);
e->ref_count = 1;
e->oper = OPER_CONSTANT;
e->u.constant = v;
type = CONSTANT;
......@@ -822,6 +846,7 @@ gnumeric_expr_parser (const char *expr, const ParsePosition *pp,
if (parser_error == PARSE_OK)
alloc_list_free ();
else {
printf ("Parser error!\n");
alloc_clean ();
*parser_result = NULL;
}
......
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