Skip to content

Commit d9635bb

Browse files
committed
make workspace load more robust
there were some issues with error handling
1 parent f40be19 commit d9635bb

File tree

6 files changed

+85
-25
lines changed

6 files changed

+85
-25
lines changed

src/compile.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,9 @@ compile_check(Compile *compile)
17581758
void
17591759
compile_error_set(Compile *compile)
17601760
{
1761+
g_assert(strlen(error_get_top()) > 0);
1762+
g_assert(strlen(error_get_sub()) > 0);
1763+
17611764
(void) slist_map(compile->exprs, (SListMapFn) expr_error_set, NULL);
17621765
}
17631766

src/expr.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,9 @@ expr_strip(Expr *expr)
257257

258258
/* Break top links we're part of.
259259
*/
260-
if (slist_map(expr->static_links,
261-
(SListMapFn) link_expr_destroy, NULL))
260+
if (slist_map(expr->static_links, (SListMapFn) link_expr_destroy, NULL))
262261
return expr;
263-
if (slist_map(expr->dynamic_links,
264-
(SListMapFn) link_expr_destroy, NULL))
262+
if (slist_map(expr->dynamic_links, (SListMapFn) link_expr_destroy, NULL))
265263
return expr;
266264
g_assert(!expr->static_links);
267265
g_assert(!expr->dynamic_links);
@@ -460,21 +458,25 @@ expr_error_set(Expr *expr)
460458
#ifdef DEBUG_ERROR
461459
printf("expr_error_set: error in ");
462460
symbol_name_print(expr->sym);
463-
printf(": %s %s\n", error_get_top(), error_get_sub());
461+
printf(": top=\"%s\" sub=\"%s\"\n", error_get_top(), error_get_sub());
464462
#endif /*DEBUG_ERROR*/
465463

464+
g_assert(strlen(error_get_top()) > 0);
465+
g_assert(strlen(error_get_sub()) > 0);
466+
466467
VIPS_SETSTR(expr->error_sub, error_get_sub());
467468

469+
char txt[MAX_LINELENGTH];
470+
VipsBuf buf = VIPS_BUF_STATIC(txt);
471+
468472
// add " in A1" etc. to the top error
473+
vips_buf_appends(&buf, error_get_top());
469474
if (expr->row) {
470-
char txt[MAX_LINELENGTH];
471-
VipsBuf buf = VIPS_BUF_STATIC(txt);
472-
475+
vips_buf_appends(&buf, " in ");
473476
row_qualified_name(expr->row, &buf);
474-
error_top(_("%s in %s"), error_get_top(), vips_buf_all(&buf));
475477
}
476478

477-
VIPS_SETSTR(expr->error_top, error_get_top());
479+
VIPS_SETSTR(expr->error_top, vips_buf_all(&buf));
478480

479481
/* Zap the value of the expr ... it may contain pointers to
480482
* dead stuff.
@@ -525,12 +527,14 @@ expr_error_clear(Expr *expr)
525527
printf("\n");
526528
#endif /*DEBUG_ERROR*/
527529

528-
expr->err = FALSE;
529530
expr_error_all = g_slist_remove(expr_error_all, expr);
530531
if (expr->row)
531532
row_error_clear(expr->row);
532533

533-
if (is_top(expr->sym) && expr->sym->expr == expr)
534+
expr->err = FALSE;
535+
536+
if (is_top(expr->sym) &&
537+
expr->sym->expr == expr)
534538
symbol_state_change(expr->sym);
535539
}
536540
}

src/itext.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,11 @@ itext_add_string(PElement *base, VipsBuf *buf)
125125
return base;
126126
}
127127

128-
/* Buffer full? Abort string print.
128+
/* Buffer full? Abort string print, though it's not an error (return
129+
* NULL).
129130
*/
130131
if (buf->full)
131-
return base;
132+
return NULL;
132133

133134
return NULL;
134135
}
@@ -335,8 +336,7 @@ itext_add_element(VipsBuf *buf, PElement *base,
335336
vips_buf_appends(buf, "'");
336337
}
337338
else if (PEISCOMPLEX(base)) {
338-
itext_add_complex(PEGETREALPART(base), PEGETIMAGPART(base),
339-
buf);
339+
itext_add_complex(PEGETREALPART(base), PEGETIMAGPART(base), buf);
340340
}
341341
else if (PEISMANAGEDSTRING(base)) {
342342
Managedstring *managedstring = PEGETMANAGEDSTRING(base);
@@ -596,10 +596,13 @@ itext_update_model(Heapmodel *heapmodel)
596596

597597
/* If this is a non-edited row, update the source.
598598
*/
599-
if (!itext->edited || row == row->top_row) {
599+
if (!itext->edited ||
600+
row == row->top_row) {
600601
const char *new_formula;
601602

602-
if (expr && expr->compile && expr->compile->rhstext)
603+
if (expr &&
604+
expr->compile &&
605+
expr->compile->rhstext)
603606
new_formula = expr->compile->rhstext;
604607
else
605608
new_formula = vips_buf_all(&itext->decompile);

src/row.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ row_dirty_set(Row *row, gboolean clear_error)
254254
void
255255
row_error_set(Row *row)
256256
{
257+
workspace_error_sanity(row->ws);
258+
257259
if (!row->err) {
258260
Workspace *ws = row->ws;
259261
gboolean was_clear = ws->errors == NULL;
@@ -295,6 +297,8 @@ row_error_set(Row *row)
295297
expr_error_set(row->top_row->expr);
296298
}
297299
}
300+
301+
workspace_error_sanity(row->ws);
298302
}
299303

300304
/* Clear error state ... called from expr_error_clear() ... don't call this
@@ -303,7 +307,9 @@ row_error_set(Row *row)
303307
void
304308
row_error_clear(Row *row)
305309
{
306-
if (row->err && row->ws) {
310+
workspace_error_sanity(row->ws);
311+
312+
if (row->err) {
307313
Workspace *ws = row->ws;
308314

309315
ws->errors = g_slist_remove(ws->errors, row);
@@ -321,9 +327,9 @@ row_error_clear(Row *row)
321327
* The code may contain pointers to dead symbols if we were in
322328
* error because they were undefined.
323329
*/
324-
if (row->child_rhs && row->child_rhs->itext)
325-
heapmodel_set_modified(
326-
HEAPMODEL(row->child_rhs->itext), TRUE);
330+
if (row->child_rhs &&
331+
row->child_rhs->itext)
332+
heapmodel_set_modified(HEAPMODEL(row->child_rhs->itext), TRUE);
327333

328334
/* All errors gone? Ws changed too.
329335
*/
@@ -333,11 +339,14 @@ row_error_clear(Row *row)
333339
/* Is this a local row? Clear the top row error as well, in
334340
* case it's in error because of us.
335341
*/
336-
if (row != row->top_row && row->top_row->expr) {
342+
if (row != row->top_row &&
343+
row->top_row->expr) {
337344
expr_error_clear(row->top_row->expr);
338345
row_dirty_set(row->top_row, TRUE);
339346
}
340347
}
348+
349+
workspace_error_sanity(row->ws);
341350
}
342351

343352
/* Break a dependency.
@@ -387,9 +396,11 @@ row_dispose(GObject *gobject)
387396

388397
/* Reset state. Also see row_parent_remove().
389398
*/
390-
row_hide_dependents(row);
391399
if (row->expr)
392400
expr_error_clear(row->expr);
401+
402+
row_hide_dependents(row);
403+
393404
if (col &&
394405
col->last_select == row)
395406
col->last_select = NULL;
@@ -1571,6 +1582,8 @@ row_recomp_row(Row *row)
15711582
static void
15721583
row_recomp_all(Row *top_row)
15731584
{
1585+
workspace_error_sanity(top_row->ws);
1586+
15741587
/* Rebuild all dirty rows.
15751588
*/
15761589
while (!top_row->err && top_row->recomp) {
@@ -1608,6 +1621,8 @@ row_recomp_all(Row *top_row)
16081621
pgraph(&top_row->expr->root);
16091622
#endif /*DEBUG*/
16101623
}
1624+
1625+
workspace_error_sanity(top_row->ws);
16111626
}
16121627

16131628
static GSList *

src/workspace.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1429,9 +1429,37 @@ workspace_selected_group(Workspace *ws)
14291429
return TRUE;
14301430
}
14311431

1432+
void
1433+
workspace_error_sanity(Workspace *ws)
1434+
{
1435+
#ifdef DEBUG
1436+
if (ws->errors) {
1437+
g_assert(!ws->last_error || ws->last_error->err);
1438+
g_assert(!ws->last_error || g_slist_find(ws->errors, ws->last_error));
1439+
1440+
GSList *p;
1441+
for (p = ws->errors; p; p = p->next) {
1442+
Row *row = ROW(p->data);
1443+
1444+
g_assert(row->top_row);
1445+
g_assert(row->top_row->expr);
1446+
1447+
g_assert(row->err);
1448+
g_assert(row->expr);
1449+
g_assert(strlen(row->expr->error_top) > 0);
1450+
g_assert(strlen(row->expr->error_sub) > 0);
1451+
}
1452+
}
1453+
else
1454+
g_assert(ws->last_error == NULL);
1455+
#endif /*DEBUG*/
1456+
}
1457+
14321458
static Row *
14331459
workspace_test_error(Row *row, Workspace *ws, int *found)
14341460
{
1461+
g_assert(row->err);
1462+
14351463
/* Found next?
14361464
*/
14371465
if (*found)
@@ -1452,11 +1480,14 @@ workspace_test_error(Row *row, Workspace *ws, int *found)
14521480
gboolean
14531481
workspace_next_error(Workspace *ws)
14541482
{
1483+
workspace_error_sanity(ws);
1484+
14551485
int found;
14561486

14571487
if (!ws->errors) {
14581488
error_top(_("No errors in tab"));
1459-
error_sub("%s", _("there are no errors (that I can see) in this tab"));
1489+
error_sub("%s",
1490+
_("there are no errors (that I can see) in this tab"));
14601491
return FALSE;
14611492
}
14621493

@@ -1484,6 +1515,8 @@ workspace_next_error(Workspace *ws)
14841515
error_top("%s", ws->last_error->expr->error_top);
14851516
error_sub("%s", ws->last_error->expr->error_sub);
14861517

1518+
workspace_error_sanity(ws);
1519+
14871520
return TRUE;
14881521
}
14891522

src/workspace.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ void workspace_selected_remove_yesno(Workspace *ws, GtkWindow *parent);
173173
gboolean workspace_selected_ungroup(Workspace *ws);
174174
gboolean workspace_selected_group(Workspace *ws);
175175

176+
void workspace_error_sanity(Workspace *ws);
177+
176178
gboolean workspace_next_error(Workspace *ws);
177179

178180
void workspace_set_mode(Workspace *ws, WorkspaceMode mode);

0 commit comments

Comments
 (0)