Detecting failures

Most HarfBuzz constructors return a shared, inert object on allocation failure. You can pass this object to HarfBuzz functions and destroy it as usual. For example, if hb_font_create() cannot allocate a font, it returns hb_font_get_empty().

Constructors whose names end in _or_fail return NULL on failure. Use hb_blob_create_or_fail() to wrap data in memory, hb_blob_create_from_file_or_fail() to read a file, or hb_face_create_or_fail() to open a face at a given index in a blob. Check the return value before using the object.

Buffers, sets, and maps record allocation failures on the object. You can check hb_buffer_allocation_successful() after adding text, hb_set_allocation_successful() after adding set members, or hb_map_allocation_successful() after inserting map entries. Each function also returns false for its type’s empty singleton.