Skip to content
  • Simon McVittie's avatar
    codegen: make g_autoptr for the GInterface conditional · 1c6cd5f0
    Simon McVittie authored
    Some GNOME projects unconditionally work around the generated code's
    lack of g_autoptr support by defining the autoptr cleanup function
    themselves, which is not forward-compatible; as a result, commit
    cbbcaa4d
    
     broke them. Do not define the cleanup function unless the
    including app "opts in" to newer APIs via GLIB_VERSION_MAX_ALLOWED.
    
    Projects requiring compatibility with GLib < 2.49 can get a
    forward-compatible g_autoptr for a generated GInterface type found in
    a library, for example ExampleAnimal in the GIO tests, by declaring
    and using a typedef with a distinct name outside the library's
    namespace:
    
        typedef AutoExampleAnimal ExampleAnimal;
        G_DEFINE_AUTOPTR_CLEANUP_FUNC (AutoExampleAnimal, g_object_unref)
    
        ...
    
        g_autoptr (AutoExampleAnimal) animal = NULL;
    
        /* returns ExampleAnimal * */
        animal = example_animal_proxy_new_sync (...);
        /* takes ExampleAnimal * first argument */
        example_animal_call_poke_sync (animal, ...);
    
    Signed-off-by: default avatarSimon McVittie <simon.mcvittie@collabora.co.uk>
    Bug: https://bugzilla.gnome.org/show_bug.cgi?id=763379
    
    
    Reviewed-by: default avatarColin Walters <walters@verbum.org>
    Reviewed-by: default avatarEmmanuele Bassi <ebassi@gnome.org>
    1c6cd5f0