summaryrefslogtreecommitdiff
path: root/glib/glibmm/extraclassinit.h
diff options
context:
space:
mode:
authorKjell Ahlstedt <kjellahlstedt@gmail.com>2023-03-31 15:24:13 +0200
committerKjell Ahlstedt <kjellahlstedt@gmail.com>2023-03-31 15:24:13 +0200
commit98f3b67b5c1bd71d0e7b41193fb4683fc957e321 (patch)
tree1fa8a4cf1bf9a93a79bfe08be83426bb15da01e9 /glib/glibmm/extraclassinit.h
parentb7ad9b86d70003c065606c563578cc66dcd2ce0a (diff)
downloadglibmm-2-76.tar.gz
Glib: Use callback functions with C linkageglibmm-2-76
* gio/src/cancellable.ccg: Add TODO comment. * glib/glibmm/class.cc: Call custom_class_base_finalize_function() and custom_class_init_function() via local functions with C linkage. * glib/glibmm/extraclassinit.h: Point out in the class documentation that the class init and instance init functions shall have C linkage. * glib/glibmm/main.[cc|h]: Call prepare_vfunc(), check_vfunc() and dispatch_vfunc() via local functions with C linkage. * glib/glibmm/objectbase.cc: Call destroy_notify_callback() via a local function with C linkage. * glib/glibmm/propertyproxy_base.cc: Call PropertyProxyConnectionNode:: callback() and destroy_notify_handler() via local functions with C linkage. * glib/glibmm/signalproxy.cc: Call SignalProxyNormal::slot0_void_callback() and SignalProxyConnectionNode::destroy_notify_handler() via local functions with C linkage. * glib/src/binding.ccg: Add extern "C". * glib/src/bytearray.ccg: Add a TODO comment. * glib/src/markup.ccg: Call functions in the vfunc table via local functions with C linkage. * glib/src/optioncontext.ccg: Add extern "C". * glib/src/optiongroup.ccg: Call post_parse_callback() and option_arg_callback() via local functions with C linkage. Part of issue #1
Diffstat (limited to 'glib/glibmm/extraclassinit.h')
-rw-r--r--glib/glibmm/extraclassinit.h45
1 files changed, 34 insertions, 11 deletions
diff --git a/glib/glibmm/extraclassinit.h b/glib/glibmm/extraclassinit.h
index b5b9e698..03ad9c8a 100644
--- a/glib/glibmm/extraclassinit.h
+++ b/glib/glibmm/extraclassinit.h
@@ -29,6 +29,30 @@ namespace Glib
* @code
* #include <glibmm/extraclassinit.h>
*
+ * extern "C"
+ * {
+ * // Extra class init function.
+ * static void my_extra_class_init_function(void* g_class, void* class_data)
+ * {
+ * g_return_if_fail(GTK_IS_WIDGET_CLASS(g_class));
+ *
+ * const auto klass = static_cast<GtkWidgetClass*>(g_class);
+ * const auto css_name = static_cast<Glib::ustring*>(class_data);
+ *
+ * gtk_widget_class_set_css_name(klass, css_name->c_str());
+ * }
+ *
+ * // Extra instance init function.
+ * static void my_instance_init_function(GTypeInstance* instance, void* g_class)
+ * {
+ * g_return_if_fail(GTK_IS_WIDGET(instance));
+ *
+ * // Nothing to do here.
+ * // This extra instance init function just shows how such a function can
+ * // be added to a custom widget, if necessary.
+ * }
+ * } // extern "C"
+ *
* class MyExtraInit : public Glib::ExtraClassInit
* {
* public:
@@ -39,17 +63,6 @@ namespace Glib
* { }
*
* private:
- * static void my_extra_class_init_function(void* g_class, void* class_data)
- * {
- * const auto klass = static_cast<GtkWidgetClass*>(g_class);
- * const auto css_name = static_cast<Glib::ustring*>(class_data);
- * gtk_widget_class_set_css_name(klass, css_name->c_str());
- * }
- * static void my_instance_init_function(GTypeInstance* instance, void* g_class)
- * {
- * gtk_widget_set_has_surface(GTK_WIDGET(instance), true);
- * }
- *
* Glib::ustring m_css_name;
* };
*
@@ -69,6 +82,16 @@ namespace Glib
* };
* @endcode
*
+ * The callback functions (my_extra_class_init_function() and my_instance_init_function()
+ * in the example) are called from GLib (a C library). They shall have C linkage.
+ * (Many compilers accept callback functions with C++ linkage, but such a program
+ * has undefined behavior.)
+ *
+ * If you want the functions with C linkage to have internal linkage, they must
+ * be declared 'static', even if they are defined in an anonymous namespace.
+ * The compiler respects namespace declarations of functions with C linkage,
+ * but the linker does not.
+
* @note Classes derived from %ExtraClassInit (MyExtraInit in the example)
* must be listed before Glib::Object or a class derived from
* %Glib::Object (Gtk::Widget in the example) in the list of base classes.