summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrés <andmarti@gmail.com>2021-03-22 16:19:44 -0300
committerAndrés <andmarti@gmail.com>2021-03-22 16:19:44 -0300
commitddc4c6a4453980be88c45ba208d7d13bf7821f7c (patch)
treec77edcd0b3d3e3742f2ef15ffb0401eae29c764b /src
parent9a2530e03ead79a41b9df943cbcf826cebd4fdbc (diff)
Work on issues #473 #201
Diffstat (limited to 'src')
-rw-r--r--src/interp.c19
-rw-r--r--src/undo.c1
2 files changed, 16 insertions, 4 deletions
diff --git a/src/interp.c b/src/interp.c
index 4c9f6a5..c1264c3 100644
--- a/src/interp.c
+++ b/src/interp.c
@@ -1051,14 +1051,14 @@ double eval(register struct ent * ent, register struct enode * e) {
}
// Changed 06/03/2021 for #issue 499
if (ent && ent->expr != NULL && getVertex(graph, ent, 0) == NULL) GraphAddVertex(graph, ent);
-
return (e->e.k);
+
case GETENT:
if (ent && getVertex(graph, ent, 0) == NULL) GraphAddVertex(graph, ent);
return (eval(ent, e->e.o.left));
case O_VAR: {
struct ent * vp = e->e.v.vp;
- //FIXME sc_debug("vp %d %d", vp->row, vp->col);
+ //sc_debug("var %d %d", vp->row, vp->col);
if (vp && ent && vp->row == ent->row && vp->col == ent->col && !(vp->flags & is_deleted) ) {
sc_error("Circular reference in eval (cell %s%d)", coltoa(vp->col), vp->row);
//ERR propagates. comment to make it not to.
@@ -1068,7 +1068,6 @@ double eval(register struct ent * ent, register struct enode * e) {
GraphAddEdge( getVertex(graph, lookat(ent->row, ent->col), 1), getVertex(graph, lookat(vp->row, vp->col), 1) ) ;
return (double) 0;
}
-
if (vp && vp->cellerror == CELLERROR && !(vp->flags & is_deleted)) {
// here we store the dependences in a graph
if (ent && vp) GraphAddEdge( getVertex(graph, lookat(ent->row, ent->col), 1),
@@ -1107,6 +1106,14 @@ double eval(register struct ent * ent, register struct enode * e) {
// here we store the dependences in a graph
if (ent && vp) {
+ if (GraphIsReachable(getVertex(graph, lookat(ent->row, ent->col), 0), getVertex(graph, lookat(vp->row, vp->col), 0), 1)) {
+ sc_debug("Circular reference in eval (cell %s%d)", coltoa(vp->col), vp->row);
+ e->op = ERR_;
+ e->e.o.left = NULL;
+ e->e.o.right = NULL;
+ cellerror = CELLERROR;
+ return (double) 0;
+ }
GraphAddEdge( getVertex(graph, lookat(ent->row, ent->col), 1), getVertex(graph, lookat(vp->row, vp->col), 1) ) ;
}
@@ -1117,6 +1124,7 @@ double eval(register struct ent * ent, register struct enode * e) {
if (vp->cellerror == CELLERROR) {
return (double) 0;
}
+
return (vp->v);
}
case SUM:
@@ -1143,6 +1151,11 @@ double eval(register struct ent * ent, register struct enode * e) {
for (row=minr; row <= maxr; row++) {
for (col=minc; col <= maxc; col++) {
if (ent == NULL) continue;
+ if (ent->row == row && ent->col == col) {
+ sc_error("Circular reference in eval (cell %s%d)", coltoa(col), row);
+ cellerror = CELLERROR;
+ return (double) 0;
+ }
GraphAddEdge(getVertex(graph, lookat(ent->row, ent->col), 1), getVertex(graph, lookat(row, col), 1));
}
}
diff --git a/src/undo.c b/src/undo.c
index b7de582..6130c61 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -407,7 +407,6 @@ void copy_to_undostruct (int row_desde, int col_desde, int row_hasta, int col_ha
// not repeated - we malloc an ent and add it to list
struct ent * e = (struct ent *) malloc( (unsigned) sizeof(struct ent) );
cleanent(e);
- //copyent(e, lookat(r, c), 0, 0, 0, 0, 0, 0, 0);
copyent(e, lookat(r, c), 0, 0, 0, 0, 0, 0, 'u');
// Append 'ent' element at the beginning