[API] Add hb_*_get_empty() for all objects

This commit is contained in:
Behdad Esfahbod 2011-05-11 18:14:44 -04:00
parent d3b30be378
commit 80a6833b03
7 changed files with 78 additions and 3 deletions

View File

@ -152,6 +152,12 @@ hb_buffer_create (unsigned int pre_alloc_size)
return buffer;
}
hb_buffer_t *
hb_buffer_get_empty (void)
{
return &_hb_buffer_nil;
}
hb_buffer_t *
hb_buffer_reference (hb_buffer_t *buffer)
{

View File

@ -62,6 +62,9 @@ typedef struct _hb_glyph_position_t {
hb_buffer_t *
hb_buffer_create (unsigned int pre_alloc_size);
hb_buffer_t *
hb_buffer_get_empty (void);
hb_buffer_t *
hb_buffer_reference (hb_buffer_t *buffer);

View File

@ -159,6 +159,12 @@ hb_font_funcs_create (void)
return ffuncs;
}
hb_font_funcs_t *
hb_font_funcs_get_empty (void)
{
return &_hb_font_funcs_nil;
}
hb_font_funcs_t *
hb_font_funcs_reference (hb_font_funcs_t *ffuncs)
{
@ -404,6 +410,12 @@ hb_face_create_for_data (hb_blob_t *blob,
(hb_destroy_func_t) _hb_face_for_data_closure_destroy);
}
hb_face_t *
hb_face_get_empty (void)
{
return &_hb_face_nil;
}
hb_face_t *
hb_face_reference (hb_face_t *face)
@ -533,6 +545,12 @@ hb_font_create_sub_font (hb_font_t *parent)
return font;
}
hb_font_t *
hb_font_get_empty (void)
{
return &_hb_font_nil;
}
hb_font_t *
hb_font_reference (hb_font_t *font)
{

View File

@ -52,6 +52,9 @@ hb_face_create_for_tables (hb_get_table_func_t get_table,
void *user_data,
hb_destroy_func_t destroy);
hb_face_t *
hb_face_get_empty (void);
hb_face_t *
hb_face_reference (hb_face_t *face);
@ -87,6 +90,9 @@ typedef struct _hb_font_funcs_t hb_font_funcs_t;
hb_font_funcs_t *
hb_font_funcs_create (void);
hb_font_funcs_t *
hb_font_funcs_get_empty (void);
hb_font_funcs_t *
hb_font_funcs_reference (hb_font_funcs_t *ffuncs);
@ -206,6 +212,9 @@ hb_font_create (hb_face_t *face);
hb_font_t *
hb_font_create_sub_font (hb_font_t *parent);
hb_font_t *
hb_font_get_empty (void);
hb_font_t *
hb_font_reference (hb_font_t *font);

View File

@ -125,6 +125,12 @@ hb_unicode_funcs_create (hb_unicode_funcs_t *parent)
return ufuncs;
}
hb_unicode_funcs_t *
hb_unicode_funcs_get_empty (void)
{
return &_hb_unicode_funcs_nil;
}
hb_unicode_funcs_t *
hb_unicode_funcs_reference (hb_unicode_funcs_t *ufuncs)
{

View File

@ -53,6 +53,9 @@ hb_unicode_funcs_get_default (void);
hb_unicode_funcs_t *
hb_unicode_funcs_create (hb_unicode_funcs_t *parent);
hb_unicode_funcs_t *
hb_unicode_funcs_get_empty (void);
hb_unicode_funcs_t *
hb_unicode_funcs_reference (hb_unicode_funcs_t *ufuncs);

View File

@ -43,7 +43,7 @@ create_blob (void)
static void *
create_blob_inert (void)
{
return hb_blob_get_empty ();
return hb_blob_create (NULL, 0, HB_MEMORY_MODE_DUPLICATE, NULL, NULL);
}
static void *
@ -68,7 +68,7 @@ create_face (void)
static void *
create_face_inert (void)
{
return hb_face_create_for_data ((hb_blob_t *) create_blob_inert (), 0);
return hb_face_create_for_data (hb_blob_get_empty (), 0);
}
static void *
@ -82,7 +82,7 @@ create_font (void)
static void *
create_font_inert (void)
{
return hb_font_create (create_face_inert ());
return hb_font_create (hb_face_get_empty ());
}
static void *
@ -124,6 +124,7 @@ typedef hb_bool_t (*is_immutable_func_t) (void *obj);
typedef struct {
create_func_t create;
create_func_t create_inert;
create_func_t get_empty;
reference_func_t reference;
destroy_func_t destroy;
set_user_data_func_t set_user_data;
@ -137,6 +138,7 @@ typedef struct {
{ \
(create_func_t) create_##name, \
(create_func_t) create_##name##_inert, \
(create_func_t) hb_##name##_get_empty, \
(reference_func_t) hb_##name##_reference, \
(destroy_func_t) hb_##name##_destroy, \
(set_user_data_func_t) hb_##name##_set_user_data, \
@ -149,6 +151,7 @@ typedef struct {
{ \
(create_func_t) create_##name, \
(create_func_t) create_##name##_inert, \
(create_func_t) hb_##name##_get_empty, \
(reference_func_t) hb_##name##_reference, \
(destroy_func_t) hb_##name##_destroy, \
(set_user_data_func_t) hb_##name##_set_user_data, \
@ -305,6 +308,31 @@ test_object (void)
g_assert_cmpuint (global_data, ==, 1000-2);
}
{
data_t data[2] = {{MAGIC0, FALSE}, {MAGIC1, FALSE}};
g_test_message ("->get_empty()");
obj = o->get_empty ();
g_assert (obj);
g_assert (obj == o->reference (obj));
o->destroy (obj);
if (o->is_immutable)
g_assert (o->is_immutable (obj));
g_assert (!o->set_user_data (obj, &key[0], &data[0], free_up0));
g_assert (!o->get_user_data (obj, &key[0]));
o->destroy (obj);
o->destroy (obj);
o->destroy (obj);
o->destroy (obj);
o->destroy (obj);
g_assert (!data[0].freed);
}
{
data_t data[2] = {{MAGIC0, FALSE}, {MAGIC1, FALSE}};
@ -312,6 +340,8 @@ test_object (void)
obj = o->create_inert ();
if (!obj)
continue;
if (obj == o->get_empty ())
continue; /* Tested already */
g_assert (obj == o->reference (obj));
o->destroy (obj);