From 799b3c375ad0e1293fd37a0e3a0d422a3166dcd8 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 5 Nov 2009 19:37:58 -0500 Subject: [PATCH] Add debugging to object lifecycle --- src/hb-object-private.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/hb-object-private.h b/src/hb-object-private.h index 2186e58e5..27f1471bc 100644 --- a/src/hb-object-private.h +++ b/src/hb-object-private.h @@ -31,6 +31,21 @@ #define HB_REFCOUNT_PRIVATE_H +#ifndef HB_DEBUG_OBJECT +#define HB_DEBUG_OBJECT HB_DEBUG +#endif + +#if HB_DEBUG_OBJECT +#include +#define HB_OBJECT_DEBUG_OUT(obj) fprintf (stderr, "%p refcount=%d %s\n", \ + obj, \ + HB_REFERENCE_COUNT_GET_VALUE (obj->ref_count), \ + __FUNCTION__) +#else +#define HB_OBJECT_DEBUG_OUT(obj) 0 +#endif + + /* Encapsulate operations on the object's reference count */ typedef struct { hb_atomic_int_t ref_count; @@ -70,6 +85,7 @@ typedef struct { HB_LIKELY (( \ (obj) = (Type *) calloc (1, sizeof (Type)), \ HB_OBJECT_DO_INIT_EXPR (obj), \ + HB_OBJECT_DEBUG_OUT (obj), \ (obj) \ )) @@ -78,6 +94,7 @@ typedef struct { int old_count; \ if (HB_UNLIKELY (!(obj) || HB_OBJECT_IS_INERT (obj))) \ return obj; \ + HB_OBJECT_DEBUG_OUT (obj); \ old_count = hb_reference_count_inc (obj->ref_count); \ assert (old_count > 0); \ return obj; \ @@ -95,6 +112,7 @@ typedef struct { int old_count; \ if (HB_UNLIKELY (!(obj) || HB_OBJECT_IS_INERT (obj))) \ return; \ + HB_OBJECT_DEBUG_OUT (obj); \ old_count = hb_reference_count_dec (obj->ref_count); \ assert (old_count > 0); \ if (old_count != 1) \