ft_object_create( FT_Object *pobject, FT_Class clazz, FT_Pointer init_data ) { FT_Memory memory; FT_Error error; FT_Object obj; FT_ASSERT_IS_CLASS(clazz); memory = FT_CLASS__MEMORY(clazz); if ( !FT_ALLOC( obj, clazz->obj_size ) ) { obj->clazz = clazz; obj->ref_count = 1; if ( clazz->obj_init ) { error = clazz->obj_init( obj, init_data ); if ( error ) { /* IMPORTANT: call the destructor when an error */ /* was detected in the constructor !! */ if ( clazz->obj_done ) clazz->obj_done( obj ); FT_FREE( obj ); } } } *pobject = obj; return error; }
/* the cleanup routine for all objects */ static void ft_object_cleanup( FT_Object object ) { FT_Memory memory = FT_OBJECT__MEMORY(object); FT_Class clazz = FT_OBJECT__CLASS(object); if ( clazz->obj_done ) clazz->obj_done( object ); FT_FREE( object ); }