提交 3506672c 编写于 作者: B Behdad Esfahbod

Port _nil objects to Null() machinery

Finally, unified!
上级 1abd427a
...@@ -76,6 +76,7 @@ struct hb_blob_t ...@@ -76,6 +76,7 @@ struct hb_blob_t
void *user_data; void *user_data;
hb_destroy_func_t destroy; hb_destroy_func_t destroy;
}; };
DECLARE_NULL_INSTANCE (hb_blob_t);
#endif /* HB_BLOB_PRIVATE_HH */ #endif /* HB_BLOB_PRIVATE_HH */
...@@ -45,6 +45,20 @@ ...@@ -45,6 +45,20 @@
#include <stdlib.h> #include <stdlib.h>
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) * hb_blob_create: (skip)
* @data: Pointer to blob data. * @data: Pointer to blob data.
...@@ -182,20 +196,7 @@ hb_blob_copy_writable_or_fail (hb_blob_t *blob) ...@@ -182,20 +196,7 @@ hb_blob_copy_writable_or_fail (hb_blob_t *blob)
hb_blob_t * hb_blob_t *
hb_blob_get_empty (void) hb_blob_get_empty (void)
{ {
static const hb_blob_t _hb_blob_nil = { return const_cast<hb_blob_t *> (&Null(hb_blob_t));
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_t *> (&_hb_blob_nil);
} }
/** /**
......
...@@ -83,7 +83,8 @@ HB_MARK_AS_FLAG_T (hb_buffer_scratch_flags_t); ...@@ -83,7 +83,8 @@ HB_MARK_AS_FLAG_T (hb_buffer_scratch_flags_t);
* hb_buffer_t * hb_buffer_t
*/ */
struct hb_buffer_t { struct hb_buffer_t
{
hb_object_header_t header; hb_object_header_t header;
ASSERT_POD (); ASSERT_POD ();
...@@ -352,6 +353,7 @@ struct hb_buffer_t { ...@@ -352,6 +353,7 @@ struct hb_buffer_t {
info[i].mask &= ~HB_GLYPH_FLAG_UNSAFE_TO_BREAK; info[i].mask &= ~HB_GLYPH_FLAG_UNSAFE_TO_BREAK;
} }
}; };
DECLARE_NULL_INSTANCE (hb_buffer_t);
/* Loop over clusters. Duplicated in foreach_syllable(). */ /* Loop over clusters. Duplicated in foreach_syllable(). */
......
...@@ -701,6 +701,28 @@ hb_buffer_t::guess_segment_properties (void) ...@@ -701,6 +701,28 @@ hb_buffer_t::guess_segment_properties (void)
/* Public API */ /* Public API */
DEFINE_NULL_INSTANCE (hb_buffer_t) =
{
HB_OBJECT_HEADER_STATIC,
const_cast<hb_unicode_funcs_t *> (&_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) * hb_buffer_create: (Xconstructor)
* *
...@@ -743,27 +765,7 @@ hb_buffer_create (void) ...@@ -743,27 +765,7 @@ hb_buffer_create (void)
hb_buffer_t * hb_buffer_t *
hb_buffer_get_empty (void) hb_buffer_get_empty (void)
{ {
static const hb_buffer_t _hb_buffer_nil = { return const_cast<hb_buffer_t *> (&Null(hb_buffer_t));
HB_OBJECT_HEADER_STATIC,
const_cast<hb_unicode_funcs_t *> (&_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_t *> (&_hb_buffer_nil);
} }
/** /**
......
...@@ -39,7 +39,8 @@ ...@@ -39,7 +39,8 @@
* hb_face_t * hb_face_t
*/ */
struct hb_face_t { struct hb_face_t
{
hb_object_header_t header; hb_object_header_t header;
ASSERT_POD (); ASSERT_POD ();
...@@ -94,8 +95,7 @@ struct hb_face_t { ...@@ -94,8 +95,7 @@ struct hb_face_t {
HB_INTERNAL void load_upem (void) const; HB_INTERNAL void load_upem (void) const;
HB_INTERNAL void load_num_glyphs (void) const; HB_INTERNAL void load_num_glyphs (void) const;
}; };
DECLARE_NULL_INSTANCE (hb_face_t);
extern HB_INTERNAL const hb_face_t _hb_face_nil;
#define HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS #define HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS
#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_PROTOTYPE(shaper, face); #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_PROTOTYPE(shaper, face);
......
...@@ -63,7 +63,8 @@ hb_face_count (hb_blob_t *blob) ...@@ -63,7 +63,8 @@ hb_face_count (hb_blob_t *blob)
* hb_face_t * hb_face_t
*/ */
const hb_face_t _hb_face_nil = { DEFINE_NULL_INSTANCE (hb_face_t) =
{
HB_OBJECT_HEADER_STATIC, HB_OBJECT_HEADER_STATIC,
true, /* immutable */ true, /* immutable */
...@@ -215,7 +216,7 @@ hb_face_create (hb_blob_t *blob, ...@@ -215,7 +216,7 @@ hb_face_create (hb_blob_t *blob,
hb_face_t * hb_face_t *
hb_face_get_empty (void) hb_face_get_empty (void)
{ {
return const_cast<hb_face_t *> (&_hb_face_nil); return const_cast<hb_face_t *> (&Null(hb_face_t));
} }
......
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
#include "hb-shaper-private.hh" #include "hb-shaper-private.hh"
/* /*
* hb_font_funcs_t * hb_font_funcs_t
*/ */
...@@ -57,7 +56,8 @@ ...@@ -57,7 +56,8 @@
HB_FONT_FUNC_IMPLEMENT (glyph_from_name) \ HB_FONT_FUNC_IMPLEMENT (glyph_from_name) \
/* ^--- Add new callbacks here */ /* ^--- Add new callbacks here */
struct hb_font_funcs_t { struct hb_font_funcs_t
{
hb_object_header_t header; hb_object_header_t header;
ASSERT_POD (); ASSERT_POD ();
...@@ -89,14 +89,15 @@ struct hb_font_funcs_t { ...@@ -89,14 +89,15 @@ struct hb_font_funcs_t {
]) (void); ]) (void);
} get; } get;
}; };
DECLARE_NULL_INSTANCE (hb_font_funcs_t);
/* /*
* hb_font_t * hb_font_t
*/ */
struct hb_font_t { struct hb_font_t
{
hb_object_header_t header; hb_object_header_t header;
ASSERT_POD (); ASSERT_POD ();
...@@ -553,6 +554,7 @@ struct hb_font_t { ...@@ -553,6 +554,7 @@ struct hb_font_t {
return (float) v * scale / face->get_upem (); return (float) v * scale / face->get_upem ();
} }
}; };
DECLARE_NULL_INSTANCE (hb_font_t);
#define HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS #define HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS
#define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_PROTOTYPE(shaper, font); #define HB_SHAPER_IMPLEMENT(shaper) HB_SHAPER_DATA_PROTOTYPE(shaper, font);
......
...@@ -341,7 +341,8 @@ hb_font_get_glyph_from_name_parent (hb_font_t *font, ...@@ -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); 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, HB_OBJECT_HEADER_STATIC,
true, /* immutable */ true, /* immutable */
...@@ -364,6 +365,7 @@ static const hb_font_funcs_t _hb_font_funcs_nil = { ...@@ -364,6 +365,7 @@ static const hb_font_funcs_t _hb_font_funcs_nil = {
} }
} }
}; };
static const hb_font_funcs_t _hb_font_funcs_parent = { static const hb_font_funcs_t _hb_font_funcs_parent = {
HB_OBJECT_HEADER_STATIC, HB_OBJECT_HEADER_STATIC,
...@@ -1100,6 +1102,37 @@ hb_font_glyph_from_string (hb_font_t *font, ...@@ -1100,6 +1102,37 @@ hb_font_glyph_from_string (hb_font_t *font,
* hb_font_t * hb_font_t
*/ */
DEFINE_NULL_INSTANCE (hb_font_t) =
{
HB_OBJECT_HEADER_STATIC,
true, /* immutable */
nullptr, /* parent */
const_cast<hb_face_t *> (&_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_font_funcs_t *> (&_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) * hb_font_create: (Xconstructor)
* @face: a face. * @face: a face.
...@@ -1187,36 +1220,7 @@ hb_font_create_sub_font (hb_font_t *parent) ...@@ -1187,36 +1220,7 @@ hb_font_create_sub_font (hb_font_t *parent)
hb_font_t * hb_font_t *
hb_font_get_empty (void) hb_font_get_empty (void)
{ {
static const hb_font_t _hb_font_nil = { return const_cast<hb_font_t *> (&Null(hb_font_t));
HB_OBJECT_HEADER_STATIC,
true, /* immutable */
nullptr, /* parent */
const_cast<hb_face_t *> (&_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_t *> (&_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_t *> (&_hb_font_nil);
} }
/** /**
......
...@@ -59,10 +59,19 @@ template <> \ ...@@ -59,10 +59,19 @@ template <> \
} \ } \
namespace Namespace { \ namespace Namespace { \
static_assert (true, "Just so we take semicolon after.") static_assert (true, "Just so we take semicolon after.")
#define DEFINE_NULL_NAMESPACE_BYTES(Namespace, Type) \ #define DEFINE_NULL_NAMESPACE_BYTES(Namespace, Type) \
const unsigned char _hb_Null_##Namespace##_##Type[Namespace::Type::min_size] 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<Type> (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. */ /* Global writable pool. Enlarge as necessary. */
......
...@@ -205,8 +205,6 @@ struct arabic_fallback_plan_t ...@@ -205,8 +205,6 @@ struct arabic_fallback_plan_t
hb_ot_layout_lookup_accelerator_t accel_array[ARABIC_FALLBACK_MAX_LOOKUPS]; 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) #if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(HB_NO_WIN1256)
#define HB_WITH_WIN1256 #define HB_WITH_WIN1256
#endif #endif
...@@ -215,7 +213,8 @@ static const arabic_fallback_plan_t arabic_fallback_plan_nil = {}; ...@@ -215,7 +213,8 @@ static const arabic_fallback_plan_t arabic_fallback_plan_nil = {};
#include "hb-ot-shape-complex-arabic-win1256.hh" #include "hb-ot-shape-complex-arabic-win1256.hh"
#endif #endif
struct ManifestLookup { struct ManifestLookup
{
OT::Tag tag; OT::Tag tag;
OT::OffsetTo<OT::SubstLookup> lookupOffset; OT::OffsetTo<OT::SubstLookup> lookupOffset;
}; };
...@@ -299,7 +298,7 @@ arabic_fallback_plan_create (const hb_ot_shape_plan_t *plan, ...@@ -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)); arabic_fallback_plan_t *fallback_plan = (arabic_fallback_plan_t *) calloc (1, sizeof (arabic_fallback_plan_t));
if (unlikely (!fallback_plan)) if (unlikely (!fallback_plan))
return const_cast<arabic_fallback_plan_t *> (&arabic_fallback_plan_nil); return const_cast<arabic_fallback_plan_t *> (&Null(arabic_fallback_plan_t));
fallback_plan->num_lookups = 0; fallback_plan->num_lookups = 0;
fallback_plan->free_lookups = false; fallback_plan->free_lookups = false;
...@@ -315,13 +314,13 @@ arabic_fallback_plan_create (const hb_ot_shape_plan_t *plan, ...@@ -315,13 +314,13 @@ arabic_fallback_plan_create (const hb_ot_shape_plan_t *plan,
return fallback_plan; return fallback_plan;
free (fallback_plan); free (fallback_plan);
return const_cast<arabic_fallback_plan_t *> (&arabic_fallback_plan_nil); return const_cast<arabic_fallback_plan_t *> (&Null(arabic_fallback_plan_t));
} }
static void static void
arabic_fallback_plan_destroy (arabic_fallback_plan_t *fallback_plan) 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; return;
for (unsigned int i = 0; i < fallback_plan->num_lookups; i++) for (unsigned int i = 0; i < fallback_plan->num_lookups; i++)
......
...@@ -51,6 +51,7 @@ struct hb_shape_plan_t ...@@ -51,6 +51,7 @@ struct hb_shape_plan_t
struct hb_shaper_data_t shaper_data; struct hb_shaper_data_t shaper_data;
}; };
DECLARE_NULL_INSTANCE (hb_shape_plan_t);
#define HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS \ #define HB_SHAPER_DATA_CREATE_FUNC_EXTRA_ARGS \
, const hb_feature_t *user_features \ , const hb_feature_t *user_features \
......
...@@ -88,6 +88,31 @@ hb_shape_plan_plan (hb_shape_plan_t *shape_plan, ...@@ -88,6 +88,31 @@ hb_shape_plan_plan (hb_shape_plan_t *shape_plan,
* hb_shape_plan_t * 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) * hb_shape_plan_create: (Xconstructor)
* @face: * @face:
...@@ -188,30 +213,7 @@ hb_shape_plan_create2 (hb_face_t *face, ...@@ -188,30 +213,7 @@ hb_shape_plan_create2 (hb_face_t *face,
hb_shape_plan_t * hb_shape_plan_t *
hb_shape_plan_get_empty (void) hb_shape_plan_get_empty (void)
{ {
static const hb_shape_plan_t _hb_shape_plan_nil = { return const_cast<hb_shape_plan_t *> (&Null(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
}
};
return const_cast<hb_shape_plan_t *> (&_hb_shape_plan_nil);
} }
/** /**
......
...@@ -60,7 +60,8 @@ extern HB_INTERNAL const uint8_t _hb_modified_combining_class[256]; ...@@ -60,7 +60,8 @@ extern HB_INTERNAL const uint8_t _hb_modified_combining_class[256];
HB_UNICODE_FUNC_IMPLEMENT (hb_script_t, script) \ HB_UNICODE_FUNC_IMPLEMENT (hb_script_t, script) \
/* ^--- Add new simple callbacks here */ /* ^--- Add new simple callbacks here */
struct hb_unicode_funcs_t { struct hb_unicode_funcs_t
{
hb_object_header_t header; hb_object_header_t header;
ASSERT_POD (); ASSERT_POD ();
...@@ -263,9 +264,7 @@ HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE ...@@ -263,9 +264,7 @@ HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE
#undef HB_UNICODE_FUNC_IMPLEMENT #undef HB_UNICODE_FUNC_IMPLEMENT
} destroy; } destroy;
}; };
DECLARE_NULL_INSTANCE (hb_unicode_funcs_t);
extern HB_INTERNAL const hb_unicode_funcs_t _hb_unicode_funcs_nil;
/* Modified combining marks */ /* Modified combining marks */
......
...@@ -185,7 +185,8 @@ hb_unicode_funcs_create (hb_unicode_funcs_t *parent) ...@@ -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, HB_OBJECT_HEADER_STATIC,
nullptr, /* parent */ nullptr, /* parent */
...@@ -209,7 +210,7 @@ const hb_unicode_funcs_t _hb_unicode_funcs_nil = { ...@@ -209,7 +210,7 @@ const hb_unicode_funcs_t _hb_unicode_funcs_nil = {
hb_unicode_funcs_t * hb_unicode_funcs_t *
hb_unicode_funcs_get_empty (void) hb_unicode_funcs_get_empty (void)
{ {
return const_cast<hb_unicode_funcs_t *> (&_hb_unicode_funcs_nil); return const_cast<hb_unicode_funcs_t *> (&Null(hb_unicode_funcs_t));
} }
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册