Trying to figure out why gprolog blows up and dies on me, so I'm starting
with a few minor patches.  Comments on correctness/intent appreciated.

Patches:

0001-sizeof-int-sizeof-long.txt
    Changes G_IMPOSSIBLE_SIZE to (~0 >> 1) as the field it's assigned to is
    an int, not an unsigned long as per the original macro.  On amd64/Linux,
    sizeof(int) == 4, sizeof(long) == 8.
0002-pointer-integer-cleanups.txt
    The pointer in DynCInf and DynPInfo, first_erased_cl, has the two least
    significant bits being used to indicate "mark" and "all must be erased".
    Move these out to bitfields.
    It makes gcc 3.4.4 (Debian/sarge) happier and cleans up gcc 4.x porting
    issues, such as casting lvalues and using bitwise operators on pointers.
    It also converts some DBGPRINT() statements so instead of using
    %08lx, it uses %p.
    The naming of the bitfields are a bit fugly, though -- would changing the
    names to "mark" and "erase_all" be clear enough?

-- DN
Daniel
>From nobody Mon Sep 17 00:00:00 2001
From: carbonated beverage <[EMAIL PROTECTED]>
Date: Sat, 27 May 2006 13:46:47 -0700
Subject: [PATCH] sizeof(int) <= sizeof(long)

I32LP64 systems spit out warnings.
Fix the macro, which looks like it's only trying to get an integer with all bits
set except for the highest bit, to use an int.

---

 src/BipsPl/g_var_inl_c.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

ed161fd286591cb47ca2d9c1830cd424d25e49f5
diff --git a/src/BipsPl/g_var_inl_c.c b/src/BipsPl/g_var_inl_c.c
index 8119f1a..cdb534d 100644
--- a/src/BipsPl/g_var_inl_c.c
+++ b/src/BipsPl/g_var_inl_c.c
@@ -45,7 +45,7 @@ #define G_ARRAY                    0
 #define G_ARRAY_AUTO               1
 #define G_ARRAY_EXTEND             2
 
-#define G_IMPOSSIBLE_SIZE          ((unsigned long) -1 >> 1)
+#define G_IMPOSSIBLE_SIZE          (~0 >> 1)
 #define MAX_AUTO_SIZE              (1 << 20)
 
 
-- 
1.3.3

>From nobody Mon Sep 17 00:00:00 2001
From: carbonated beverage <[EMAIL PROTECTED]>
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 <[EMAIL PROTECTED]>

---

 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

_______________________________________________
Users-prolog mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/users-prolog

Reply via email to