summaryrefslogtreecommitdiff
path: root/glib/glibmm
diff options
context:
space:
mode:
authorKjell Ahlstedt <kjellahlstedt@gmail.com>2022-06-08 18:33:59 +0200
committerKjell Ahlstedt <kjellahlstedt@gmail.com>2022-06-08 18:33:59 +0200
commita41d6e28461bad90fdb78756344daa7c7d9db1dd (patch)
tree67ae38a3f3b7ee2a8cb5b8c321bc2eb25601339a /glib/glibmm
parent6dc1ce0d7cae09f3ea84f4a7b44f5ff440803765 (diff)
downloadglibmm-a41d6e28461bad90fdb78756344daa7c7d9db1dd.tar.gz
gmmproc: Improved handling of final types
Some GObject-derived classes shall not be derived from. * glib/glibmm/class.cc: * glib/glibmm/interface.cc: Don't derive or add interfaces to a class if G_TYPE_IS_FINAL(gtype) is true. * tools/m4/class_shared.m4: Fix gtype_ when _DO_NOT_DERIVE_GTYPE is used. Add _ABI_AS_WITH_DERIVED_GTYPE, making it possible to add _DO_NOT_DERIVE_GTYPE without breaking ABI.
Diffstat (limited to 'glib/glibmm')
-rw-r--r--glib/glibmm/class.cc9
-rw-r--r--glib/glibmm/interface.cc7
2 files changed, 16 insertions, 0 deletions
diff --git a/glib/glibmm/class.cc b/glib/glibmm/class.cc
index 36c3c4be..31f92c61 100644
--- a/glib/glibmm/class.cc
+++ b/glib/glibmm/class.cc
@@ -42,6 +42,15 @@ Class::register_derived_type(GType base_type, GTypeModule* module)
if (base_type == 0)
return; // already initialized
+#if GLIB_CHECK_VERSION(2,70,0)
+ // Don't derive a type if the base type is a final type.
+ if (G_TYPE_IS_FINAL(base_type))
+ {
+ gtype_ = base_type;
+ return;
+ }
+#endif
+
GTypeQuery base_query = {
0, nullptr, 0, 0,
};
diff --git a/glib/glibmm/interface.cc b/glib/glibmm/interface.cc
index f01f13dc..eec50e3a 100644
--- a/glib/glibmm/interface.cc
+++ b/glib/glibmm/interface.cc
@@ -25,6 +25,13 @@ namespace Glib
void
Interface_Class::add_interface(GType instance_type) const
{
+#if GLIB_CHECK_VERSION(2,70,0)
+ // If instance_type is a final type, it has not been registered by
+ // Glib::Class::register_derived_type(). Don't add an interface.
+ if (G_TYPE_IS_FINAL(instance_type))
+ return;
+#endif
+
// This check is disabled, because it checks whether any of the types's bases implement the
// interface, not just the specific type.
// if( !g_type_is_a(instance_type, gtype_) ) //For convenience, don't complain about calling this