Merge branch 'wjt/gdbus-codegen-add-autocleanup-for-FooObject' into 'master'

gdbus-codegen: add autocleanup for FooObject

See merge request GNOME/glib!420
This commit is contained in:
Philip Withnall 2018-10-29 23:12:41 +00:00
commit d512c0fe43
4 changed files with 50 additions and 0 deletions

View File

@ -433,6 +433,11 @@ class HeaderCodeGenerator:
self.outfile.write('GType %sobject_get_type (void) G_GNUC_CONST;\n'
'\n'
%(self.ns_lower))
if self.generate_autocleanup == 'all':
self.outfile.write('#if GLIB_CHECK_VERSION(2, 44, 0)\n')
self.outfile.write('G_DEFINE_AUTOPTR_CLEANUP_FUNC (%sObject, g_object_unref)\n' % (self.namespace))
self.outfile.write('#endif\n')
self.outfile.write('\n')
for i in self.ifaces:
if i.deprecated:
self.outfile.write('G_GNUC_DEPRECATED ')

View File

@ -502,6 +502,7 @@ gdbus-test-codegen-generated.h: test-codegen.xml Makefile $(top_builddir)/gio/gd
--interface-prefix org.project. \
--generate-c-code gdbus-test-codegen-generated \
--c-generate-object-manager \
--c-generate-autocleanup all \
--c-namespace Foo_iGen \
--generate-docbook gdbus-test-codegen-generated-doc \
--annotate "org.project.Bar" Key1 Value1 \

View File

@ -2385,6 +2385,48 @@ test_property_naming (void)
/* ---------------------------------------------------------------------------------------------------- */
/* autocleanups
*
* - check that g_autoptr() works for all generated types, if supported by the
* current compiler
*/
static void
test_autocleanups (void)
{
#ifdef g_autoptr
g_autoptr(FooiGenBar) bar = NULL;
g_autoptr(FooiGenBarProxy) bar_proxy = NULL;
g_autoptr(FooiGenBarSkeleton) bar_skeleton = NULL;
g_autoptr(FooiGenObject) object = NULL;
g_autoptr(FooiGenObjectProxy) object_proxy = NULL;
g_autoptr(FooiGenObjectSkeleton) object_skeleton = NULL;
g_autoptr(FooiGenObjectManagerClient) object_manager_client = NULL;
(void) bar;
(void) bar_proxy;
(void) bar_skeleton;
(void) object;
(void) object_proxy;
(void) object_skeleton;
(void) object_manager_client;
#elif GLIB_CHECK_VERSION(2, 38, 0)
/* This file is compiled twice, once without GLib version guards and once
* with
*
* -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_36
* -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_36
*
* g_test_skip() was added in 2.38.
*/
g_test_skip ("g_autoptr() not supported on this compiler");
#else
/* Let's just say it passed. */
#endif
}
/* ---------------------------------------------------------------------------------------------------- */
int
main (int argc,
char *argv[])
@ -2395,6 +2437,7 @@ main (int argc,
g_test_add_func ("/gdbus/codegen/interface_stability", test_interface_stability);
g_test_add_func ("/gdbus/codegen/object-manager", test_object_manager);
g_test_add_func ("/gdbus/codegen/property-naming", test_property_naming);
g_test_add_func ("/gdbus/codegen/autocleanups", test_autocleanups);
return session_bus_run ();
}

View File

@ -182,6 +182,7 @@ if host_machine.system() != 'windows'
'--output-directory', '@OUTDIR@',
'--generate-c-code', 'gdbus-test-codegen-generated',
'--c-generate-object-manager',
'--c-generate-autocleanup', 'all',
'--c-namespace', 'Foo_iGen',
'--generate-docbook', 'gdbus-test-codegen-generated-doc',
'--annotate', 'org.project.Bar', 'Key1', 'Value1',