From 3b6bff1433bc8f520ced1e84e82d794803c0b8b0 Mon Sep 17 00:00:00 2001
From: Martin Stjernholm <mast@lysator.liu.se>
Date: Sun, 1 Dec 2002 18:36:03 +0100
Subject: [PATCH] Added a macro to get some debug trace.

Rev: src/cyclic.c:1.9
Rev: src/cyclic.h:1.8
---
 src/cyclic.c | 15 ++++++++++++---
 src/cyclic.h | 25 ++++++++++++++++++++-----
 2 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/src/cyclic.c b/src/cyclic.c
index e9eda5809b..7721fc4453 100644
--- a/src/cyclic.c
+++ b/src/cyclic.c
@@ -2,13 +2,13 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: cyclic.c,v 1.8 2002/10/11 01:39:30 nilsson Exp $
+|| $Id: cyclic.c,v 1.9 2002/12/01 17:36:03 mast Exp $
 */
 
 #include "global.h"
 #include "cyclic.h"
 
-RCSID("$Id: cyclic.c,v 1.8 2002/10/11 01:39:30 nilsson Exp $");
+RCSID("$Id: cyclic.c,v 1.9 2002/12/01 17:36:03 mast Exp $");
 
 #define CYCLIC_HASH_SIZE 4711
 
@@ -33,6 +33,9 @@ static void low_unlink_cyclic(CYCLIC *c)
     if(c == *p)
     {
       *p=c->next;
+#ifdef CYCLIC_DEBUG
+      fprintf (stderr, "%s: END_CYCLIC a=%p b=%p: no cycle\n", c->id, c->a, c->b);
+#endif
       return;
     }
   }
@@ -46,7 +49,7 @@ void unlink_cyclic(CYCLIC *c)
 }
 
 void *begin_cyclic(CYCLIC *c,
-		   void *id,
+		   char *id,
 		   void *th,
 		   void *a,
 		   void *b)
@@ -69,6 +72,9 @@ void *begin_cyclic(CYCLIC *c,
   {
     if(a == p->a && b==p->b && id==p->id)
     {
+#ifdef CYCLIC_DEBUG
+      fprintf (stderr, "%s: BEGIN_CYCLIC a=%p b=%p: found cycle\n", id, a, b);
+#endif
       ret=p->ret;
       break;
     }
@@ -82,5 +88,8 @@ void *begin_cyclic(CYCLIC *c,
   c->next=cyclic_hash[h];
   cyclic_hash[h]=c;
   SET_ONERROR(c->onerr, low_unlink_cyclic, c);
+#ifdef CYCLIC_DEBUG
+  if (!ret) fprintf (stderr, "%s: BEGIN_CYCLIC a=%p b=%p: no cycle\n", id, a, b);
+#endif
   return ret;
 }
diff --git a/src/cyclic.h b/src/cyclic.h
index 17585d88dc..166534db68 100644
--- a/src/cyclic.h
+++ b/src/cyclic.h
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: cyclic.h,v 1.7 2002/10/11 01:39:30 nilsson Exp $
+|| $Id: cyclic.h,v 1.8 2002/12/01 17:36:03 mast Exp $
 */
 
 #ifndef CYCLIC_H
@@ -11,24 +11,39 @@
 #include "pike_error.h"
 #include "threads.h"
 
+/* #define CYCLIC_DEBUG */
+
 typedef struct CYCLIC
 {
   ONERROR onerr;
   void *th;
-  void *id,*a,*b;
+  char *id;
+  void *a,*b;
   void *ret;
   struct CYCLIC *next;
 } CYCLIC;
 
 
-#define DECLARE_CYCLIC() \
-  static char cyclic_identifier__; \
+#ifdef CYCLIC_DEBUG
+
+#define DECLARE_CYCLIC()						\
+  static char cyclic_identifier__[] = __FILE__ ":" DEFINETOSTR(__LINE__); \
   CYCLIC cyclic_struct__
+#define BEGIN_CYCLIC(A,B) \
+   begin_cyclic(&cyclic_struct__, cyclic_identifier__, \
+                (void *)(ptrdiff_t)th_self(), (void *)(A), (void *)(B))
 
+#else  /* CYCLIC_DEBUG */
+
+#define DECLARE_CYCLIC()	   \
+  static char cyclic_identifier__; \
+  CYCLIC cyclic_struct__
 #define BEGIN_CYCLIC(A,B) \
    begin_cyclic(&cyclic_struct__, &cyclic_identifier__, \
                 (void *)(ptrdiff_t)th_self(), (void *)(A), (void *)(B))
 
+#endif	/* !CYCLIC_DEBUG */
+
 #define SET_CYCLIC_RET(RET) \
    cyclic_struct__.ret=(void *)(RET)
 
@@ -37,7 +52,7 @@ typedef struct CYCLIC
 /* Prototypes begin here */
 void unlink_cyclic(CYCLIC *c);
 void *begin_cyclic(CYCLIC *c,
-		   void *id,
+		   char *id,
 		   void *thread,
 		   void *a,
 		   void *b);
-- 
GitLab