summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2009-08-01 19:30:31 -0400
committerBehdad Esfahbod <behdad@behdad.org>2009-08-01 19:30:50 -0400
commit3ebf3e536b645f86f7dea8d68be08d7b99498f35 (patch)
tree34f014f408d56c015f37f48a223a7d1c17fad0ac
parent7257d6625638eaeffa13acd614c0eb53875e8172 (diff)
downloadpango-3ebf3e536b645f86f7dea8d68be08d7b99498f35.tar.gz
[HB] Simplify refcounting functions
-rw-r--r--pango/opentype/hb-blob.c32
-rw-r--r--pango/opentype/hb-common.h2
-rw-r--r--pango/opentype/hb-private.h2
-rw-r--r--pango/opentype/hb-refcount-private.h31
4 files changed, 44 insertions, 23 deletions
diff --git a/pango/opentype/hb-blob.c b/pango/opentype/hb-blob.c
index 50bb9730..87cd7a42 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 c719d803..2e127a31 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 196bc3c1..2f482db9 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 e8acb256..29c29431 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 */