codegen: make g_autoptr for the GInterface conditional

Desktop / GNOME / GLib - Simon McVittie [collabora.co.uk] - 3 May 2016 09:48 UTC

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 cbbcaa4 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, ...);

1c6cd5f codegen: make g_autoptr for the GInterface conditional
gio/gdbus-2.0/codegen/codegen.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

Upstream: git.gnome.org


  • Share