Details

[Home]

Issue of the Implementation # S0837

Brief

Segfault when implementing dynamically declared interface

Detailed Description

Segmentation fault occurs when one tries to create an implementation of an interface the type of which was registered dynamically, i.e. using g_type_register_dynamic.

For simplicity, the example that reproduces the problem uses GTypeModule for dynamic registration of the type of the interface. But the same occurs if one creates his or her own class implementing GTypePlugin and uses an object of this class in g_type_register_dynamic.

Problem appears in glib-2.23 version of library, previous versions of the library seem to work correctly with dynamically declared interfaces.

Problem location(s) in the standard

Linux Standard Base Desktop Specification 4.0, Section 16.5. Interfaces for libgobject-2.0 that refers Gobject 2.8.6 Reference Manual, Section "Type Information"

Example

#include <glib-object.h>
#include <stdio.h>

// TestModule - derived from GTypeModule
GType test_module_type_register()
{
	GTypeInfo test_module_info = {
		.class_size = sizeof(GTypeModuleClass),
		.instance_size = sizeof(GTypeModule)
	};

	return g_type_register_static(G_TYPE_TYPE_MODULE,
		"test_module",
		&test_module_info,
		0);
}
// TestIface - dynamically registered interface
GType test_iface_type_register(GTypeModule* module)
{
	GTypeInfo test_iface_info = {
		.class_size = sizeof(GTypeInterface)
	};
	return g_type_module_register_type(module,
		G_TYPE_INTERFACE,
		"test_iface",
		&test_iface_info,
		0);
}

// TestObject - statically registered object, implements interface
GType test_object_type_register()
{
	GTypeInfo test_object_info = {
		.class_size = sizeof(GObjectClass),
		.instance_size = sizeof(GObject),
	};

	return g_type_register_static(G_TYPE_OBJECT,
		"test_object",
		&test_object_info,
		0);
}
void test_object_implement_iface(GType test_object_type,
        GType test_iface_type)
{
	GInterfaceInfo test_object_iface_info = {};
	g_type_add_interface_static(test_object_type,
                test_iface_type,
		&test_object_iface_info);
}
int main()
{
	g_type_init();
	
	GType test_module_type = test_module_type_register();
	GTypeModule* module = 
                G_TYPE_MODULE(g_object_new(test_module_type, NULL));
	GType test_iface_type = test_iface_type_register(module);
	GType test_object_type = test_object_type_register();

	test_object_implement_iface(test_object_type,
                 test_iface_type);
	
	g_object_unref(module);
	return 0;
}

Component

gtk-gobject-2.23

Accepted

Gnome Bugzilla 608315

Status

Fixed in gtk-gobject-2.23.4

[Home]