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
This commit is contained in:
Matthias Clasen 2016-05-03 18:11:09 -04:00
parent 2ca496a2e7
commit 98f86beed6
3 changed files with 51 additions and 26 deletions

View File

@ -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>

View File

@ -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,7 +308,8 @@ 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')
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')
@ -455,10 +457,10 @@ 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')
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 ')
@ -546,6 +548,7 @@ 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')
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')
@ -614,6 +617,7 @@ 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')
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')
@ -645,6 +649,7 @@ 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')
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')
@ -683,6 +688,7 @@ class CodeGenerator:
self.h.write(' GDBusObjectManagerClientClass parent_class;\n')
self.h.write('};\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')

View File

@ -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()