4.2 Naming

All functions are named according to one of the following schemes:

The sole exceptions to this are where we have MuPDF specific functions that emulate (or extend) ‘well known’ functions, where we parrot those functions. For example ‘fz_printf’ or ‘fz_strdup’.

In addition, we avoid using ‘get’ in function names as this is generally redundant. In contrast, however, we do use ‘set’ where required. Consider for instance fz_aa_level (to retrieve the current anti-aliasing level), and fz_set_aa_level (to update it).

MuPDF makes extensive use of reference counting (see section 21.3 Reference Counting for more details). We reserve various words to indicate that reference counting is being used:

All of these calls return an object reference. It is the callers responsibility to store this reference safely somewhere for the duration of the required lifespan of the object, and to destroy that reference when the caller no longer requires it.

No function should return ownership of a reference without being named with one of the reserved words above.

Once all the references to a given object are released, the system will remove the object itself.

Failure to drop references will result in memory leaks. Dropping references too early may result in crashes due to objects being accessed after they have been destroyed.

API functions to destroy objects that are not subject to reference counted can be destroyed by calling functions using the words ‘drop’, ‘close’ or ‘free’.

In contrast to ‘find’ described above, we have one other reserved word regarding searching:

When we have a structure already allocated, and we wish to initialise some or all of its internal details, we use ‘init’. The matching pair to this should be named ’fin’. For example, fz_cmm_init_profile is matched by fz_cmm_fin_profile.

Some objects are created using functions using the verb ‘create’. Sometimes these can be reference counted objects (e.g. ‘pdf_create_document’), in which case they should be ‘drop’ped as usual. Non reference counted objects should be ‘destroyed’ (e.g. fz_destroy_mutex.