gnumeric r16595 - in trunk: . plugins/fn-info src



Author: mortenw
Date: Wed May 21 17:13:16 2008
New Revision: 16595
URL: http://svn.gnome.org/viewvc/gnumeric?rev=16595&view=rev

Log:
2008-05-21  Morten Welinder  <terra gnome org>

	* src/value-sheet.c (value_area_foreach): Always NULL ->cell_iter.

2008-05-21  Morten Welinder  <terra gnome org>

	* functions.c (gnumeric_countblank): Use value_area_* functions.
	Fixes #534204.



Modified:
   trunk/ChangeLog
   trunk/NEWS
   trunk/plugins/fn-info/ChangeLog
   trunk/plugins/fn-info/functions.c
   trunk/src/parser.y
   trunk/src/value-sheet.c

Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS	(original)
+++ trunk/NEWS	Wed May 21 17:13:16 2008
@@ -21,6 +21,7 @@
 	* Fix parser crashes.  [#533951]  [#534131]
 	* Fix RANDEXPPOW hang.  [#533965]
 	* Fix array evaluation problem.  [#533953]
+	* Fix COUNTBLANK crash.  [#534204]
 
 --------------------------------------------------------------------------
 Gnumeric 1.9.0

Modified: trunk/plugins/fn-info/functions.c
==============================================================================
--- trunk/plugins/fn-info/functions.c	(original)
+++ trunk/plugins/fn-info/functions.c	Wed May 21 17:13:16 2008
@@ -1226,33 +1226,45 @@
 };
 
 static GnmValue *
-cb_countblank (GnmCellIter const *iter, gpointer user)
+cb_countblank (GnmValueIter const *iter, gpointer user)
 {
-	gnm_cell_eval (iter->cell);
-	if (!gnm_cell_is_empty (iter->cell)) {
-		GnmValue const *v = iter->cell->value;
-		if (VALUE_IS_STRING (v) && value_peek_string (v)[0] == 0)
-			; /* Nothing -- the empty string is blank.  */
-		else
-			*((int *)user) -= 1;
-	}
+	GnmValue const *v = iter->v;
+
+	if (VALUE_IS_STRING (v) && value_peek_string (v)[0] == 0)
+		; /* Nothing -- the empty string is blank.  */
+	else if (VALUE_IS_EMPTY (v))
+		; /* Nothing  */
+	else
+		*((int *)user) -= 1;
+
 	return NULL;
 }
 
 static GnmValue *
 gnumeric_countblank (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
 {
-	Sheet *start_sheet, *end_sheet;
-	GnmRange r;
-	int count;
-
-	gnm_rangeref_normalize (&argv[0]->v_range.cell, ei->pos,
-		&start_sheet, &end_sheet, &r);
-	count = range_width (&r) * range_height	(&r);
-	if (start_sheet != end_sheet && end_sheet != NULL)
-		count *= 1 + abs (end_sheet->index_in_wb - start_sheet->index_in_wb);
-	workbook_foreach_cell_in_range (ei->pos, argv[0],
-		CELL_ITER_IGNORE_BLANK, &cb_countblank, &count);
+	GnmValue const *v = argv[0];
+	int count =
+		value_area_get_width (v, ei->pos) *
+		value_area_get_height (v, ei->pos);
+	int nsheets = 1;
+
+	if (v->type == VALUE_CELLRANGE) {
+		GnmRange r;
+		Sheet *start_sheet, *end_sheet;
+
+		gnm_rangeref_normalize (&v->v_range.cell, ei->pos,
+					&start_sheet, &end_sheet, &r);
+
+		if (start_sheet != end_sheet && end_sheet != NULL)
+			nsheets = 1 + abs (end_sheet->index_in_wb -
+					   start_sheet->index_in_wb);
+	}
+
+	count *= nsheets;
+
+	value_area_foreach (v, ei->pos, CELL_ITER_IGNORE_BLANK,
+			    &cb_countblank, &count);
 
 	return value_new_int (count);
 }

Modified: trunk/src/parser.y
==============================================================================
--- trunk/src/parser.y	(original)
+++ trunk/src/parser.y	Wed May 21 17:13:16 2008
@@ -314,7 +314,7 @@
 }
 
 /*
- * Build an array expresssion.
+ * Build an array expression.
  *
  * Returns NULL on failure.  Caller must YYERROR in that case.
  */

Modified: trunk/src/value-sheet.c
==============================================================================
--- trunk/src/value-sheet.c	(original)
+++ trunk/src/value-sheet.c	Wed May 21 17:13:16 2008
@@ -304,13 +304,14 @@
 			(CellIterFunc) cb_wrapper_foreach_cell_in_area, &wrap);
 	}
 
+	v_iter.ep = ep;
+	v_iter.region = v;
+	v_iter.cell_iter = NULL;
+
 	/* If not an array, apply func to singleton */
-	v_iter.ep	= ep;
-	v_iter.region	= v;
         if (v->type != VALUE_ARRAY) {
 		v_iter.x = v_iter.y = 0;
 		v_iter.v = v;
-		v_iter.cell_iter = NULL;
 		return (*func) (&v_iter, user_data);
 	}
 



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