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

typedef GObject Parent, Child;
typedef GObjectClass ParentClass, ChildClass;

#define DEFINE_DTYPE(Tn, t_n, T_P) \
static GType t_n ## _type = 0; \
GObjectClass * t_n ## _parent_class; \
static void t_n ## _dispose (Tn *obj); \
static void t_n ## _dispose_real (Tn *obj) \
{ \
	t_n ## _dispose (obj); \
	G_OBJECT_CLASS (t_n ## _parent_class)->dispose (obj); \
} \
static void t_n ## _class_init (Tn ## Class *klass) \
{ \
	t_n ## _parent_class = g_type_class_peek_parent (klass); \
	G_OBJECT_CLASS (klass)->dispose = \
		(void (*) (GObject *)) t_n ## _dispose_real; \
} \
static void t_n ## _init (Tn *obj); \
GType \
t_n ## _get_type (void) { \
	return t_n ## _type; \
} \
static void \
t_n ## _register (GTypeModule *mod) \
{ \
	static GTypeInfo t_n ## _info = { \
		sizeof (Tn ## Class), \
		NULL, NULL, (GClassInitFunc) t_n ## _class_init, \
		NULL, NULL, sizeof (Tn), 0, \
		(GInstanceInitFunc) t_n ## _init, NULL \
	}; \
	t_n ## _type = g_type_module_register_type (mod, T_P, #Tn, \
						    & t_n ## _info, 0); \
}

DEFINE_DTYPE (Parent, parent, G_TYPE_OBJECT);
DEFINE_DTYPE (Child, child, parent_get_type ());

static void
parent_init (Parent *p)
{
	g_print ("Parent init\n");
}

static void
child_init (Child *c)
{
	g_print ("Child init\n");
}

static void
child_dispose (Child *c)
{
	g_print ("Child dispose\n");
}

static void
parent_dispose (Parent *p)
{
	g_print ("parent dispose\n");
}

void
init (GTypeModule *m)
{
	parent_register (m);
	child_register (m);
}
