From c784c67a28f5b92d396eaa9529d57ef91a5cb9ac Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 2 May 2011 15:59:57 -0400 Subject: [PATCH] [unicode] Make _get_parent() return _nil object instead of NULL --- src/hb-unicode.cc | 29 ++++++++++++----------------- test/test-unicode.c | 2 +- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/hb-unicode.cc b/src/hb-unicode.cc index 0486be3..e8eb553 100644 --- a/src/hb-unicode.cc +++ b/src/hb-unicode.cc @@ -110,22 +110,18 @@ hb_unicode_funcs_create (hb_unicode_funcs_t *parent) if (!(ufuncs = hb_object_create ())) return &_hb_unicode_funcs_nil; - if (parent != NULL) - { - hb_unicode_funcs_make_immutable (parent); - ufuncs->parent = hb_unicode_funcs_reference (parent); + if (!parent) + parent = &_hb_unicode_funcs_nil; - ufuncs->get = parent->get; + hb_unicode_funcs_make_immutable (parent); + ufuncs->parent = hb_unicode_funcs_reference (parent); - /* We can safely copy user_data from parent since we hold a reference - * onto it and it's immutable. We should not copy the destroy notifiers - * though. */ - ufuncs->user_data = parent->user_data; - } - else - { - ufuncs->get = _hb_unicode_funcs_nil.get; - } + ufuncs->get = parent->get; + + /* We can safely copy user_data from parent since we hold a reference + * onto it and it's immutable. We should not copy the destroy notifiers + * though. */ + ufuncs->user_data = parent->user_data; return ufuncs; } @@ -149,8 +145,7 @@ hb_unicode_funcs_destroy (hb_unicode_funcs_t *ufuncs) DESTROY (script); #undef DESTROY - if (ufuncs->parent != NULL) - hb_unicode_funcs_destroy (ufuncs->parent); + hb_unicode_funcs_destroy (ufuncs->parent); free (ufuncs); } @@ -190,7 +185,7 @@ hb_unicode_funcs_is_immutable (hb_unicode_funcs_t *ufuncs) hb_unicode_funcs_t * hb_unicode_funcs_get_parent (hb_unicode_funcs_t *ufuncs) { - return ufuncs->parent; + return ufuncs->parent ? ufuncs->parent : &_hb_unicode_funcs_nil; } diff --git a/test/test-unicode.c b/test/test-unicode.c index 96d6806..cc95a9f 100644 --- a/test/test-unicode.c +++ b/test/test-unicode.c @@ -67,7 +67,7 @@ simple_get_script (hb_unicode_funcs_t *ufuncs, { data_t *data = (data_t *) user_data; - g_assert (hb_unicode_funcs_get_parent (ufuncs) == NULL); + g_assert (hb_unicode_funcs_get_parent (ufuncs) != NULL); g_assert (data->value == MAGIC0); g_assert (data->freed == FALSE); -- 2.7.4