- Despite a full afternoon of debugging, semiRunCreate/Destroy still

lose 8 blocks. I'm fairly confused.
This commit is contained in:
ccremers 2004-12-08 16:25:27 +00:00
parent ecd114c5c3
commit 3ca180d968
6 changed files with 395 additions and 234 deletions

View File

@ -8,6 +8,10 @@
*/ */
#include <limits.h> #include <limits.h>
#ifdef DEBUG
#include <malloc.h>
#endif
#include "term.h" #include "term.h"
#include "termlist.h" #include "termlist.h"
#include "role.h" #include "role.h"
@ -33,6 +37,7 @@ extern Term TERM_Function;
extern int *graph; extern int *graph;
extern int nodes; extern int nodes;
extern int graph_uordblks;
static System sys; static System sys;
static Claimlist current_claim; static Claimlist current_claim;
@ -113,9 +118,8 @@ arachneInit (const System mysys)
*/ */
INTRUDER = protocolCreate (makeGlobalConstant (" INTRUDER ")); INTRUDER = protocolCreate (makeGlobalConstant (" INTRUDER "));
GVT = makeGlobalVariable ("GlobalVariable");
add_event (SEND, GVT); add_event (SEND, NULL);
I_M = add_role ("I_M: Atomic message"); I_M = add_role ("I_M: Atomic message");
add_event (READ, NULL); add_event (READ, NULL);
@ -667,14 +671,20 @@ bind_new_run (const Binding b, const Protocol p, const Role r,
int flag; int flag;
int newgoals; int newgoals;
findLoserBegin (graph_uordblks);
run = semiRunCreate (p, r); run = semiRunCreate (p, r);
proof_suppose_run (run, 0, index + 1); proof_suppose_run (run, 0, index + 1);
newgoals = add_read_goals (run, 0, index + 1); {
indentDepth++; findLoserBegin (graph_uordblks);
flag = bind_existing_to_goal (b, run, index); newgoals = add_read_goals (run, 0, index + 1);
indentDepth--; indentDepth++;
goal_remove_last (newgoals); flag = bind_existing_to_goal (b, run, index);
indentDepth--;
goal_remove_last (newgoals);
findLoserEnd (graph_uordblks, "bind_new_run: add read goals");
}
semiRunDestroy (); semiRunDestroy ();
findLoserEnd (graph_uordblks, "bind_new_run: inner");
return flag; return flag;
} }
@ -1280,55 +1290,67 @@ select_goal ()
int int
bind_goal_new_m0 (const Binding b) bind_goal_new_m0 (const Binding b)
{ {
Termlist m0tl; Termlist m0tl,tl;
int flag; int flag;
int found; int found;
findLoserBegin(graph_uordblks);
flag = 1; flag = 1;
found = 0; found = 0;
m0tl = knowledgeSet (sys->know); m0tl = knowledgeSet (sys->know);
while (flag && m0tl != NULL) tl = m0tl;
while (flag && tl != NULL)
{ {
Term m0t; Term m0t;
Termlist subst; Termlist subst;
findLoserBegin (graph_uordblks);
m0t = m0tl->term; m0t = tl->term;
subst = termMguTerm (b->term, m0t); subst = termMguTerm (b->term, m0t);
if (subst != MGUFAIL) if (subst != MGUFAIL)
{ {
int run; int run;
findLoserBegin (graph_uordblks);
I_M->roledef->message = b->term;
run = semiRunCreate (INTRUDER, I_M); run = semiRunCreate (INTRUDER, I_M);
proof_suppose_run (run, 0, 1); proof_suppose_run (run, 0, 1);
sys->runs[run].start->message = termDuplicate (b->term);
sys->runs[run].length = 1; sys->runs[run].length = 1;
indentDepth++;
if (goal_bind (b, run, 0))
{ {
found++; findLoserBegin (graph_uordblks);
proof_suppose_binding (b); indentDepth++;
if (sys->output == PROOF) if (goal_bind (b, run, 0))
{ {
indentPrint (); found++;
eprintf ("* I.e. retrieving "); proof_suppose_binding (b);
termPrint (b->term); if (sys->output == PROOF)
eprintf (" from the initial knowledge.\n"); {
indentPrint ();
eprintf ("* I.e. retrieving ");
termPrint (b->term);
eprintf (" from the initial knowledge.\n");
}
flag = flag && iterate ();
} }
flag = flag && iterate (); else
{
proof_cannot_bind (b, run, 0);
}
goal_unbind (b);
indentDepth--;
findLoserEnd (graph_uordblks, "bind goal new m0 sugar core");
} }
else
{
proof_cannot_bind (b, run, 0);
}
goal_unbind (b);
indentDepth--;
semiRunDestroy (); semiRunDestroy ();
findLoserEnd (graph_uordblks, "bind goal new m0: inner loop 2");
termlistSubstReset (subst); termlistSubstReset (subst);
termlistDelete (subst); termlistDelete (subst);
} }
m0tl = m0tl->next; tl = tl->next;
findLoserEnd(graph_uordblks, "bind goal new m0: inner loop");
} }
if (found == 0 && sys->output == PROOF) if (found == 0 && sys->output == PROOF)
@ -1339,6 +1361,9 @@ bind_goal_new_m0 (const Binding b)
eprintf (" cannot be constructed from the initial knowledge.\n"); eprintf (" cannot be constructed from the initial knowledge.\n");
} }
termlistDelete (m0tl); termlistDelete (m0tl);
findLoserEnd(graph_uordblks, "bind goal new m0");
return flag; return flag;
} }
@ -1353,6 +1378,8 @@ bind_goal_new_encrypt (const Binding b)
int flag; int flag;
int can_be_encrypted; int can_be_encrypted;
findLoserBegin(graph_uordblks);
flag = 1; flag = 1;
term = deVar (b->term); term = deVar (b->term);
can_be_encrypted = 0; can_be_encrypted = 0;
@ -1396,21 +1423,25 @@ bind_goal_new_encrypt (const Binding b)
termPrint (t2); termPrint (t2);
eprintf ("\n"); eprintf ("\n");
} }
newgoals = add_read_goals (run, 0, index + 1); { // indenting purely added for findLoser
findLoserBegin(graph_uordblks);
newgoals = add_read_goals (run, 0, index + 1);
indentDepth++; indentDepth++;
if (goal_bind (b, run, index)) if (goal_bind (b, run, index))
{ {
proof_suppose_binding (b); proof_suppose_binding (b);
flag = flag && iterate (); flag = flag && iterate ();
}
else
{
proof_cannot_bind (b, run, index);
}
goal_unbind (b);
indentDepth--;
goal_remove_last (newgoals);
findLoserEnd(graph_uordblks, "Goal bindings within m0 new");
} }
else
{
proof_cannot_bind (b, run, index);
}
goal_unbind (b);
indentDepth--;
goal_remove_last (newgoals);
semiRunDestroy (); semiRunDestroy ();
} }
} }
@ -1425,6 +1456,9 @@ bind_goal_new_encrypt (const Binding b)
eprintf (" cannot be constructed by encryption.\n"); eprintf (" cannot be constructed by encryption.\n");
} }
} }
findLoserEnd(graph_uordblks, "bind goal new encrypt");
return flag; return flag;
} }
@ -1496,6 +1530,7 @@ bind_goal_regular_run (const Binding b)
NULL)) NULL))
{ {
int sflag; int sflag;
findLoserBegin (graph_uordblks);
// A good candidate // A good candidate
found++; found++;
@ -1522,8 +1557,13 @@ bind_goal_regular_run (const Binding b)
// Bind to existing run // Bind to existing run
sflag = bind_existing_run (b, p, r, index); sflag = bind_existing_run (b, p, r, index);
// bind to new run // bind to new run
sflag = sflag && bind_new_run (b, p, r, index); {
findLoserBegin (graph_uordblks);
sflag = sflag && bind_new_run (b, p, r, index);
findLoserEnd (graph_uordblks, "bind this role send; new run");
}
indentDepth--; indentDepth--;
findLoserEnd (graph_uordblks, "bind this role send x");
return sflag; return sflag;
} }
else else
@ -1604,6 +1644,7 @@ bind_goal (const Binding b)
int know_only; int know_only;
Term function; Term function;
flag = 1;
proof_select_goal (b); proof_select_goal (b);
indentDepth++; indentDepth++;
@ -1633,14 +1674,20 @@ bind_goal (const Binding b)
proofDepth++; proofDepth++;
if (know_only) if (know_only)
{ {
findLoserBegin (graph_uordblks);
// Special case: only from intruder // Special case: only from intruder
flag = flag && bind_goal_old_intruder_run (b); flag = flag && bind_goal_old_intruder_run (b);
flag = flag && bind_goal_new_intruder_run (b); flag = flag && bind_goal_new_intruder_run (b);
findLoserEnd (graph_uordblks, "bind_goal intruder case");
} }
else else
{ {
// Normal case // Normal case
flag = bind_goal_regular_run (b); {
findLoserBegin (graph_uordblks);
flag = bind_goal_regular_run (b);
findLoserEnd (graph_uordblks, "bind_goal case regular run");
}
flag = flag && bind_goal_old_intruder_run (b); flag = flag && bind_goal_old_intruder_run (b);
flag = flag && bind_goal_new_intruder_run (b); flag = flag && bind_goal_new_intruder_run (b);
} }
@ -1773,14 +1820,19 @@ prune_theorems ()
} }
// Check for c-minimality // Check for c-minimality
if (!bindings_c_minimal ())
{ {
if (sys->output == PROOF) findLoserBegin(graph_uordblks);
if (!bindings_c_minimal ())
{ {
indentPrint (); if (sys->output == PROOF)
eprintf ("Pruned because this is not <=c-minimal.\n"); {
findLoserBegin(graph_uordblks);
indentPrint ();
eprintf ("Pruned because this is not <=c-minimal.\n");
}
return 1;
} }
return 1; findLoserEnd(graph_uordblks, "C-minimality test");
} }
/** /**
@ -2031,11 +2083,15 @@ iterate ()
{ {
int flag; int flag;
findLoserBegin(graph_uordblks);
flag = 1; flag = 1;
if (!prune_theorems ()) if (!prune_theorems ())
{ {
findLoserBegin(graph_uordblks);
if (!prune_claim_specifics ()) if (!prune_claim_specifics ())
{ {
findLoserBegin(graph_uordblks);
if (!prune_bounds ()) if (!prune_bounds ())
{ {
Binding b; Binding b;
@ -2071,7 +2127,9 @@ iterate ()
/* /*
* bind this goal in all possible ways and iterate * bind this goal in all possible ways and iterate
*/ */
findLoserBegin (graph_uordblks);
flag = bind_goal (b); flag = bind_goal (b);
findLoserEnd (graph_uordblks, "bind_goal outer");
} }
} }
else else
@ -2079,7 +2137,9 @@ iterate ()
// Pruned because of bound! // Pruned because of bound!
current_claim->complete = 0; current_claim->complete = 0;
} }
findLoserEnd(graph_uordblks, "just outside prune_bounds condition");
} }
findLoserEnd(graph_uordblks, "just outside prune_claim_specifics condition");
} }
#ifdef DEBUG #ifdef DEBUG
@ -2088,6 +2148,10 @@ iterate ()
warning ("Flag has turned 0!"); warning ("Flag has turned 0!");
} }
#endif #endif
#ifdef DEBUG
findLoserEnd (graph_uordblks, "iterate");
#endif
return flag; return flag;
} }

View File

@ -12,10 +12,12 @@
#include "debug.h" #include "debug.h"
#include "term.h" #include "term.h"
#include "termmap.h" #include "termmap.h"
#include <malloc.h>
static System sys; static System sys;
int *graph; int *graph = NULL;
int nodes; int nodes = 0;
int graph_uordblks = 0;
extern Protocol INTRUDER; // The intruder protocol extern Protocol INTRUDER; // The intruder protocol
extern Role I_M; // special role; precedes all other events always extern Role I_M; // special role; precedes all other events always
@ -38,8 +40,7 @@ binding_create (Term term, int run_to, int ev_to)
b->ev_from = -1; b->ev_from = -1;
b->run_to = run_to; b->run_to = run_to;
b->ev_to = ev_to; b->ev_to = ev_to;
graph = NULL; goal_graph_destroy();
nodes = 0;
b->term = term; b->term = term;
b->level = 0; b->level = 0;
return b; return b;
@ -68,6 +69,9 @@ bindingInit (const System mysys)
{ {
sys = mysys; sys = mysys;
sys->bindings = NULL; sys->bindings = NULL;
graph = NULL;
nodes = 0;
graph_uordblks = 0;
} }
//! Close up //! Close up
@ -87,11 +91,27 @@ bindingDone ()
void void
goal_graph_destroy () goal_graph_destroy ()
{ {
findLoserBegin (graph_uordblks);
if (graph != NULL) if (graph != NULL)
{ {
#ifdef DEBUG
struct mallinfo mi_free;
int mem_free;
mi_free = mallinfo();
mem_free = mi_free.uordblks;
#endif
memFree (graph, (nodes * nodes) * sizeof (int)); memFree (graph, (nodes * nodes) * sizeof (int));
graph = NULL; graph = NULL;
#ifdef DEBUG
mi_free = mallinfo();
if (mem_free - mi_free.uordblks != graph_uordblks)
error ("Freeing gave a weird result.");
#endif
graph_uordblks = 0;
nodes = 0;
} }
findLoserEnd (graph_uordblks, "goal_graph_destroy");
} }
//! Compute unclosed graph //! Compute unclosed graph
@ -101,201 +121,229 @@ goal_graph_create ()
int run, ev; int run, ev;
int last_m; int last_m;
List bl; List bl;
findLoserBegin (graph_uordblks);
goal_graph_destroy (); goal_graph_destroy ();
// Setup graph // Setup graph
nodes = node_count (); nodes = node_count ();
graph = memAlloc ((nodes * nodes) * sizeof (int));
graph_fill (graph, nodes, 0);
// Setup run order
run = 0;
last_m = -1; // last I_M run
while (run < sys->maxruns)
{ {
ev = 1; struct mallinfo create_mi;
//!@todo This now reference to step, but we intend "length" as in Arachne. int create_mem_before;
while (ev < sys->runs[run].step)
if (graph_uordblks != 0)
error ("Trying to create graph stuff without 0 uordblks for it first, but it is %i.", graph_uordblks);
findLoserBegin (graph_uordblks);
create_mi = mallinfo();
create_mem_before = create_mi.uordblks;
graph = memAlloc ((nodes * nodes) * sizeof (int));
create_mi = mallinfo();
graph_uordblks = create_mi.uordblks - create_mem_before;
findLoserEnd (graph_uordblks, "core graph creation??");
}
{
findLoserBegin (graph_uordblks);
graph_fill (graph, nodes, 0);
// Setup run order
run = 0;
last_m = -1; // last I_M run
while (run < sys->maxruns)
{ {
graph[graph_nodes (nodes, run, ev - 1, run, ev)] = 1; findLoserBegin (graph_uordblks);
ev++; ev = 1;
} //!@todo This now reference to step, but we intend "length" as in Arachne.
// Enforce I_M ordering while (ev < sys->runs[run].step)
if (sys->runs[run].protocol == INTRUDER && sys->runs[run].role == I_M)
{
if (last_m != -1)
{ {
graph[graph_nodes (nodes, last_m, 0, run, 0)] = 1; graph[graph_nodes (nodes, run, ev - 1, run, ev)] = 1;
ev++;
} }
last_m = run; // Enforce I_M ordering
} if (sys->runs[run].protocol == INTRUDER && sys->runs[run].role == I_M)
// Next
run++;
}
// Setup bindings order
bl = sys->bindings;
while (bl != NULL)
{
Binding b;
b = (Binding) bl->data;
if (b->done)
{
#ifdef DEBUG
if (graph_nodes
(nodes, b->run_from, b->ev_from, b->run_to,
b->ev_to) >= (nodes * nodes))
error ("Node out of scope for %i,%i -> %i,%i.\n", b->run_from,
b->ev_from, b->run_to, b->ev_to);
#endif
graph[graph_nodes
(nodes, b->run_from, b->ev_from, b->run_to, b->ev_to)] = 1;
}
bl = bl->next;
}
// Setup local constants order
run = 0;
while (run < sys->maxruns)
{
if (sys->runs[run].protocol != INTRUDER)
{
int run2;
run2 = 0;
while (run2 < sys->maxruns)
{ {
if (sys->runs[run].protocol != INTRUDER && run != run2) if (last_m != -1)
{ {
// For these two runs, we check whether run has any variables that are mapped graph[graph_nodes (nodes, last_m, 0, run, 0)] = 1;
// to constants from run2 }
Termlist tl; last_m = run;
}
// Next
run++;
findLoserEnd (graph_uordblks, "goal_graph_create: runloop");
}
// Setup bindings order
bl = sys->bindings;
while (bl != NULL)
{
findLoserBegin (graph_uordblks);
Binding b;
tl = sys->runs[run].locals; b = (Binding) bl->data;
while (tl != NULL) if (b->done)
{ {
Term t;
t = tl->term;
if (t->type == VARIABLE && TermRunid (t) == run
&& t->subst != NULL)
{
// t is a variable of run
Termlist tl2;
tl2 = sys->runs[run2].locals;
while (tl2 != NULL)
{
Term t2;
t2 = tl2->term;
if (realTermLeaf (t2) && t2->type != VARIABLE
&& TermRunid (t2) == run2)
{
// t2 is a constant of run2
if (isTermEqual (t, t2))
{
// Indeed, run depends on the run2 constant t2. Thus we must store this order.
// The first send of t2 in run2 must be before the first (read) event in run with t2.
int ev2;
int done;
Roledef rd2;
done = 0;
ev2 = 0;
rd2 = sys->runs[run2].start;
while (!done
&& ev2 < sys->runs[run2].step)
{
if (rd2->type == SEND
&& termSubTerm (rd2->message,
t2))
{
// Allright, we send it here at ev2 first
int ev;
Roledef rd;
ev = 0;
rd = sys->runs[run].start;
while (!done
&& ev <
sys->runs[run].step)
{
if (termSubTerm
(rd->message, t2))
{
// Term occurs here in run
if (rd->type == READ)
{
// It's read here first.
// Order and be done with it.
graph[graph_nodes
(nodes, run2,
ev2, run,
ev)] = 1;
#ifdef DEBUG #ifdef DEBUG
if (DEBUGL (5)) if (graph_nodes
{ (nodes, b->run_from, b->ev_from, b->run_to,
eprintf b->ev_to) >= (nodes * nodes))
("* [local originator] term "); error ("Node out of scope for %i,%i -> %i,%i.\n", b->run_from,
termPrint (t2); b->ev_from, b->run_to, b->ev_to);
eprintf
(" is bound using %i, %i before %i,%i\n",
run2, ev2,
run, ev);
}
#endif #endif
done = 1; graph[graph_nodes
} (nodes, b->run_from, b->ev_from, b->run_to, b->ev_to)] = 1;
else }
bl = bl->next;
findLoserEnd (graph_uordblks, "goal_graph_create: bindings loop");
}
// Setup local constants order
run = 0;
while (run < sys->maxruns)
{
findLoserBegin (graph_uordblks);
if (sys->runs[run].protocol != INTRUDER)
{
int run2;
run2 = 0;
while (run2 < sys->maxruns)
{
if (sys->runs[run].protocol != INTRUDER && run != run2)
{
// For these two runs, we check whether run has any variables that are mapped
// to constants from run2
Termlist tl;
tl = sys->runs[run].locals;
while (tl != NULL)
{
Term t;
t = tl->term;
if (t->type == VARIABLE && TermRunid (t) == run
&& t->subst != NULL)
{
// t is a variable of run
Termlist tl2;
tl2 = sys->runs[run2].locals;
while (tl2 != NULL)
{
Term t2;
t2 = tl2->term;
if (realTermLeaf (t2) && t2->type != VARIABLE
&& TermRunid (t2) == run2)
{
// t2 is a constant of run2
if (isTermEqual (t, t2))
{
// Indeed, run depends on the run2 constant t2. Thus we must store this order.
// The first send of t2 in run2 must be before the first (read) event in run with t2.
int ev2;
int done;
Roledef rd2;
done = 0;
ev2 = 0;
rd2 = sys->runs[run2].start;
while (!done
&& ev2 < sys->runs[run2].step)
{
if (rd2->type == SEND
&& termSubTerm (rd2->message,
t2))
{
// Allright, we send it here at ev2 first
int ev;
Roledef rd;
ev = 0;
rd = sys->runs[run].start;
while (!done
&& ev <
sys->runs[run].step)
{
if (termSubTerm
(rd->message, t2))
{ {
// It doesn't occur first in a READ, which shouldn't be happening // Term occurs here in run
if (sys->output == if (rd->type == READ)
PROOF)
{ {
eprintf // It's read here first.
("Term "); // Order and be done with it.
termPrint (t2); graph[graph_nodes
eprintf (nodes, run2,
(" from run %i occurs in run %i, term ", ev2, run,
run2, run); ev)] = 1;
termPrint (t); #ifdef DEBUG
eprintf if (DEBUGL (5))
(" before it is read?\n"); {
eprintf
("* [local originator] term ");
termPrint (t2);
eprintf
(" is bound using %i, %i before %i,%i\n",
run2, ev2,
run, ev);
}
#endif
done = 1;
} }
// Thus, we create an artificial loop else
if (sys->runs[0].
step > 1)
{ {
// This forces a loop, and thus prunes // It doesn't occur first in a READ, which shouldn't be happening
graph if (sys->output ==
[graph_nodes PROOF)
(nodes, 0, 1, {
0, 0)] = 1; eprintf
("Term ");
termPrint (t2);
eprintf
(" from run %i occurs in run %i, term ",
run2, run);
termPrint (t);
eprintf
(" before it is read?\n");
}
// Thus, we create an artificial loop
if (sys->runs[0].
step > 1)
{
// This forces a loop, and thus prunes
graph
[graph_nodes
(nodes, 0, 1,
0, 0)] = 1;
}
} }
} }
rd = rd->next;
ev++;
} }
rd = rd->next; done = 1;
ev++;
} }
done = 1; rd2 = rd2->next;
ev2++;
} }
rd2 = rd2->next;
ev2++;
} }
} }
tl2 = tl2->next;
} }
tl2 = tl2->next;
} }
tl = tl->next;
} }
tl = tl->next;
} }
run2++;
} }
run2++;
} }
run++;
findLoserEnd (graph_uordblks, "goal_graph_create local constants loop");
} }
run++; findLoserEnd (graph_uordblks, "goal_graph_create: constructing graph innards");
} }
findLoserEnd (graph_uordblks, "goal_graph_create");
} }

View File

@ -11,4 +11,20 @@ void memDone ();
#define memFree(p,t) free(p) #define memFree(p,t) free(p)
#define memRealloc(p,t) realloc(p,t); #define memRealloc(p,t) realloc(p,t);
#define findLoserBegin(ign) int mem_before; \
int mem_diff; \
static int mem_errorcount = 0; \
struct mallinfo mi; \
mi = mallinfo(); \
mem_before = mi.uordblks - ign;
#define findLoserEnd(ign,t) mi = mallinfo(); \
mem_diff = mi.uordblks - ign - mem_before; \
if (mem_diff != 0) \
{ \
warning ("Memory leak in [%s] of %i", t, mem_diff); \
mem_errorcount++; \
if (mem_errorcount >= 10) \
error ("More than enough leaks."); \
}
#endif #endif

View File

@ -589,12 +589,18 @@ run_localize (const System sys, const int rid, Termlist fromlist,
rd = sys->runs[rid].start; rd = sys->runs[rid].start;
while (rd != NULL) while (rd != NULL)
{ {
rd->from = termLocal (rd->from, fromlist, tolist, rid); rd->from = termLocal (rd->from, fromlist, tolist);
rd->to = termLocal (rd->to, fromlist, tolist, rid); rd->to = termLocal (rd->to, fromlist, tolist);
rd->message = termLocal (rd->message, fromlist, tolist, rid); rd->message = termLocal (rd->message, fromlist, tolist);
rd = rd->next; rd = rd->next;
} }
// Substlist is NULL currently? No usage of this last stuff now
// TODO
if (substlist != NULL)
{
error ("Substlist should be NULL in run_localize");
}
sys->runs[rid].substitutions = NULL; sys->runs[rid].substitutions = NULL;
while (substlist != NULL) while (substlist != NULL)
{ {
@ -603,7 +609,7 @@ run_localize (const System sys, const int rid, Termlist fromlist,
t = substlist->term; t = substlist->term;
if (t->subst != NULL) if (t->subst != NULL)
{ {
t->subst = termLocal (t->subst, fromlist, tolist, rid); t->subst = termLocal (t->subst, fromlist, tolist);
sys->runs[rid].substitutions = sys->runs[rid].substitutions =
termlistAdd (sys->runs[rid].substitutions, t); termlistAdd (sys->runs[rid].substitutions, t);
} }
@ -668,7 +674,7 @@ roleInstanceArachne (const System sys, const Protocol protocol,
{ {
// Make new var for this run // Make new var for this run
newt = makeTermType (VARIABLE, TermSymb (newt), rid); newt = makeTermType (VARIABLE, TermSymb (newt), rid);
artefacts = termlistAdd (artefacts, newt); artefacts = termlistAddNew (artefacts, newt);
newt->stype = oldt->stype; newt->stype = oldt->stype;
// Copy substitution // Copy substitution
newt->subst = oldt->subst; newt->subst = oldt->subst;
@ -695,7 +701,8 @@ roleInstanceArachne (const System sys, const Protocol protocol,
else else
{ {
extterm = makeTermTuple (newt, extterm); extterm = makeTermTuple (newt, extterm);
artefacts = termlistAdd (artefacts, extterm); // NOTE: don't these get double deleted? By roledefdestroy?
artefacts = termlistAddNew (artefacts, extterm);
} }
} }
} }
@ -728,10 +735,10 @@ roleInstanceArachne (const System sys, const Protocol protocol,
newt = create_new_local (t, rid); newt = create_new_local (t, rid);
if (newt != NULL) if (newt != NULL)
{ {
artefacts = termlistAdd (artefacts, newt); artefacts = termlistAddNew (artefacts, newt);
if (realTermVariable (newt)) if (realTermVariable (newt))
{ {
sys->variables = termlistAdd (sys->variables, newt); sys->variables = termlistAddNew (sys->variables, newt);
} }
fromlist = termlistAdd (fromlist, t); fromlist = termlistAdd (fromlist, t);
tolist = termlistAdd (tolist, newt); tolist = termlistAdd (tolist, newt);
@ -967,13 +974,41 @@ roleInstanceDestroy (const System sys)
} }
substlist = substlist->next; substlist = substlist->next;
} }
termlistDelete(myrun.substitutions);
// sys->variables might contain locals from the run: remove them
{
Termlist tl;
tl = sys->variables;
while (tl != NULL)
{
Term t;
t = tl->term;
if (TermRunid(t) == runid)
{
// remove from list; return pointer to head
sys->variables = termlistDelTerm (tl);
tl = sys->variables;
}
else
{
// proceed
tl = tl->next;
}
}
}
// remove lists
termlistDelete (myrun.artefacts); termlistDelete (myrun.artefacts);
termlistDelete (myrun.locals); termlistDelete (myrun.locals);
termlistDelete (myrun.agents); termlistDelete (myrun.agents);
// Destroy run struct allocation in array using realloc // Destroy run struct allocation in array using realloc
sys->runs = (Run) memRealloc (sys->runs, sizeof (struct run) * (runid));
// Reduce run count // Reduce run count
sys->maxruns = runid; sys->maxruns = sys->maxruns - 1;
sys->runs = (Run) memRealloc (sys->runs, sizeof (struct run) * (sys->maxruns));
} }
} }

View File

@ -621,7 +621,7 @@ inverseKey (Termlist inverses, Term key)
*\sa termlistLocal() *\sa termlistLocal()
*/ */
Term Term
termLocal (Term t, Termlist fromlist, Termlist tolist, const int runid) termLocal (Term t, Termlist fromlist, Termlist tolist)
{ {
if (t == NULL) if (t == NULL)
return NULL; return NULL;
@ -645,13 +645,13 @@ termLocal (Term t, Termlist fromlist, Termlist tolist, const int runid)
Term newt = termNodeDuplicate (t); Term newt = termNodeDuplicate (t);
if (realTermTuple (t)) if (realTermTuple (t))
{ {
TermOp1 (newt) = termLocal (TermOp1 (t), fromlist, tolist, runid); TermOp1 (newt) = termLocal (TermOp1 (t), fromlist, tolist);
TermOp2 (newt) = termLocal (TermOp2 (t), fromlist, tolist, runid); TermOp2 (newt) = termLocal (TermOp2 (t), fromlist, tolist);
} }
else else
{ {
TermOp (newt) = termLocal (TermOp (t), fromlist, tolist, runid); TermOp (newt) = termLocal (TermOp (t), fromlist, tolist);
TermKey (newt) = termLocal (TermKey (t), fromlist, tolist, runid); TermKey (newt) = termLocal (TermKey (t), fromlist, tolist);
} }
return newt; return newt;
} }
@ -663,15 +663,14 @@ termLocal (Term t, Termlist fromlist, Termlist tolist, const int runid)
*\sa termLocal() *\sa termLocal()
*/ */
Termlist Termlist
termlistLocal (Termlist tl, const Termlist fromlist, const Termlist tolist, termlistLocal (Termlist tl, const Termlist fromlist, const Termlist tolist)
int runid)
{ {
Termlist newtl = NULL; Termlist newtl = NULL;
while (tl != NULL) while (tl != NULL)
{ {
newtl = newtl =
termlistAdd (newtl, termLocal (tl->term, fromlist, tolist, runid)); termlistAdd (newtl, termLocal (tl->term, fromlist, tolist));
tl = tl->next; tl = tl->next;
} }
return newtl; return newtl;

View File

@ -46,10 +46,9 @@ Termlist termlistAddBasics (Termlist tl, Termlist scan);
Termlist termlistMinusTerm (Termlist tl, Term t); Termlist termlistMinusTerm (Termlist tl, Term t);
int termlistLength (Termlist tl); int termlistLength (Termlist tl);
Term inverseKey (Termlist inverses, Term key); Term inverseKey (Termlist inverses, Term key);
Term termLocal (const Term t, Termlist fromlist, Termlist tolist, Term termLocal (const Term t, Termlist fromlist, Termlist tolist);
const int runid);
Termlist termlistLocal (Termlist tl, const Termlist fromlist, Termlist termlistLocal (Termlist tl, const Termlist fromlist,
const Termlist tolist, const int runid); const Termlist tolist);
int termlistContained (const Termlist tlbig, Termlist tlsmall); int termlistContained (const Termlist tlbig, Termlist tlsmall);
int validSubst (const int matchmode, const Term term); int validSubst (const int matchmode, const Term term);
Term termFunction (Termlist fromlist, Termlist tolist, Term tx); Term termFunction (Termlist fromlist, Termlist tolist, Term tx);