[gnumeric] Dependencies: names with sheet-less cell references were not handled right.



commit 30ad06c778b5a13755c65ba3e3d5e98bce0059f2
Author: Morten Welinder <terra gnome org>
Date:   Sat May 2 20:31:47 2009 -0400

    Dependencies: names with sheet-less cell references were not handled right.
---
 ChangeLog       |    8 ++++++++
 NEWS            |    1 +
 src/expr-name.c |    9 +++++++++
 src/expr.c      |   28 +++++++++++++---------------
 4 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 3faff91..b2b1195 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2009-05-02  Morten Welinder  <terra gnome org>
 
+	* src/expr-name.c (expr_name_handle_references): Handle NULL sheet
+	from expr_name_handle_references.  Fixes #581117.
+
+	* src/expr.c (gnm_insert_unique): Renamed from
+	g_slist_insert_unique.  Insert NULL too, if appropriate.
+	(do_referenced_sheets): Correctly handle right-hand side of a
+	range if it is NULL.
+
 	* src/position.c (eval_pos_init_sheet, parse_pos_init,
 	parse_pos_init_sheet): Constify.
 
diff --git a/NEWS b/NEWS
index 2363363..e580171 100644
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,7 @@ Morten:
 	* Fix various R1C1 bugs.
 	* Fix precision for xml saving inside graphs.
 	* Fix long-sheet-name GUI issue.  [#580837]
+	* Fix dependency problem with names.  [#581117]
 
 --------------------------------------------------------------------------
 Gnumeric 1.9.6
diff --git a/src/expr-name.c b/src/expr-name.c
index 0b606f4..98f1595 100644
--- a/src/expr-name.c
+++ b/src/expr-name.c
@@ -319,12 +319,21 @@ static void
 expr_name_handle_references (GnmNamedExpr *nexpr, gboolean add)
 {
 	GSList *sheets, *ptr;
+	Sheet *base_sheet = nexpr->pos.sheet;
 
 	sheets = gnm_expr_top_referenced_sheets (nexpr->texpr);
+	if (g_slist_find (sheets, NULL) &&
+	    !g_slist_find (sheets, base_sheet))
+		sheets = g_slist_prepend (sheets, base_sheet);
+
 	for (ptr = sheets ; ptr != NULL ; ptr = ptr->next) {
 		Sheet *sheet = ptr->data;
 		GnmNamedExpr *found;
 
+		/* Handled above.  */
+		if (!sheet)
+			continue;
+
 		/* No need to do anything during destruction */
 		if (sheet->deps == NULL)
 			continue;
diff --git a/src/expr.c b/src/expr.c
index 8756a3b..853d826 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -2266,9 +2266,9 @@ cellref_boundingbox (GnmCellRef const *cr, GnmRange *bound)
 }
 
 static GSList *
-g_slist_insert_unique (GSList *list, gpointer data)
+gnm_insert_unique (GSList *list, gpointer data)
 {
-	if (data != NULL && g_slist_find (list, data) == NULL)
+	if (g_slist_find (list, data) == NULL)
 		return g_slist_prepend (list, data);
 	return list;
 }
@@ -2280,11 +2280,8 @@ do_referenced_sheets (GnmExpr const *expr, GSList *sheets)
 	case GNM_EXPR_OP_RANGE_CTOR:
 	case GNM_EXPR_OP_INTERSECT:
 	case GNM_EXPR_OP_ANY_BINARY:
-		return do_referenced_sheets (
-			expr->binary.value_a,
-			do_referenced_sheets (
-				expr->binary.value_b,
-				sheets));
+		sheets = do_referenced_sheets (expr->binary.value_a, sheets);
+		return do_referenced_sheets (expr->binary.value_b, sheets);
 
 	case GNM_EXPR_OP_ANY_UNARY:
 		return do_referenced_sheets (expr->unary.value, sheets);
@@ -2308,16 +2305,17 @@ do_referenced_sheets (GnmExpr const *expr, GSList *sheets)
 		return sheets;
 
 	case GNM_EXPR_OP_CELLREF:
-		return g_slist_insert_unique (sheets, expr->cellref.ref.sheet);
+		return gnm_insert_unique (sheets, expr->cellref.ref.sheet);
 
 	case GNM_EXPR_OP_CONSTANT: {
 		GnmValue const *v = expr->constant.value;
 		if (v->type != VALUE_CELLRANGE)
 			return sheets;
-		return g_slist_insert_unique (
-			g_slist_insert_unique (sheets,
-					       v->v_range.cell.a.sheet),
-			v->v_range.cell.b.sheet);
+		sheets = gnm_insert_unique (sheets, v->v_range.cell.a.sheet);
+		/* A NULL b sheet means a's sheet.  Do not insert that.  */
+		if (v->v_range.cell.b.sheet)
+			sheets = gnm_insert_unique (sheets, v->v_range.cell.b.sheet);
+		return sheets;
 	}
 
 	case GNM_EXPR_OP_ARRAY_CORNER:
@@ -2507,7 +2505,7 @@ do_gnm_expr_get_ranges (GnmExpr const *expr, GSList *ranges)
 	default: {
 		GnmValue *v = gnm_expr_get_range (expr);
 		if (v)
-			return g_slist_insert_unique (ranges, v);
+			return gnm_insert_unique (ranges, v);
 		return ranges;
 	}
 	}
@@ -2964,10 +2962,10 @@ gnm_expr_top_eval (GnmExprTop const *texpr,
 /**
  * gnm_expr_top_referenced_sheets :
  * @texpr :
- * @sheets : usually NULL.
  *
  * Generates a list of the sheets referenced by the supplied expression.
- * Caller must free the list.
+ * Caller must free the list.  Note, that NULL may occur in the result
+ * if the expression has a range or cellref without a sheet.
  */
 GSList *
 gnm_expr_top_referenced_sheets (GnmExprTop const *texpr)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]