[glib] codegen: make g_autoptr for the GInterface conditional



commit 1c6cd5f0a3104aa9b62c7f1d3086181f63e71b59
Author: Simon McVittie <simon mcvittie collabora co uk>
Date:   Tue May 3 14:26:30 2016 +0100

    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 <simon mcvittie collabora co uk>
    Bug: https://bugzilla.gnome.org/show_bug.cgi?id=763379
    Reviewed-by: Colin Walters <walters verbum org>
    Reviewed-by: Emmanuele Bassi <ebassi gnome org>

 gio/gdbus-2.0/codegen/codegen.py |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
---
diff --git a/gio/gdbus-2.0/codegen/codegen.py b/gio/gdbus-2.0/codegen/codegen.py
index ac836f9..6f19772 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')


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]