>From nobody Mon Sep 17 00:00:00 2001 From: carbonated beverage Date: Sat, 27 May 2006 14:28:19 -0700 Subject: [PATCH] pointer/integer cleanups: 1. pointers are %p, not %08lx. 2. add two new bitfields to DynPInf instead of using the 2 least significant bits in the pointer itself to store data. Signed-off-by: carbonated beverage --- src/BipsPl/dynam_supp.c | 31 ++++++++++++++++++------------- src/BipsPl/dynam_supp.h | 5 +++++ src/EnginePl/gprolog.h | 5 +++++ 3 files changed, 28 insertions(+), 13 deletions(-) 7a6db39576039c64ebbdca60136a2d13c74deac7 diff --git a/src/BipsPl/dynam_supp.c b/src/BipsPl/dynam_supp.c index acc15d5..0edd78c 100644 --- a/src/BipsPl/dynam_supp.c +++ b/src/BipsPl/dynam_supp.c @@ -369,6 +369,8 @@ Alloc_Init_Dyn_Info(PredInf *pred, int a dyn->count_a = -1; dyn->count_z = 0; dyn->first_erased_cl = NULL; + dyn->first_erased_cl_mark = 0; + dyn->first_erased_cl_all_must_be_erased = 0; dyn->next_dyn_with_erase = NULL; pred->dyn = (long *) dyn; @@ -556,7 +558,7 @@ Erase_All(DynPInf *dyn) return; first = (dyn->first_erased_cl == NULL); - dyn->first_erased_cl = ALL_MUST_BE_ERASED; + dyn->first_erased_cl_all_must_be_erased = 1; if (first) { @@ -600,8 +602,10 @@ Clean_Erased_Clauses(void) dyn = scan->dyn; - if (dyn->first_erased_cl) /* we must keep it - free impossible */ - (unsigned long) (dyn->first_erased_cl) |= 1; /* mark it */ + /* we must keep it - free impossible */ + if (dyn->first_erased_cl) { + dyn->first_erased_cl_mark = 1; + } } @@ -609,10 +613,9 @@ Clean_Erased_Clauses(void) for (dyn = first_dyn_with_erase; dyn; dyn = dyn1) { dyn1 = dyn->next_dyn_with_erase; - if ((long) (dyn->first_erased_cl) & 1) /* marked ? */ + if (dyn->first_erased_cl_mark) /* marked? */ { /* cannot free it */ - dyn->first_erased_cl = (DynCInf *) - ((unsigned long) (dyn->first_erased_cl) & (~1)); + dyn->first_erased_cl_mark = 0; prev = &(dyn->next_dyn_with_erase); continue; } @@ -620,7 +623,7 @@ Clean_Erased_Clauses(void) /* not marked - can be cleaned */ *prev = dyn->next_dyn_with_erase; - if (dyn->first_erased_cl == ALL_MUST_BE_ERASED) /* clean all ? */ + if (dyn->first_erased_cl_all_must_be_erased) /* clean all ? */ { for (clause = dyn->seq_chain.first; clause; clause = clause1) { @@ -650,6 +653,8 @@ Clean_Erased_Clauses(void) Free_Clause(clause); } dyn->first_erased_cl = NULL; + dyn->first_erased_cl_mark = 0; + dyn->first_erased_cl_all_must_be_erased = 0; dyn->next_dyn_with_erase = NULL; if (dyn->seq_chain.first == NULL) /* no more clauses */ @@ -1055,12 +1060,12 @@ #if defined(DEBUG) || defined(DEBUG1) static void Check_Dynamic_Clauses(DynPInf *dyn) { - DBGPRINTF("\nFirst dyn with erase:0x%08lx\n", - (long) first_dyn_with_erase); - DBGPRINTF("Dyn:0x%08lx arity:%d count_a:%d count_z:%d " - "1st erased:0x%08lx next dyn with erase:0x%08lx\n", - (long) dyn, dyn->arity, dyn->count_a, dyn->count_z, - (long) dyn->first_erased_cl, (long) dyn->next_dyn_with_erase); + DBGPRINTF("\nFirst dyn with erase:0x%p\n", + first_dyn_with_erase); + DBGPRINTF("Dyn:0x%p arity:%d count_a:%d count_z:%d " + "1st erased:0x%p next dyn with erase:0x%p\n", + dyn, dyn->arity, dyn->count_a, dyn->count_z, + dyn->first_erased_cl, dyn->next_dyn_with_erase); Check_Chain(&dyn->seq_chain, NO_INDEX); Check_Chain(&dyn->var_ind_chain, VAR_INDEX); diff --git a/src/BipsPl/dynam_supp.h b/src/BipsPl/dynam_supp.h index 225cdac..8242651 100644 --- a/src/BipsPl/dynam_supp.h +++ b/src/BipsPl/dynam_supp.h @@ -104,6 +104,11 @@ typedef struct dynpinf /* Dynamic predi int count_z; /* next clause nb for assertz */ DynCInfP first_erased_cl; /* 1st erased clause NULL if none */ DynPInfP next_dyn_with_erase; /* next dyn with erased clauses */ + int first_erased_cl_mark:1; /* To get rid of pointer fiddling, + * used the LSb before this in the + * first_erased_cl pointer + */ + int first_erased_cl_all_must_be_erased:1; /* ditto, but bit 1 */ } DynPInf; diff --git a/src/EnginePl/gprolog.h b/src/EnginePl/gprolog.h index f92af57..4e2db26 100644 --- a/src/EnginePl/gprolog.h +++ b/src/EnginePl/gprolog.h @@ -2059,6 +2059,11 @@ typedef struct dynpinf /* Dynamic predi int count_z; /* next clause nb for assertz */ DynCInfP first_erased_cl; /* 1st erased clause NULL if none */ DynPInfP next_dyn_with_erase; /* next dyn with erased clauses */ + int first_erased_cl_mark:1; /* To get rid of pointer fiddling, + * used the LSb before this in the + * first_erased_cl pointer + */ + int first_erased_cl_all_must_be_erased:1; /* ditto, but bit 1 */ } DynPInf; DynCInf *Add_Dynamic_Clause(WamWord head_word, WamWord body_word, -- 1.3.3