From: Behdad Esfahbod Date: Sat, 1 Aug 2009 23:30:31 +0000 (-0400) Subject: [HB] Simplify refcounting functions X-Git-Tag: 2.0_alpha~7^2~1120 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=35a7383c6138fd705560f0d4bb30659cbd1ab64c;p=apps%2Fhome%2Fvideo-player.git [HB] Simplify refcounting functions --- diff --git a/src/hb-blob.c b/src/hb-blob.c index 50bb973..87cd7a4 100644 --- a/src/hb-blob.c +++ b/src/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/src/hb-common.h b/src/hb-common.h index c719d80..2e127a3 100644 --- a/src/hb-common.h +++ b/src/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/src/hb-private.h b/src/hb-private.h index 196bc3c..2f482db 100644 --- a/src/hb-private.h +++ b/src/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/src/hb-refcount-private.h b/src/hb-refcount-private.h index e8acb25..29c2943 100644 --- a/src/hb-refcount-private.h +++ b/src/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 + * 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 */