Commit 98f86bee authored by Matthias Clasen's avatar Matthias Clasen

gdbus-codegen: Only generate autocleanup when instructed to

This adds a new --c-generate-autocleanup option to gdbus-codegen
which can be used to instruct gdbus-codegen about what autocleanup
definitions to emit.

Doing this unconditionally was found to interfere with existing
code out in the wild.

The new option takes an argument that can be
none, objects or all; to indicate whether to generate no
autocleanup functions, only do it for object types, or do it
for interface types as well. The default is 'objects', which
matches the unconditional behavior of gdbus-codegen on the 2.48
branch.

https://bugzilla.gnome.org/show_bug.cgi?id=763379
parent 2ca496a2
......@@ -32,6 +32,7 @@
<arg><option>--generate-c-code</option> <replaceable>OUTFILES</replaceable></arg>
<arg><option>--c-namespace</option> <replaceable>YourProject</replaceable></arg>
<arg><option>--c-generate-object-manager</option></arg>
<arg><option>--c-generate-autocleanup</option> none|objects|all</arg>
<arg><option>--generate-docbook</option> <replaceable>OUTFILES</replaceable></arg>
<arg><option>--xml-files</option> <replaceable>FILE</replaceable></arg>
<group choice="plain" rep="repeat">
......@@ -214,6 +215,21 @@
</listitem>
</varlistentry>
<varlistentry>
<term><option>--c-generate-autocleanup</option> none|objects|all</term>
<listitem>
<para>
This option influences what types autocleanup functions are
generated for. 'none' means to not generate any autocleanup functions.
'objects' means to generate them for object types, and 'all' means to
generate them for object types and interfaces. The default is 'objects'
due to a corner case in backwards compatibility with a few projects,
but you should likely switch your project to use 'all'.
This option was added in GLib 2.50.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--annotate</option> <replaceable>ELEMENT</replaceable> <replaceable>KEY</replaceable> <replaceable>VALUE</replaceable></term>
<listitem>
......
......@@ -28,9 +28,10 @@ from . import dbustypes
# ----------------------------------------------------------------------------------------------------
class CodeGenerator:
def __init__(self, ifaces, namespace, interface_prefix, generate_objmanager, docbook_gen, h, c):
def __init__(self, ifaces, namespace, interface_prefix, generate_objmanager, generate_autocleanup, docbook_gen, h, c):
self.docbook_gen = docbook_gen
self.generate_objmanager = generate_objmanager
self.generate_autocleanup = generate_autocleanup
self.ifaces = ifaces
self.h = h
self.c = c
......@@ -307,10 +308,11 @@ class CodeGenerator:
self.h.write('};\n')
self.h.write('\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')
if self.generate_autocleanup == 'all':
self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\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')
self.h.write('GType %s_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
self.h.write('\n')
self.h.write('GDBusInterfaceInfo *%s_interface_info (void);\n'%(i.name_lower))
......@@ -455,11 +457,11 @@ class CodeGenerator:
self.h.write('\n')
self.h.write('GType %s_proxy_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
self.h.write('\n')
self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n')
self.h.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%sProxy, g_object_unref)\n' % (i.camel_name))
self.h.write('#endif\n')
self.h.write('\n')
if self.generate_autocleanup in ('objects', 'all'):
self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n')
self.h.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%sProxy, g_object_unref)\n' % (i.camel_name))
self.h.write('#endif\n')
self.h.write('\n')
if i.deprecated:
self.h.write('G_GNUC_DEPRECATED ')
self.h.write('void %s_proxy_new (\n'
......@@ -546,10 +548,11 @@ class CodeGenerator:
self.h.write('\n')
self.h.write('GType %s_skeleton_get_type (void) G_GNUC_CONST;\n'%(i.name_lower))
self.h.write('\n')
self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n')
self.h.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%sSkeleton, g_object_unref)\n' % (i.camel_name))
self.h.write('#endif\n')
self.h.write('\n')
if self.generate_autocleanup in ('objects', 'all'):
self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n')
self.h.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%sSkeleton, g_object_unref)\n' % (i.camel_name))
self.h.write('#endif\n')
self.h.write('\n')
if i.deprecated:
self.h.write('G_GNUC_DEPRECATED ')
self.h.write('%s *%s_skeleton_new (void);\n'%(i.camel_name, i.name_lower))
......@@ -614,10 +617,11 @@ class CodeGenerator:
self.h.write('\n')
self.h.write('GType %sobject_proxy_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
self.h.write('\n')
self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n')
self.h.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%sObjectProxy, g_object_unref)\n' % (self.namespace))
self.h.write('#endif\n')
self.h.write('\n')
if self.generate_autocleanup in ('objects', 'all'):
self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n')
self.h.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%sObjectProxy, g_object_unref)\n' % (self.namespace))
self.h.write('#endif\n')
self.h.write('\n')
self.h.write('%sObjectProxy *%sobject_proxy_new (GDBusConnection *connection, const gchar *object_path);\n'%(self.namespace, self.ns_lower))
self.h.write('\n')
self.h.write('#define %sTYPE_OBJECT_SKELETON (%sobject_skeleton_get_type ())\n'%(self.ns_upper, self.ns_lower))
......@@ -645,10 +649,11 @@ class CodeGenerator:
self.h.write('\n')
self.h.write('GType %sobject_skeleton_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
self.h.write('\n')
self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n')
self.h.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%sObjectSkeleton, g_object_unref)\n' % (self.namespace))
self.h.write('#endif\n')
self.h.write('\n')
if self.generate_autocleanup in ('objects', 'all'):
self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n')
self.h.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%sObjectSkeleton, g_object_unref)\n' % (self.namespace))
self.h.write('#endif\n')
self.h.write('\n')
self.h.write('%sObjectSkeleton *%sobject_skeleton_new (const gchar *object_path);\n'
%(self.namespace, self.ns_lower))
for i in self.ifaces:
......@@ -683,10 +688,11 @@ class CodeGenerator:
self.h.write(' GDBusObjectManagerClientClass parent_class;\n')
self.h.write('};\n')
self.h.write('\n')
self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n')
self.h.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%sObjectManagerClient, g_object_unref)\n' % (self.namespace))
self.h.write('#endif\n')
self.h.write('\n')
if self.generate_autocleanup in ('objects', 'all'):
self.h.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n')
self.h.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%sObjectManagerClient, g_object_unref)\n' % (self.namespace))
self.h.write('#endif\n')
self.h.write('\n')
self.h.write('GType %sobject_manager_client_get_type (void) G_GNUC_CONST;\n'%(self.ns_lower))
self.h.write('\n')
self.h.write('GType %sobject_manager_client_get_proxy_type (GDBusObjectManagerClient *manager, const gchar *object_path, const gchar *interface_name, gpointer user_data);\n'%(self.ns_lower))
......
......@@ -156,6 +156,8 @@ def codegen_main():
help='Generate a GDBusObjectManagerClient subclass when generating C code')
arg_parser.add_option('', '--generate-c-code', metavar='OUTFILES',
help='Generate C code in OUTFILES.[ch]')
arg_parser.add_option('', '--c-generate-autocleanup', type='choice', choices=['none', 'objects', 'all'], default='objects',
help='Generate autocleanup support')
arg_parser.add_option('', '--generate-docbook', metavar='OUTFILES',
help='Generate Docbook in OUTFILES-org.Project.IFace.xml')
arg_parser.add_option('', '--annotate', nargs=3, action='append', metavar='WHAT KEY VALUE',
......@@ -189,6 +191,7 @@ def codegen_main():
opts.c_namespace,
opts.interface_prefix,
opts.c_generate_object_manager,
opts.c_generate_autocleanup,
docbook_gen,
h, c);
ret = gen.generate()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment