mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-12 15:36:17 +01:00
gdbus-codegen: Take into consideration MAX_ALLOWED for private data
The G_ADD_PRIVATE() macro, and the auto-generated get_instance_private() internal function, should be used conditionally depending on the maximum allowed version of GLib, as defined by the GLIB_VERSION_MAX_ALLOWED pre-processor symbol. This allows generating code that can be compiled in projects that wish to use an older API version of GLib through the use of the GLIB_VERSION_MAX_ALLOWED symbol. https://bugzilla.gnome.org/show_bug.cgi?id=710133
This commit is contained in:
parent
066df98849
commit
1b08980b48
@ -1570,7 +1570,9 @@ class CodeGenerator:
|
||||
self.c.write('static void %s_proxy_iface_init (%sIface *iface);\n'
|
||||
'\n'%(i.name_lower, i.camel_name))
|
||||
self.c.write('G_DEFINE_TYPE_WITH_CODE (%sProxy, %s_proxy, G_TYPE_DBUS_PROXY,\n'%(i.camel_name, i.name_lower))
|
||||
self.c.write('#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38\n')
|
||||
self.c.write(' G_ADD_PRIVATE (%sProxy)\n'%(i.camel_name))
|
||||
self.c.write('#endif\n')
|
||||
self.c.write(' G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_proxy_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
|
||||
|
||||
# finalize
|
||||
@ -1795,12 +1797,17 @@ class CodeGenerator:
|
||||
self.c.write('static void\n'
|
||||
'%s_proxy_init (%sProxy *proxy)\n'
|
||||
'{\n'
|
||||
'#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38\n'
|
||||
' proxy->priv = %s_proxy_get_instance_private (proxy);\n'
|
||||
'#else\n'
|
||||
' proxy->priv = G_TYPE_INSTANCE_GET_PRIVATE (proxy, %sTYPE_%s_PROXY, %sProxyPrivate);\n'
|
||||
'#endif\n\n'
|
||||
' g_dbus_proxy_set_interface_info (G_DBUS_PROXY (proxy), %s_interface_info ());\n'
|
||||
'}\n'
|
||||
'\n'
|
||||
%(i.name_lower, i.camel_name,
|
||||
i.name_lower,
|
||||
i.ns_upper, i.name_upper, i.camel_name,
|
||||
i.name_lower))
|
||||
self.c.write('static void\n'
|
||||
'%s_proxy_class_init (%sProxyClass *klass)\n'
|
||||
@ -1819,8 +1826,10 @@ class CodeGenerator:
|
||||
'\n'%(i.name_lower, i.camel_name,
|
||||
i.name_lower, i.name_lower, i.name_lower, i.name_lower, i.name_lower))
|
||||
if len(i.properties) > 0:
|
||||
self.c.write('\n'
|
||||
' %s_override_properties (gobject_class, 1);\n'%(i.name_lower))
|
||||
self.c.write(' %s_override_properties (gobject_class, 1);\n\n'%(i.name_lower))
|
||||
self.c.write('#if GLIB_VERSION_MAX_ALLOWED < GLIB_VERSION_2_38\n'
|
||||
' g_type_class_add_private (klass, sizeof (%sProxyPrivate));\n'
|
||||
'#endif\n'%(i.camel_name))
|
||||
self.c.write('}\n'
|
||||
'\n')
|
||||
|
||||
@ -2339,7 +2348,9 @@ class CodeGenerator:
|
||||
%(i.name_lower, i.camel_name))
|
||||
|
||||
self.c.write('G_DEFINE_TYPE_WITH_CODE (%sSkeleton, %s_skeleton, G_TYPE_DBUS_INTERFACE_SKELETON,\n'%(i.camel_name, i.name_lower))
|
||||
self.c.write('#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38\n')
|
||||
self.c.write(' G_ADD_PRIVATE (%sSkeleton)\n'%(i.camel_name))
|
||||
self.c.write('#endif\n')
|
||||
self.c.write(' G_IMPLEMENT_INTERFACE (%sTYPE_%s, %s_skeleton_iface_init));\n\n'%(i.ns_upper, i.name_upper, i.name_lower))
|
||||
|
||||
# finalize
|
||||
@ -2533,9 +2544,14 @@ class CodeGenerator:
|
||||
self.c.write('static void\n'
|
||||
'%s_skeleton_init (%sSkeleton *skeleton)\n'
|
||||
'{\n'
|
||||
'#if GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_38\n'
|
||||
' skeleton->priv = %s_skeleton_get_instance_private (skeleton);\n'
|
||||
'#else\n'
|
||||
' skeleton->priv = G_TYPE_INSTANCE_GET_PRIVATE (skeleton, %sTYPE_%s_SKELETON, %sSkeletonPrivate);\n'
|
||||
'#endif\n\n'
|
||||
%(i.name_lower, i.camel_name,
|
||||
i.name_lower))
|
||||
i.name_lower,
|
||||
i.ns_upper, i.name_upper, i.camel_name))
|
||||
self.c.write(' g_mutex_init (&skeleton->priv->lock);\n')
|
||||
self.c.write(' skeleton->priv->context = g_main_context_ref_thread_default ();\n')
|
||||
if len(i.properties) > 0:
|
||||
@ -2587,6 +2603,12 @@ class CodeGenerator:
|
||||
self.c.write(' skeleton_class->get_properties = %s_skeleton_dbus_interface_get_properties;\n'%(i.name_lower))
|
||||
self.c.write(' skeleton_class->flush = %s_skeleton_dbus_interface_flush;\n'%(i.name_lower))
|
||||
self.c.write(' skeleton_class->get_vtable = %s_skeleton_dbus_interface_get_vtable;\n'%(i.name_lower))
|
||||
|
||||
self.c.write('\n'
|
||||
'#if GLIB_VERSION_MAX_ALLOWED < GLIB_VERSION_2_38\n'
|
||||
' g_type_class_add_private (klass, sizeof (%sSkeletonPrivate));\n'
|
||||
'#endif\n'%(i.camel_name))
|
||||
|
||||
self.c.write('}\n'
|
||||
'\n')
|
||||
|
||||
@ -3370,4 +3392,5 @@ class CodeGenerator:
|
||||
if self.generate_objmanager:
|
||||
self.generate_object()
|
||||
self.generate_object_manager_client()
|
||||
|
||||
self.generate_outro()
|
||||
|
1
gio/tests/.gitignore
vendored
1
gio/tests/.gitignore
vendored
@ -67,6 +67,7 @@ gdbus-proxy-well-known-name
|
||||
gdbus-serialization
|
||||
gdbus-test-codegen
|
||||
gdbus-test-codegen-generated*
|
||||
gdbus-test-codegen-old
|
||||
gdbus-test-fixture
|
||||
gdbus-testserver
|
||||
gdbus-threading
|
||||
|
@ -350,6 +350,7 @@ test_programs += \
|
||||
gdbus-proxy-threads \
|
||||
gdbus-proxy-well-known-name \
|
||||
gdbus-test-codegen \
|
||||
gdbus-test-codegen-old \
|
||||
gdbus-threading \
|
||||
gmenumodel \
|
||||
$(NULL)
|
||||
@ -373,9 +374,12 @@ gdbus_proxy_SOURCES = $(gdbus_sessionbus_sources) gdbus-pro
|
||||
gdbus_proxy_threads_SOURCES = $(gdbus_sessionbus_sources) gdbus-proxy-threads.c
|
||||
gdbus_proxy_well_known_name_SOURCES = $(gdbus_sessionbus_sources) gdbus-proxy-well-known-name.c
|
||||
gdbus_test_codegen_SOURCES = $(gdbus_sessionbus_sources) gdbus-test-codegen.c
|
||||
nodist_gdbus_test_codegen_SOURCES = gdbus-test-codegen-generated.c gdbus-test-codegen-generated.h
|
||||
gdbus_test_codegen_old_SOURCES = $(gdbus_sessionbus_sources) gdbus-test-codegen.c
|
||||
nodist_gdbus_test_codegen_old_SOURCES = gdbus-test-codegen-generated.c gdbus-test-codegen-generated.h
|
||||
gdbus_test_codegen_old_CPPFLAGS = $(AM_CPPFLAGS) -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_36 -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_36
|
||||
gdbus_threading_SOURCES = $(gdbus_sessionbus_sources) gdbus-threading.c
|
||||
gmenumodel_SOURCES = $(gdbus_sessionbus_sources) gmenumodel.c
|
||||
nodist_gdbus_test_codegen_SOURCES = gdbus-test-codegen-generated.c gdbus-test-codegen-generated.h
|
||||
|
||||
gdbus-test-codegen.o: gdbus-test-codegen-generated.h
|
||||
gdbus-test-codegen-generated.h gdbus-test-codegen-generated.c: test-codegen.xml Makefile $(top_builddir)/gio/gdbus-2.0/codegen/gdbus-codegen
|
||||
|
Loading…
Reference in New Issue
Block a user