diff --git a/src/hb-blob-private.hh b/src/hb-blob-private.hh index 93fbc2d51..49ad68ece 100644 --- a/src/hb-blob-private.hh +++ b/src/hb-blob-private.hh @@ -76,6 +76,7 @@ struct hb_blob_t void *user_data; hb_destroy_func_t destroy; }; +DECLARE_NULL_INSTANCE (hb_blob_t); #endif /* HB_BLOB_PRIVATE_HH */ diff --git a/src/hb-blob.cc b/src/hb-blob.cc index 5bab1abbe..25c3e05aa 100644 --- a/src/hb-blob.cc +++ b/src/hb-blob.cc @@ -45,6 +45,20 @@ #include +DEFINE_NULL_INSTANCE (hb_blob_t) = +{ + HB_OBJECT_HEADER_STATIC, + + true, /* immutable */ + + nullptr, /* data */ + 0, /* length */ + HB_MEMORY_MODE_READONLY, /* mode */ + + nullptr, /* user_data */ + nullptr /* destroy */ +}; + /** * hb_blob_create: (skip) * @data: Pointer to blob data. @@ -182,20 +196,7 @@ hb_blob_copy_writable_or_fail (hb_blob_t *blob) hb_blob_t * hb_blob_get_empty (void) { - static const hb_blob_t _hb_blob_nil = { - HB_OBJECT_HEADER_STATIC, - - true, /* immutable */ - - nullptr, /* data */ - 0, /* length */ - HB_MEMORY_MODE_READONLY, /* mode */ - - nullptr, /* user_data */ - nullptr /* destroy */ - }; - - return const_cast (&_hb_blob_nil); + return const_cast (&Null(hb_blob_t)); } /** diff --git a/src/hb-buffer-private.hh b/src/hb-buffer-private.hh index f45814070..a6c4b6963 100644 --- a/src/hb-buffer-private.hh +++ b/src/hb-buffer-private.hh @@ -83,7 +83,8 @@ HB_MARK_AS_FLAG_T (hb_buffer_scratch_flags_t); * hb_buffer_t */ -struct hb_buffer_t { +struct hb_buffer_t +{ hb_object_header_t header; ASSERT_POD (); @@ -352,6 +353,7 @@ struct hb_buffer_t { info[i].mask &= ~HB_GLYPH_FLAG_UNSAFE_TO_BREAK; } }; +DECLARE_NULL_INSTANCE (hb_buffer_t); /* Loop over clusters. Duplicated in foreach_syllable(). */ diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index d04e1e80f..e79b45ae4 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -701,6 +701,28 @@ hb_buffer_t::guess_segment_properties (void) /* Public API */ +DEFINE_NULL_INSTANCE (hb_buffer_t) = +{ + HB_OBJECT_HEADER_STATIC, + + const_cast (&_hb_Null_hb_unicode_funcs_t), + HB_BUFFER_FLAG_DEFAULT, + HB_BUFFER_CLUSTER_LEVEL_DEFAULT, + HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT, + HB_BUFFER_SCRATCH_FLAG_DEFAULT, + HB_BUFFER_MAX_LEN_DEFAULT, + HB_BUFFER_MAX_OPS_DEFAULT, + + HB_BUFFER_CONTENT_TYPE_INVALID, + HB_SEGMENT_PROPERTIES_DEFAULT, + false, /* successful */ + true, /* have_output */ + true /* have_positions */ + + /* Zero is good enough for everything else. */ +}; + + /** * hb_buffer_create: (Xconstructor) * @@ -743,27 +765,7 @@ hb_buffer_create (void) hb_buffer_t * hb_buffer_get_empty (void) { - static const hb_buffer_t _hb_buffer_nil = { - HB_OBJECT_HEADER_STATIC, - - const_cast (&_hb_unicode_funcs_nil), - HB_BUFFER_FLAG_DEFAULT, - HB_BUFFER_CLUSTER_LEVEL_DEFAULT, - HB_BUFFER_REPLACEMENT_CODEPOINT_DEFAULT, - HB_BUFFER_SCRATCH_FLAG_DEFAULT, - HB_BUFFER_MAX_LEN_DEFAULT, - HB_BUFFER_MAX_OPS_DEFAULT, - - HB_BUFFER_CONTENT_TYPE_INVALID, - HB_SEGMENT_PROPERTIES_DEFAULT, - false, /* successful */ - true, /* have_output */ - true /* have_positions */ - - /* Zero is good enough for everything else. */ - }; - - return const_cast (&_hb_buffer_nil); + return const_cast (&Null(hb_buffer_t)); } /** diff --git a/src/hb-face-private.hh b/src/hb-face-private.hh index 73a684616..a4b2cd36d 100644 --- a/src/hb-face-private.hh +++ b/src/hb-face-private.hh @@ -39,7 +39,8 @@ * hb_face_t */ -struct hb_face_t { +struct hb_face_t +{ hb_object_header_t header; ASSERT_POD (); @@ -94,8 +95,7 @@ struct hb_face_t { HB_INTERNAL void load_upem (void) const; HB_INTERNAL void load_num_glyphs (void) const; }; - -extern HB_INTERNAL const hb_face_t _hb_face_nil; +DECLARE_NULL_INSTANCE (hb_face_t); #define HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_PROTOTYPE(shaper, face); diff --git a/src/hb-face.cc b/src/hb-face.cc index 9d17c4a5f..e1492756c 100644 --- a/src/hb-face.cc +++ b/src/hb-face.cc @@ -63,7 +63,8 @@ hb_face_count (hb_blob_t *blob) * hb_face_t */ -const hb_face_t _hb_face_nil = { +DEFINE_NULL_INSTANCE (hb_face_t) = +{ HB_OBJECT_HEADER_STATIC, true, /* immutable */ @@ -215,7 +216,7 @@ hb_face_create (hb_blob_t *blob, hb_face_t * hb_face_get_empty (void) { - return const_cast (&_hb_face_nil); + return const_cast (&Null(hb_face_t)); } diff --git a/src/hb-font-private.hh b/src/hb-font-private.hh index 9f657db60..4950e0bbe 100644 --- a/src/hb-font-private.hh +++ b/src/hb-font-private.hh @@ -35,7 +35,6 @@ #include "hb-shaper-private.hh" - /* * hb_font_funcs_t */ @@ -57,7 +56,8 @@ HB_FONT_FUNC_IMPLEMENT (glyph_from_name) \ /* ^--- Add new callbacks here */ -struct hb_font_funcs_t { +struct hb_font_funcs_t +{ hb_object_header_t header; ASSERT_POD (); @@ -89,14 +89,15 @@ struct hb_font_funcs_t { ]) (void); } get; }; - +DECLARE_NULL_INSTANCE (hb_font_funcs_t); /* * hb_font_t */ -struct hb_font_t { +struct hb_font_t +{ hb_object_header_t header; ASSERT_POD (); @@ -553,6 +554,7 @@ struct hb_font_t { return (float) v * scale / face->get_upem (); } }; +DECLARE_NULL_INSTANCE (hb_font_t); #define HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_PROTOTYPE(shaper, font); diff --git a/src/hb-font.cc b/src/hb-font.cc index 4d62b9e9c..7d8de6d0c 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -341,7 +341,8 @@ hb_font_get_glyph_from_name_parent (hb_font_t *font, return font->parent->get_glyph_from_name (name, len, glyph); } -static const hb_font_funcs_t _hb_font_funcs_nil = { +DEFINE_NULL_INSTANCE (hb_font_funcs_t) = +{ HB_OBJECT_HEADER_STATIC, true, /* immutable */ @@ -364,6 +365,7 @@ static const hb_font_funcs_t _hb_font_funcs_nil = { } } }; + static const hb_font_funcs_t _hb_font_funcs_parent = { HB_OBJECT_HEADER_STATIC, @@ -1100,6 +1102,37 @@ hb_font_glyph_from_string (hb_font_t *font, * hb_font_t */ +DEFINE_NULL_INSTANCE (hb_font_t) = +{ + HB_OBJECT_HEADER_STATIC, + + true, /* immutable */ + + nullptr, /* parent */ + const_cast (&_hb_Null_hb_face_t), + + 1000, /* x_scale */ + 1000, /* y_scale */ + + 0, /* x_ppem */ + 0, /* y_ppem */ + 0, /* ptem */ + + 0, /* num_coords */ + nullptr, /* coords */ + + const_cast (&_hb_Null_hb_font_funcs_t), /* klass */ + nullptr, /* user_data */ + nullptr, /* destroy */ + + { +#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID, +#include "hb-shaper-list.hh" +#undef HB_SHAPER_IMPLEMENT + } +}; + + /** * hb_font_create: (Xconstructor) * @face: a face. @@ -1187,36 +1220,7 @@ hb_font_create_sub_font (hb_font_t *parent) hb_font_t * hb_font_get_empty (void) { - static const hb_font_t _hb_font_nil = { - HB_OBJECT_HEADER_STATIC, - - true, /* immutable */ - - nullptr, /* parent */ - const_cast (&_hb_face_nil), - - 1000, /* x_scale */ - 1000, /* y_scale */ - - 0, /* x_ppem */ - 0, /* y_ppem */ - 0, /* ptem */ - - 0, /* num_coords */ - nullptr, /* coords */ - - const_cast (&_hb_font_funcs_nil), /* klass */ - nullptr, /* user_data */ - nullptr, /* destroy */ - - { -#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID, -#include "hb-shaper-list.hh" -#undef HB_SHAPER_IMPLEMENT - } - }; - - return const_cast (&_hb_font_nil); + return const_cast (&Null(hb_font_t)); } /** diff --git a/src/hb-null.hh b/src/hb-null.hh index 5ab3289eb..91efee644 100644 --- a/src/hb-null.hh +++ b/src/hb-null.hh @@ -59,10 +59,19 @@ template <> \ } \ namespace Namespace { \ static_assert (true, "Just so we take semicolon after.") - #define DEFINE_NULL_NAMESPACE_BYTES(Namespace, Type) \ const unsigned char _hb_Null_##Namespace##_##Type[Namespace::Type::min_size] +/* Specializaitons for arbitrary-content Null objects expressed as struct initializer. */ +#define DECLARE_NULL_INSTANCE(Type) \ +extern HB_INTERNAL const Type _hb_Null_##Type; \ +template <> \ +/*static*/ inline const Type& Null (void) { \ + return _hb_Null_##Type; \ +} \ +static_assert (true, "Just so we take semicolon after.") +#define DEFINE_NULL_INSTANCE(Type) \ +const Type _hb_Null_##Type /* Global writable pool. Enlarge as necessary. */ diff --git a/src/hb-ot-shape-complex-arabic-fallback.hh b/src/hb-ot-shape-complex-arabic-fallback.hh index 40c5015c9..2803febbf 100644 --- a/src/hb-ot-shape-complex-arabic-fallback.hh +++ b/src/hb-ot-shape-complex-arabic-fallback.hh @@ -205,8 +205,6 @@ struct arabic_fallback_plan_t hb_ot_layout_lookup_accelerator_t accel_array[ARABIC_FALLBACK_MAX_LOOKUPS]; }; -static const arabic_fallback_plan_t arabic_fallback_plan_nil = {}; - #if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(HB_NO_WIN1256) #define HB_WITH_WIN1256 #endif @@ -215,7 +213,8 @@ static const arabic_fallback_plan_t arabic_fallback_plan_nil = {}; #include "hb-ot-shape-complex-arabic-win1256.hh" #endif -struct ManifestLookup { +struct ManifestLookup +{ OT::Tag tag; OT::OffsetTo lookupOffset; }; @@ -299,7 +298,7 @@ arabic_fallback_plan_create (const hb_ot_shape_plan_t *plan, { arabic_fallback_plan_t *fallback_plan = (arabic_fallback_plan_t *) calloc (1, sizeof (arabic_fallback_plan_t)); if (unlikely (!fallback_plan)) - return const_cast (&arabic_fallback_plan_nil); + return const_cast (&Null(arabic_fallback_plan_t)); fallback_plan->num_lookups = 0; fallback_plan->free_lookups = false; @@ -315,13 +314,13 @@ arabic_fallback_plan_create (const hb_ot_shape_plan_t *plan, return fallback_plan; free (fallback_plan); - return const_cast (&arabic_fallback_plan_nil); + return const_cast (&Null(arabic_fallback_plan_t)); } static void arabic_fallback_plan_destroy (arabic_fallback_plan_t *fallback_plan) { - if (!fallback_plan || fallback_plan == &arabic_fallback_plan_nil) + if (!fallback_plan || fallback_plan == &Null(arabic_fallback_plan_t)) return; for (unsigned int i = 0; i < fallback_plan->num_lookups; i++) diff --git a/src/hb-shape-plan-private.hh b/src/hb-shape-plan-private.hh index c2c4987e5..7d020ff16 100644 --- a/src/hb-shape-plan-private.hh +++ b/src/hb-shape-plan-private.hh @@ -51,6 +51,7 @@ struct hb_shape_plan_t struct hb_shaper_data_t shaper_data; }; +DECLARE_NULL_INSTANCE (hb_shape_plan_t); #define HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS \ , const hb_feature_t *user_features \ diff --git a/src/hb-shape-plan.cc b/src/hb-shape-plan.cc index 37ff1a6e6..cc1834c47 100644 --- a/src/hb-shape-plan.cc +++ b/src/hb-shape-plan.cc @@ -88,6 +88,31 @@ hb_shape_plan_plan (hb_shape_plan_t *shape_plan, * hb_shape_plan_t */ +DEFINE_NULL_INSTANCE (hb_shape_plan_t) = +{ + HB_OBJECT_HEADER_STATIC, + + true, /* default_shaper_list */ + nullptr, /* face */ + HB_SEGMENT_PROPERTIES_DEFAULT, /* props */ + + nullptr, /* shaper_func */ + nullptr, /* shaper_name */ + + nullptr, /* user_features */ + 0, /* num_user_featurs */ + + nullptr, /* coords */ + 0, /* num_coords */ + + { +#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID, +#include "hb-shaper-list.hh" +#undef HB_SHAPER_IMPLEMENT + } +}; + + /** * hb_shape_plan_create: (Xconstructor) * @face: @@ -188,30 +213,7 @@ hb_shape_plan_create2 (hb_face_t *face, hb_shape_plan_t * hb_shape_plan_get_empty (void) { - static const hb_shape_plan_t _hb_shape_plan_nil = { - HB_OBJECT_HEADER_STATIC, - - true, /* default_shaper_list */ - nullptr, /* face */ - HB_SEGMENT_PROPERTIES_DEFAULT, /* props */ - - nullptr, /* shaper_func */ - nullptr, /* shaper_name */ - - nullptr, /* user_features */ - 0, /* num_user_featurs */ - - nullptr, /* coords */ - 0, /* num_coords */ - - { -#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_INVALID, -#include "hb-shaper-list.hh" -#undef HB_SHAPER_IMPLEMENT - } - }; - - return const_cast (&_hb_shape_plan_nil); + return const_cast (&Null(hb_shape_plan_t)); } /** diff --git a/src/hb-unicode-private.hh b/src/hb-unicode-private.hh index b2c203d26..fb16ba437 100644 --- a/src/hb-unicode-private.hh +++ b/src/hb-unicode-private.hh @@ -60,7 +60,8 @@ extern HB_INTERNAL const uint8_t _hb_modified_combining_class[256]; HB_UNICODE_FUNC_IMPLEMENT (hb_script_t, script) \ /* ^--- Add new simple callbacks here */ -struct hb_unicode_funcs_t { +struct hb_unicode_funcs_t +{ hb_object_header_t header; ASSERT_POD (); @@ -263,9 +264,7 @@ HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE #undef HB_UNICODE_FUNC_IMPLEMENT } destroy; }; - - -extern HB_INTERNAL const hb_unicode_funcs_t _hb_unicode_funcs_nil; +DECLARE_NULL_INSTANCE (hb_unicode_funcs_t); /* Modified combining marks */ diff --git a/src/hb-unicode.cc b/src/hb-unicode.cc index 2d16c2e3a..8cb417233 100644 --- a/src/hb-unicode.cc +++ b/src/hb-unicode.cc @@ -185,7 +185,8 @@ hb_unicode_funcs_create (hb_unicode_funcs_t *parent) } -const hb_unicode_funcs_t _hb_unicode_funcs_nil = { +DEFINE_NULL_INSTANCE (hb_unicode_funcs_t) = +{ HB_OBJECT_HEADER_STATIC, nullptr, /* parent */ @@ -209,7 +210,7 @@ const hb_unicode_funcs_t _hb_unicode_funcs_nil = { hb_unicode_funcs_t * hb_unicode_funcs_get_empty (void) { - return const_cast (&_hb_unicode_funcs_nil); + return const_cast (&Null(hb_unicode_funcs_t)); } /**