[pango/harfbuzz-ng: 12/57] [HB] Simplify refcounting functions



commit 3ebf3e536b645f86f7dea8d68be08d7b99498f35
Author: Behdad Esfahbod <behdad behdad org>
Date:   Sat Aug 1 19:30:31 2009 -0400

    [HB] Simplify refcounting functions

 pango/opentype/hb-blob.c             |   32 ++++++++++----------------------
 pango/opentype/hb-common.h           |    2 ++
 pango/opentype/hb-private.h          |    2 ++
 pango/opentype/hb-refcount-private.h |   31 ++++++++++++++++++++++++++++++-
 4 files changed, 44 insertions(+), 23 deletions(-)
---
diff --git a/pango/opentype/hb-blob.c b/pango/opentype/hb-blob.c
index 50bb973..87cd7a4 100644
--- a/pango/opentype/hb-blob.c
+++ b/pango/opentype/hb-blob.c
@@ -40,14 +40,14 @@ struct _hb_blob_t {
   void *user_data;
 };
 static hb_blob_t _hb_blob_nil = {
-  HB_REFERENCE_COUNT_INVALID,
+  HB_REFERENCE_COUNT_INVALID, /* ref_count */
 
-  NULL,
-  0,
-  HB_MEMORY_MODE_READONLY,
+  NULL, /* data */
+  0, /* len */
+  HB_MEMORY_MODE_READONLY, /* mode */
 
-  NULL,
-  NULL
+  NULL, /* destroy */
+  NULL /* user_data */
 };
 
 static void
@@ -76,11 +76,12 @@ hb_blob_create (const char        *data,
     return &_hb_blob_nil;
   }
 
+  HB_REFERENCE_COUNT_DO_CREATE (blob);
+
   blob->data = data;
   blob->len = len;
   blob->mode = mode;
 
-  HB_REFERENCE_COUNT_INIT (blob->ref_count, 1);
   blob->destroy = destroy;
   blob->user_data = user_data;
 
@@ -95,26 +96,13 @@ hb_blob_create (const char        *data,
 hb_blob_t *
 hb_blob_reference (hb_blob_t *blob)
 {
-  if (blob == NULL || HB_REFERENCE_COUNT_IS_INVALID (blob->ref_count))
-    return blob;
-
-  assert (HB_REFERENCE_COUNT_HAS_REFERENCE (blob->ref_count));
-
-  _hb_reference_count_inc (blob->ref_count);
-
-  return blob;
+  HB_REFERENCE_COUNT_DO_REFERENCE (blob);
 }
 
 void
 hb_blob_destroy (hb_blob_t *blob)
 {
-  if (blob == NULL || HB_REFERENCE_COUNT_IS_INVALID (blob->ref_count))
-    return;
-
-  assert (HB_REFERENCE_COUNT_HAS_REFERENCE (blob->ref_count));
-
-  if (!_hb_reference_count_dec_and_test (blob->ref_count))
-    return;
+  HB_REFERENCE_COUNT_DO_DESTROY (blob);
 
   _hb_blob_destroy_user_data (blob);
 
diff --git a/pango/opentype/hb-common.h b/pango/opentype/hb-common.h
index c719d80..2e127a3 100644
--- a/pango/opentype/hb-common.h
+++ b/pango/opentype/hb-common.h
@@ -59,4 +59,6 @@ typedef struct _hb_unicode_callbacks_t hb_unicode_callbacks_t;
 typedef struct _hb_face_t hb_face_t;
 typedef struct _hb_font_t hb_font_t;
 
+typedef hb_blob_t * (*hb_get_table_func_t)  (hb_tag_t tag, void *user_data);
+
 #endif /* HB_COMMON_H */
diff --git a/pango/opentype/hb-private.h b/pango/opentype/hb-private.h
index 196bc3c..2f482db 100644
--- a/pango/opentype/hb-private.h
+++ b/pango/opentype/hb-private.h
@@ -73,6 +73,8 @@
 # define TRUE 1
 #endif
 
+#define HB_STMT_START do
+#define HB_STMT_END   while (0)
 
 #define _ASSERT_STATIC1(_line, _cond) typedef int _static_assert_on_line_##_line##_failed[(_cond)?1:-1]
 #define _ASSERT_STATIC0(_line, _cond) _ASSERT_STATIC1 (_line, (_cond))
diff --git a/pango/opentype/hb-refcount-private.h b/pango/opentype/hb-refcount-private.h
index e8acb25..29c2943 100644
--- a/pango/opentype/hb-refcount-private.h
+++ b/pango/opentype/hb-refcount-private.h
@@ -1,5 +1,6 @@
 /*
- * Copyright © 2007 Chris Wilson
+ * Copyright (C) 2007 Chris Wilson
+ * Copyright (C) 2009  Red Hat, Inc.
  *
  *  This is part of HarfBuzz, an OpenType Layout engine library.
  *
@@ -23,6 +24,7 @@
  *
  * Contributor(s):
  *	Chris Wilson <chris chris-wilson co uk>
+ * Red Hat Author(s): Behdad Esfahbod
  */
 
 #ifndef HB_REFCOUNT_PRIVATE_H
@@ -51,4 +53,31 @@ typedef struct {
 
 #define HB_REFERENCE_COUNT_HAS_REFERENCE(RC) (HB_REFERENCE_COUNT_GET_VALUE (RC) > 0)
 
+
+/* Helper macros */
+
+#define HB_REFERENCE_COUNT_DO_CREATE(obj) \
+  HB_STMT_START { \
+    HB_REFERENCE_COUNT_INIT (obj->ref_count, 1); \
+  } HB_STMT_END
+
+#define HB_REFERENCE_COUNT_DO_REFERENCE(obj) \
+  HB_STMT_START { \
+    if (obj == NULL || HB_REFERENCE_COUNT_IS_INVALID (obj->ref_count)) \
+      return obj; \
+    assert (HB_REFERENCE_COUNT_HAS_REFERENCE (obj->ref_count)); \
+    _hb_reference_count_inc (obj->ref_count); \
+    return obj; \
+  } HB_STMT_END
+
+#define HB_REFERENCE_COUNT_DO_DESTROY(obj) \
+  HB_STMT_START { \
+    if (obj == NULL || HB_REFERENCE_COUNT_IS_INVALID (obj->ref_count)) \
+      return; \
+    assert (HB_REFERENCE_COUNT_HAS_REFERENCE (obj->ref_count)); \
+    if (!_hb_reference_count_dec_and_test (obj->ref_count)) \
+      return; \
+  } HB_STMT_END
+
+
 #endif /* HB_REFCOUNT_PRIVATE_H */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]