From 1c6cd5f0a3104aa9b62c7f1d3086181f63e71b59 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 3 May 2016 14:26:30 +0100 Subject: [PATCH] codegen: make g_autoptr for the GInterface conditional 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, ...); Signed-off-by: Simon McVittie Bug: https://bugzilla.gnome.org/show_bug.cgi?id=763379 Reviewed-by: Colin Walters Reviewed-by: Emmanuele Bassi --- gio/gdbus-2.0/codegen/codegen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gio/gdbus-2.0/codegen/codegen.py b/gio/gdbus-2.0/codegen/codegen.py index ac836f96c..6f19772c2 100644 --- a/gio/gdbus-2.0/codegen/codegen.py +++ b/gio/gdbus-2.0/codegen/codegen.py @@ -307,7 +307,7 @@ class CodeGenerator: self.h.write('};\n') self.h.write('\n') - self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n') + self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0) && defined(GLIB_VERSION_2_50) && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_50\n') self.h.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%s, g_object_unref)\n' % (i.camel_name)) self.h.write('#endif\n') self.h.write('\n')